What is unigram tokenisation?
Unigram tokenisation is a subword tokenisation method that splits text into the most probable subword sequence using a simple language model assigning each subword a probability, shrinking the vocabulary from a large candidate set by dropping the least useful pieces.
Unlike Byte Pair Encoding, which starts from characters and grows the vocabulary by merging frequent pairs, unigram starts large and prunes. Because it scores several segmentations of a word by probability, different segmentations can be sampled during training.
- Topic
- Core concepts
- Also known as
- Unigram tokenization, unigram LM
- Origin
- Kudo, 2018
How unigram tokenisation works
- A large candidate vocabulary is built from frequent substrings in training text.
- Each candidate's probability is estimated iteratively so the candidates best explain the text.
- Candidates whose removal least reduces total likelihood are dropped until the target size is reached.
- New text is tokenised with the most probable segmentation; training can sample alternatives.
In more detail
The independence assumption, EM and Viterbi
Mathematically, the unigram model assumes subwords occur independently, so the probability of a segmentation is the product of its pieces' probabilities. During training, subword probabilities are estimated with the Expectation-Maximisation (EM) algorithm and during encoding, the optimal split is found efficiently via the Viterbi algorithm.
Unicode normalisation and byte fallback
Practical SentencePiece Unigram deployments should configure character normalisation (such as NFKC versus identity) and enable byte fallback. Without byte fallback, unseen characters such as rare symbols or emojis collapse into an unknown (
Where it is used in the model ecosystem
SentencePiece Unigram underpins classic multilingual and encoder-decoder models such as T5, mT5, ALBERT, XLNet and XLM-R, whereas many modern open-weight decoder LLMs (such as the Llama 3 and Qwen families) favour byte-level BPE for deterministic merging and clean handling of code and bytes. Unigram remains attractive for domain-specific compact models and agglutinative languages.
Commonly confused terms
| Term | How it differs |
|---|---|
| WordPiece | WordPiece also grows a vocabulary bottom-up like BPE, but merges pairs that maximise training-corpus likelihood rather than raw frequency and encodes words greedily left-to-right at inference without Unigram's probabilistic segmentation sampling. |
| SentencePiece | SentencePiece is a language-independent tokenisation toolkit and library that implements both Unigram and BPE directly over raw Unicode streams (treating spaces as explicit markers like '▁'), not a single tokenisation algorithm by itself. |
Why unigram tokenisation matters for on-premises AI
Tokeniser choice decides how many tokens a word becomes, especially in agglutinative languages such as Turkish, affecting cost, context use and model quality. The paper proposing the method reports that subword regularisation, sampling segmentations during training, gives consistent gains especially in low-resource and out-of-domain settings. A language-independent tool implementing it trains directly from raw sentences without pre-tokenisation, so it also works for languages without spaces.
Training its own model on policy and claims texts, an insurer trains a unigram tokeniser on Turkish text; comparing tokens per word with a general tokeniser on the same samples, it picks the vocabulary size accordingly.
Common questions
How does unigram tokenisation differ from BPE?
BPE starts small and grows by merging frequent pairs. Unigram starts large, prunes by probability and can weigh several segmentations.
What is subword regularisation?
Sampling different segmentations of the same word during training, making the model more robust to segmentation ambiguity.
Related terms
Sources
- Kudo, Subword Regularization: Improving Neural Network Translation Models with Multiple Subword Candidates, 2018
- Kudo and Richardson, SentencePiece: A simple and language independent subword tokenizer and detokenizer for Neural Text Processing, 2018
In the glossary: Glossary, R to Z