How does WordPiece decide which pair to merge, compared to BPE?
BPE merges the most frequent pair; WordPiece merges the pair with the highest likelihood gain, freq(AB) / (freq(A)·freq(B)), favoring statistical dependence over raw count.
Imagine you run a sandwich shop and want a one-tap button for the pairs people actually order together. One way is to count every time two items show up in the same order and pick the biggest count. But bread is in almost everything, so 'bread plus anything' wins by sheer volume even when nobody pairs them on purpose. WordPiece picks differently. It asks: when these two items appear together, is that more often than you'd expect if people chose them independently? Peanut butter and jelly score high because they truly travel as a pair, even if each alone is less common than bread. WordPiece prints buttons for the genuine pairings, not the items that are simply everywhere.
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.
3 min: BPE raw count vs WordPiece likelihood gain + the normalized score + PMI intuition + BERT as the consumer + unknown-token risk vs byte-level BPE.
Real products, models, and research that use this idea.
- Google's BERT and its successors DistilBERT and ELECTRA tokenize with WordPiece, which is why their vocabularies mark word continuations with a ## prefix.
- The GPT family and Llama 4 use byte-level BPE instead, choosing raw-frequency merges plus guaranteed byte coverage over WordPiece's likelihood criterion.
- HuggingFace tokenizers exposes WordPiece as a first-class model class, so teams fine-tuning BERT-style encoders in 2026 still train it directly.
What an interviewer would ask next. Try answering before peeking at the approach.
QCan you derive why maximizing corpus likelihood under a unigram model reduces to ranking pairs by freq(AB) / (freq(A)·freq(B))?
QWordPiece can emit [UNK]; how would you eliminate that without abandoning the likelihood criterion?
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 WordPiece 'BPE on subwords.' Both grow a vocabulary by merging, but BPE merges by raw count while WordPiece merges by a likelihood ratio that divides out how common each piece is.
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.