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.
Concept explanation~2 min read
Everything you need to truly understand this topic: intuition, mechanics, step by step explanation, code, formulas, and worked example. Click to expand.
Concept explanation~2 min read
Everything you need to truly understand this topic: intuition, mechanics, step by step explanation, code, formulas, and worked example. Click to expand.
BPE and Unigram LM are the two subword tokenizer training algorithms that genuinely compete in 2026. They differ along enough axes (direction, optimization, determinism, sampling support) that the choice has real downstream consequences for both training and inference behavior.
This deep dive walks through each axis in turn, names the production homes of each algorithm in mid-2026, and finishes with the practical interview framing of why one wins where the other does.
Direction: grow versus prune
The headline difference is the direction of vocabulary construction.
BPE is additive. Training starts from the base alphabet (bytes or characters). On every iteration the algorithm counts adjacent pairs across the corpus, picks the most frequent pair, merges every occurrence of that pair into a new token, and adds the new token to the vocabulary. After enough iterations the vocabulary reaches the target size. The training artifact is an ordered list of merge rules that can be replayed at encoding time.
Unigram LM is subtractive. Training starts from a large candidate vocabulary, typically built by enumerating common substrings up to some length. On every iteration the algorithm estimates how much corpus likelihood would drop if a given token were removed, picks the tokens with the smallest expected drop, and prunes them. After enough rounds the vocabulary shrinks to the target size. The training artifact is a vocabulary with associated token probabilities (not a merge list).
This split has consequences. Greedy growth from a small base tends to produce a vocabulary biased toward high-frequency bigrams; pruning from a large superset under a likelihood objective produces a vocabulary biased toward statistical informativeness. On languages with rich morphology the two often disagree noticeably about where to split.
Situations where this technique stops working.
2–4 min · Everything important, quickly.
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.
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?
Token probabilities and the best segmentation of any given string are interdependent. EM handles this by alternating: in the E step, compute expected token counts given current probabilities and current most-likely segmentations; in the M step, update probabilities to match the expected counts; iterate to convergence. Greedy alternatives exist but EM gives the principled likelihood-maximizing solution.
Red flags & common mistakes
The phrases that signal junior thinking. Click to expand.
Red flags & common mistakes
The phrases 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.
60 second bullets to scan on the way to the call.
State the direction difference (additive merging versus subtractive pruning).
State the optimization difference (per-step frequency versus corpus likelihood under a unigram model).
Primary sources. Browse if you want the original framing.
Same topic, related formats. Practice these next.