What problem does it solve?
SentencePiece turns raw text into consistent subword tokens without relying on language-specific preprocessing, helping you avoid brittle tokenization pipelines across languages and scripts.
Core Features & Use Cases
- Language-independent tokenization: Treats input as raw Unicode and uses whitespace as a dedicated symbol to learn boundaries automatically.
- BPE or Unigram training: Supports both algorithms, letting you optimize for speed (BPE) or multilingual robustness (Unigram).
- Deterministic and reproducible: Provides stable vocabularies and tokenization behavior for training and inference workflows.
- Subword regularization: Optionally samples alternative segmentations to improve robustness during training (useful for augmentation).
Use case: You need one tokenizer for a multilingual dataset (including CJK) feeding a T5/T5-like or mBART-style model, and you want tokenization consistency without building separate rules per language.
Quick Start
Train a SentencePiece model from your raw text by running spm_train with input='data.txt', model_prefix='m', vocab_size=32000, and model_type='unigram'.