BPE grows the vocabulary by adding merges. Unigram does the opposite. Explain the difference.
BPE grows the vocabulary by merging the most frequent pair (additive, deterministic). Unigram LM shrinks a large candidate vocabulary by pruning the least useful tokens (subtractive, probabilistic, supports sampling).
Imagine two ways to build a Lego set. The first way starts with single bricks. You glue together the two bricks you use together most often, then repeat, until you have a small collection of useful chunks. That is BPE. Each turn adds one new piece. The second way works the other direction. You start with every Lego shape that exists, even strange ones, and you keep throwing out the shape you would miss least when building things. After enough rounds you are left with a smaller box of shapes that still let you build almost anything. That is Unigram LM. One adds, the other prunes. There is another difference. BPE always builds a thing one way. Unigram LM remembers how often each shape gets used, so it can offer alternative builds of the same thing, which is handy when you want to train a model on slightly varied versions of the same input.
Detailed answer & concept explanation~6 min readEverything you need to truly understand this topic: intuition, mechanics, step by step explanation, code, formulas, and worked example. Click to expand.
Everything you need to truly understand this topic: intuition, mechanics, step by step explanation, code, formulas, and worked example. Click to expand.
Everything you need to truly understand this topic: intuition, mechanics, step by step explanation, code, formulas, and worked example.
Everything important, quickly.
4 min: name the direction split (additive merging versus subtractive pruning), the optimization objective for each, the default and sampled segmentation behavior, the subword regularization story, and place each algorithm in the 2026 model landscape.
Real products, models, and research that use this idea.
- Llama 2 used SentencePiece with Unigram LM and a 32K vocabulary; Llama 3 and 4 switched to byte-level BPE with a 128K vocabulary, marking the high-profile generative-LLM move from Unigram to BPE.
- Google's Gemma family uses SentencePiece Unigram LM; T5 and FLAN-T5 also use Unigram LM via SentencePiece.
- OpenAI's tiktoken is byte-level BPE end to end; cl100k_base and o200k_base are both BPE encoders.
- SentencePiece supports both modes via the model_type parameter, so the same tooling can produce a BPE tokenizer or a Unigram LM tokenizer depending on which way you point it.
What an interviewer would ask next. Try answering before peeking at the approach.
QWhy does Unigram LM use EM rather than a simpler optimization loop?
QIf both algorithms produce a vocabulary of similar size on the same corpus, why do they encode strings differently?
Don't say thisRed flags and common mistakes that signal junior thinking. Click to expand.
Red flags and common mistakes that signal junior thinking. Click to expand.
Calling Unigram LM 'just a different scoring function for greedy merges'. It is the opposite direction: Unigram LM starts large and prunes, while BPE starts small and grows. The training procedure and the output behavior both differ.
The night-before-the-interview bullets. Scan these on the way to the call.
Primary sources. Skim if you want the original framing.
Same topic, related formats. Practice these next.