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

  1. A large candidate vocabulary is built from frequent substrings in training text.
  2. Each candidate's probability is estimated iteratively so the candidates best explain the text.
  3. Candidates whose removal least reduces total likelihood are dropped until the target size is reached.
  4. 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 () token, breaking lossless detokenisation in code, structured JSON or document identifiers.

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

TermHow it differs
WordPieceWordPiece 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.
SentencePieceSentencePiece 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.

ON-PREMISES EXAMPLE

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.

Sources

In the glossary: Glossary, R to Z

What does this term mean for your infrastructure?

We can work out together in a technical assessment how it maps onto your data, hardware and security requirements.

Request a technical assessment →

This site sets no cookies. Visitor numbers are counted in aggregate using a cookieless method that does not identify anyone. See the Privacy Policy for details.