sentencepiece
Agent skill fromOrchestra-Research/AI-Research-SKILLs
Language-independent tokenizer treating text as raw Unicode. Supports BPE and Unigram algorithms. Fast (50k sentences/sec), lightweight (6MB memory), deterministic vocabulary. Used by T5, ALBERT, XLNet, mBART. Train on raw text without pre-tokenization. Use when you need multilingual support, CJK languages, or reproducible tokenization.
How to install sentencepiece
install sentencepiece
# install the AI-Research-SKILLs pack with the skills CLI
npx skills add Orchestra-Research/AI-Research-SKILLs# or add only this skill to Claude Code: copy the folder
02-tokenization/sentencepiece/
# into
~/.claude/skills/sentencepiece/ (all projects)
.claude/skills/sentencepiece/ (one project)
1# SentencePiece - Language-Independent Tokenization23Unsupervised tokenizer that works on raw text without language-specific preprocessing.45## When to use SentencePiece67**Use SentencePiece when:**8- Building multilingual models (no language-specific rules)9- Working with CJK languages (Chinese, Japanese, Korean)10- Need reproducible tokenization (deterministic vocabulary)11- Want to train on raw text (no pre-tokenization needed)12- Require lightweight deployment (6MB memory, 50k sentences/sec)1314**Performance**:15- **Speed**: 50,000 sentences/sec16- **Memory**: ~6MB for loaded model17- **Languages**: All (language-independent)1819**Use alternatives instead**:20- **HuggingFace Tokenizers**: Faster training, more flexibility21- **tiktoken**: OpenAI models (GPT-3.5/4)22- **BERT WordPiece**: English-centric tasks2324## Quick start2526### Installation2728```bash29# Python30pip install sentencepiece3132# C++ (requires CMake)33git clone https://github.com/google/sentencepiece.git34cd sentencepiece35mkdir build && cd build36cmake .. && make -j $(nproc)37sudo make install38```3940### Train model4142```bash43# Command-line (BPE with 8000 vocab)44spm_train --input=data.txt --model_prefix=m --vocab_size=8000 --model_type=bpe4546# Python API47import sentencepiece as spm4849spm.SentencePieceTrainer.train(50 input='data.txt',51 model_prefix='m',52 vocab_size=8000,53 model_type='bpe'54)55```5657**Training time**: ~1-2 minutes for 100MB corpus5859### Encode and decode6061```python62import sentencepiece as spm6364# Load model65…
Excerpt shown under the repository's MIT license.
