Spot the error: 'BPE finds the globally optimal vocabulary by iteratively merging the most frequent pair.'
Click any words you think contain an error. Click again to unmark.
BPE is greedy: it merges the highest-frequency pair at each step with no lookahead, so each merge is locally optimal, not globally optimal.
Imagine driving home and always turning toward whichever road looks busiest right now, never checking a map. You make a sensible choice at every junction, but the full route can still be far from the shortest one, because a good early turn can lock you out of a better path later. BPE works like that. At each step it merges whatever pair is most frequent right then, commits to it forever, and never reconsiders. The final vocabulary is reasonable but not provably the best. A planner that scored whole routes, which is what the Unigram approach does, could find a better overall answer that no single greedy turn would reveal.
Detailed answer & concept explanation~3 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.
2 min: greedy per-step argmax + no lookahead/backtrack + local vs global optimality + Unigram likelihood pruning + why greedy still ships.
Real products, models, and research that use this idea.
- OpenAI's cl100k_base and o200k_base both use greedy BPE merges; they are fast and deterministic, not provably optimal.
- SentencePiece's Unigram LM mode prunes tokens by corpus likelihood, the global objective BPE's greedy loop lacks, and powers Llama and T5 tokenizers.
- HuggingFace tokenizers exposes both a greedy BPE trainer and a Unigram trainer, letting teams pick local-greedy speed versus likelihood-driven segmentation.
What an interviewer would ask next. Try answering before peeking at the approach.
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 BPE an exact or globally optimal algorithm. It is greedy: each merge is locally optimal, and the cumulative vocabulary carries no global guarantee.
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.