登录 注册

sentencepiece

去点 Star
网络与基础设施
12,170
Stars
—
Forks
0
Watchers
—
Open Issues
待补全
许可证
C++
语言
—
创建时间
最近更新

项目能做什么

面向神经网络文本生成的无监督分词工具。
来源:AI 基于仓库事实生成 · 内容以仓库实际 README 为准

使用说明 查看原始 README 原仓库文档

中文使用说明暂未生成。下面保留原仓库 README 摘录,命令与配置均以原文为准。
原始 README 摘录(英文原文,节选前 3000 字符)
# SentencePiece

[![Build C++](https://github.com/google/sentencepiece/actions/workflows/cmake.yml/badge.svg)](https://github.com/google/sentencepiece/actions/workflows/cmake.yml)
[![Build Wheels](https://github.com/google/sentencepiece/actions/workflows/wheel.yml/badge.svg)](https://github.com/google/sentencepiece/actions/workflows/wheel.yml)
[![GitHub Issues](https://img.shields.io/github/issues/google/sentencepiece.svg)](https://github.com/google/sentencepiece/issues)
![PyPI - Python Version](https://img.shields.io/pypi/pyversions/sentencepiece)
[![PyPI version](https://badge.fury.io/py/sentencepiece.svg)](https://badge.fury.io/py/sentencepiece)
[![PyPi downloads](https://img.shields.io/pypi/dm/sentencepiece?style=flat-square&logo=pypi&logoColor=white)](https://pypi.org/project/sentencepiece/)
[![Contributions welcome](https://img.shields.io/badge/contributions-welcome-brightgreen.svg)](CONTRIBUTING.md)
[![License](https://img.shields.io/badge/License-Apache%202.0-brightgreen.svg)](https://opensource.org/licenses/Apache-2.0)
[![SLSA 3](https://slsa.dev/images/gh-badge-level3.svg)](https://slsa.dev)
[![Documentation](https://img.shields.io/badge/docs-google.github.io%2Fsentencepiece-blue)](https://google.github.io/sentencepiece/)

SentencePiece is a fast, lightweight, and unsupervised text tokenizer and detokenizer designed for neural network-based text generation systems (such as Large Language Models) where the vocabulary size is fixed prior to training.

It implements **subword units**—including **Byte-Pair-Encoding (BPE)** [[Sennrich et al.](https://www.aclweb.org/anthology/P16-1162)] and the **unigram language model** [[Kudo.](https://arxiv.org/abs/1804.10959)]—with the ability to train directly from raw sentences. By treating input text as a raw sequence of Unicode characters, SentencePiece enables a purely end-to-end, language-independent pipeline that completely eliminates the need for language-specific pre- or post-processing.

***This is not an official Google product.***

---

## Quick Start (Python)

SentencePiece provides an easy-to-use Python module. Install it via `pip`:

```bash
pip install sentencepiece
```

### Basic Example

Here is how to train a model, encode text into tokens/IDs, and decode them back to the original string:

```python
import sentencepiece as spm

# 1. Train a model directly from a raw text file.
# (No pre-tokenization or language-specific preprocessing required!)
spm.SentencePieceTrainer.train(
    input='data/botchan.txt', 
    model_prefix='m', 
    vocab_size=1000
)

# 2. Load the trained model.
sp = spm.SentencePieceProcessor(model_file='m.model')

# 3. Encode raw text into subword pieces (strings) or vocabulary IDs (integers).
text = "I saw a girl with a telescope."
pieces = sp.encode(text, return_type=str)
ids = sp.encode(text, return_type=int)

print(f"Pieces: {pieces}")
# Output: ['▁I', '▁saw', '▁a', '▁girl', '▁with', '▁a', '▁', 'te', 'le', 's', 'c', 'o', 'pe', '.']

print(f"IDs:    {ids}")
# Outpu
阅读完整原文

项目深度分析 AI 生成

LLM多语言词表优化与Token压缩率分析SaaS

产品构想基于SentencePiece为企业提供专有语料的Token效率诊断工具,评估BPE/Unigram在特定领域的压缩率、吞吐量,并自动生成词表扩增/剪枝方案以节省LLM训练与API调用成本。
核心功能语料上传分析、Token压缩比对比看板、SentencePiece词表合并/扩增生成器、下游模型推理成本预估报告
目标用户垂直大模型研发团队、企业内部LLM架构师
难度/周期中等 · 4-6周 · 成本:极低(Web服务与少量计算节点)
收费模式按分析语料量计费或月度SaaS订阅(Freemium)
竞争风险主流框架(如HuggingFace Tokenizers)自带部分工具,单纯工具属性较薄弱
依据 数据支持的判断

垂直领域专有Tokenization训练与微调服务包

产品构想针对医疗、法律、编程语言等专业语料,提供预制好且经过充分正则化(Subword Regularization)的高性能SentencePiece模型及迁移扩词工具链。
核心功能领域专用.model预训练分词器、多语言混合训练调参脚本、与HuggingFace/Llama架构无缝对接转换器
目标用户垂直领域大模型微调工程师、自研垂直模型的中小企业
难度/周期低 · 2-3周 · 成本:低(基础计算服务器)
收费模式售卖行业模型包(一次性付费)及定制词表训练咨询服务
竞争风险开源社区容易复制类似训练配置,市场天花板受限
依据 已验证事实

移动端与嵌入式超轻量分词推理引擎 (SP-Lite)

产品构想利用SentencePiece原生C++和轻量(~6MB)特性,封装针对iOS/Android/WebAssembly的极简离线分词SDK,专为端侧小语言模型(SLM)推理提供零依赖分词支持。
核心功能C++/Rust/WASM跨平台绑定、超低内存占用、无预处理/后处理开销、兼容ONNX/TFLite端侧流
目标用户端侧AI应用开发者、边缘设备算法工程师
难度/周期高 · 8-12周 · 成本:低(个人设备与测试用移动终端)
收费模式商用闭源SDK授权许可(按应用或设备激活量阶梯收费)
竞争风险端侧LLM市场发展节奏尚在早期,直接付费意愿可能低于云端场景(推测)
依据 AI推测
AI 基于仓库公开数据分析生成,含推测成分,不构成收益承诺。
报告会保存到 个人中心

竞品与相似项目 GitHub Search 真实检索

相似项目数据正在完善中,暂不展示(避免误导)

项目优势与风险

技术成熟度创建时间待补全,最近推送 ,发布过 27 个 Release
社区活跃Star 12,170 / Fork 0 / Issue 0(数据支持,可自行核实)
许可证未检测到(需人工确认)
主要风险上游项目方向可能变化;同赛道竞争者较多(见竞品表);热度与需求不完全等价

安装与使用

此项目未提供 Docker 镜像,安装步骤以原仓库 README 为准(涉及依赖安装与环境配置,对新手门槛较高)。