Zenaique

Spot the error: 'BPE finds the globally optimal vocabulary by iteratively merging the most frequent pair.'

Spot the error·Medium·4.0 · 0·~2 min·Asked atGoldman SachsOpenAISnorkel Ai
Attempt it

Click any words you think contain an error. Click again to unmark.

Mark at least one word to submit.
TL;DR

BPE is greedy: it merges the highest-frequency pair at each step with no lookahead, so each merge is locally optimal, not globally optimal.

Memory aid
Sign in to see the mnemonic that makes this stick.
Easy to grasp

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.

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.

This question looks like a vocabulary quibble, but it probes whether you understand the kind of algorithm BPE is. Calling it globally optimal is not a minor overstatement; it misclassifies a greedy heuristic as an exact optimizer, and the two have very different guarantees.

The statement makes two linked claims: that BPE finds the globally optimal vocabulary, and that it is an exact optimization algorithm guaranteeing the best possible result for a target size. Both are false for the same underlying reason.

We will establish what greedy means here, why local optimality never adds up to a global proof, how the Unigram LM tokenizer takes a genuinely different approach, and why greedy BPE still wins in production despite all of this.

What 'greedy' means for BPE

BPE builds a vocabulary by repeating one move. Count every adjacent pair in the current corpus representation, take the single most frequent pair, add it as a new symbol, and replace all its occurrences. Repeat until the vocabulary hits the target size.

The decision rule is a pure argmax on current frequency:

merget=argmax(a,b)  countt(a,b)\text{merge}_t = \arg\max_{(a,b)} \; \text{count}_t(a, b)

Two properties define the greedy character. The choice uses only present information, no estimate of how this merge affects future options. And the choice is irrevocable: once a pair is merged it is never un-merged, and no alternative merge order is ever explored. That is the textbook signature of a greedy algorithm.

Why local optimality is not global optimality
How Unigram LM takes a global view
Why greedy still ships everywhere
Sign in to unlock the full deep dive.

Situations where this technique stops working.

Sign in to see when this approach fails.

2–4 min · Everything important, quickly.

Sign in to see the quick scan of the deep dive.

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.
Sign in to see more production examples.

What an interviewer would ask next. Try answering before peeking at the approach.

QCan you construct a small example where BPE's greedy choice is provably worse than the optimal vocabulary?
A

Build a toy corpus where merging the most frequent pair first blocks a later merge that would compress more; compare total token counts under each order.

1 more follow-up an interviewer would ask next. Sign in to reveal them.

Red flags & common mistakes

The phrases that signal junior thinking. Click to expand.

Most common mistake

Calling BPE an exact or globally optimal algorithm. It is greedy: each merge is locally optimal, and the cumulative vocabulary carries no global guarantee.

Sign in to see all red flags and common mistakes.

60 second bullets to scan on the way to the call.

  • Why each BPE merge is locally optimal

  • Why local optimality at each step gives no global guarantee

Sign in to unlock the revision sheet.

Primary sources. Browse if you want the original framing.

Similar questions

Same topic, related formats. Practice these next.

4 curated
Next question
Why does BPE tokenization use subwords instead of words or characters?
Flashcard·Easy