Compare BPE, WordPiece, SentencePiece, and byte-level BPE.
Type it the way you would explain it to an interviewer. A few sentences is enough; you can't break anything.
Model answer: the part to lead with
These are two algorithms, a library, and a base-alphabet choice - a distinction that itself scores points, because people wrongly treat them as four parallel algorithms.
Full worked answer
These are two algorithms, a library, and a base-alphabet choice - a distinction that itself scores points, because people wrongly treat them as four parallel algorithms.
BPE (algorithm): bottom-up, greedy - repeatedly merge the most frequent adjacent pair. Used (in byte-level form) by GPT-2/3/4-family tokenizers (tiktoken) and Llama 3.
WordPiece (algorithm, BERT): same bottom-up scheme but merges the pair that maximises training-corpus likelihood - score ≈ freq(ab) / (freq(a)·freq(b)) - favouring pairs that co-occur more than chance rather than just often. Recognisable by its ## continuation-piece convention. Encoding uses longest-match-first rather than merge replay.
Unigram-LM (algorithm, often used via SentencePiece): top-down - start with a large candidate vocabulary, iteratively prune tokens whose removal least damages the corpus likelihood under a unigram model; encoding picks the most probable segmentation (Viterbi). Supports sampling alternative segmentations for regularization during training.
SentencePiece (library, not an algorithm): implements both BPE and unigram-LM. Its distinctive property: it operates on raw text as a character stream with no external pre-tokenization - whitespace is encoded as a meta-symbol (▁, U+2581) - making it language-agnostic (works for Chinese/Japanese/Thai where there are no spaces) and exactly reversible. Standard for multilingual and many open models (Llama 1/2, T5, Gemma).
Byte-level BPE (base-alphabet choice): run BPE over the 256 byte values instead of Unicode characters. Guarantee: no string is ever out-of-vocabulary - anything, any language, emoji, binary-ish garbage, decomposes to bytes at worst. Cost: rare non-Latin characters can fragment into multiple byte tokens. SentencePiece offers an equivalent escape hatch called byte-fallback.
Practical engineering relevance: tokenizer choice determines token counts (cost, latency, effective context) per language, and mismatched tokenizers are a classic source of bugs when swapping models - never assume token counts transfer across model families.
What a good answer covers
- These are two algorithms, a library, and a base-alphabet choice - a distinction that itself scores…
- BPE (algorithm): bottom-up, greedy - repeatedly merge the most frequent adjacent pair
- Used (in byte-level form) by GPT-2/3/4-family tokenizers (tiktoken) and Llama 3
- WordPiece (algorithm, BERT)
- Recognisable by its ## continuation-piece convention
Key terms: BPE · WordPiece · Unigram-LM · SentencePiece · no external pre-tokenization · Byte-level BPE
In the glossary: BPE · SentencePiece
Interviewer follow-ups to expect
Why does SentencePiece encode whitespace explicitly - what property does that buy?
What is byte-fallback?
Given the same vocab size, why might unigram-LM produce more linguistically natural segmentations than BPE?
Unigram-LM (algorithm, often used via SentencePiece): top-down - start with a large candidate vocabulary, iteratively prune tokens whose removal least damages the corpus likelihood under a unigram model; encoding picks the most probable segmentation (Viterbi). Supports sampling alternative segmentations for regularization during training.
Worked answer from AI-Engineer-Interview-Questions by Om (MIT), reformatted for LLM Prep · answer text last updated 6 November 2026 · scoring and review schedule by LLM Prep