Question bank — WordPiece and SentencePiece
This page is a question bank for WordPiece and SentencePiece. It is not about crunching numbers — it is about the ideas that are easy to get backwards. Each line below hides its answer. Cover the right-hand side, commit to a guess and a reason, then reveal.
Before you start, here is the vocabulary of symbols we lean on, so nothing appears un-earned:
The two pictures behind every trap
Almost every misconception below is a confusion between two mental models. Build them visually first — then the Q&A is just checking you kept them straight.
Picture 1 — WordPiece is a ladder that only climbs
Look at figure s01. The vertical axis is , the corpus log-likelihood — "how happy the model is". The horizontal axis counts merges WordPiece has accepted so far.
- Read the orange dots left to right. Each dot is the state after accepting one merge. Notice they never dip: the curve is a staircase going only up.
- Read a purple arrow. Each arrow is one merge, labelled with its gain (like
+0.90). WordPiece computes for every candidate pair, then takes the single largest positive one — that arrow. A pair whose arrow would point down (negative PMI) is simply never climbed. - Watch the gains shrink (
+0.90, +0.70, +0.50, …). Early merges grab the tightest-bound, highest-PMI pairs; later merges have slimmer pickings. This falling step-size is why WordPiece is greedy-but-safe: it always spends its next merge on the biggest remaining likelihood win.

Hold this in mind for every "True/False" about merging: WordPiece is one arrow chosen per step, always the biggest climb, never a descent.
Picture 2 — Unigram is a spray, not a single dart
Now look at figure s02 — the same word dogs, a completely different spirit. Each horizontal bar is one possible way to cut the word, and its length is the posterior soft weight that segmentation receives.
- The bars sum to 1. The E-step does not pick a split; it distributes a total weight of across all splits, in proportion to each split's probability under current .
- Follow the orange bar
[dog, s](weight ) and the teal bar[dogs](weight ). Both are alive at once. The tiny plum bars ([do,g,s],[d,o,gs],[d,o,g,s]) get slivers of weight — down-weighted, never deleted. - Read the ink arrow: it points at the orange bar and says "greedy WordPiece would pick just this one." That contrast is the whole lesson — WordPiece throws one dart (longest-match), unigram sprays weight, and the M-step later turns those soft weights into new token probabilities.

Every "soft vs hard" trap below is really asking: did you remember the spray, or did you collapse it to a single dart?
True or false — justify
WordPiece merges whichever pair of tokens appears most frequently in the corpus.
A pair that occurs 10,000 times will always be merged before a pair that occurs 500 times, in WordPiece.
the+##dog) loses to a rarer but tightly-bound pair.SentencePiece requires the input to be split on spaces before tokenizing.
▁, so it works on space-less languages (Chinese, Thai). WordPiece is the one needing pre-tokenized, space-separated input.The ## prefix is used by both WordPiece and SentencePiece unigram to mark non-initial pieces.
##. SentencePiece unigram uses plain substrings and recovers word boundaries purely from the ▁ (space) marker.SentencePiece tokenization is exactly reversible back to the original text.
▁ encodes every space (including leading/trailing ones), joining the tokens and swapping ▁→space reconstructs the original stream character-for-character. WordPiece is not guaranteed reversible — the ##/space rejoining can lose spacing info.The unigram model used in both algorithms conditions each token on the previous token.
WordPiece uses a hard, greedy decision at inference; SentencePiece unigram uses a soft, probabilistic one during training.
Adding a merge in WordPiece can never decrease the corpus likelihood.
Both algorithms produce the same tokenization for the same corpus and vocabulary size.
## vs ▁), and different inference (greedy vs probabilistic) generally give different token sets and different splits.Spot the error
"unhappiness → WordPiece → [un, ##happiness], so the second piece always carries ##."
## is not something you decide at output — it is baked into the vocab entry. Two cases: (a) if the vocabulary stores the entry as happiness (no prefix), the output is [un, happiness]; (b) if it stores it as ##happiness, the output is [un, ##happiness]. The prefix marks how the token was learned (word-initial vs non-initial), so you must copy the stored form exactly — you cannot add or drop the ## yourself."SentencePiece scores segmentation [dog, s] as ."
"The likelihood gain formula is just the raw frequency of the pair."
"SentencePiece unigram grows its vocabulary by merging, like BPE."
"Character-level tokenization solves OOV, so subwords are unnecessary."
Why questions
Why does WordPiece pick likelihood gain instead of raw count?
Why does high PMI signal a "meaningful unit"?
un+happy. See Morphology and Compositionality.Why does SentencePiece use the special symbol ▁ instead of just deleting spaces?
hotdog from hot dog. ▁ encodes every space as data, making detokenization exact and lossless.Why is the unigram model trained with Expectation-Maximization rather than a direct formula?
Why does SentencePiece use forward-backward in the E-step instead of listing every segmentation?
Why can WordPiece never split across a word boundary, but SentencePiece can span them?
▁) as one sequence, so a token may include a ▁ and effectively straddle words.Why is WordPiece a natural fit for BERT Architecture while SentencePiece suits T5 and mT5?
## subwords work. T5/mT5 target many languages including space-less ones, needing SentencePiece's raw-stream, language-agnostic design.Edge cases
What does WordPiece output when no subword in the vocabulary matches at the current position?
[UNK] token — the fallback that guarantees termination but signals lost information. Good vocabularies keep this rare by including all single characters.If a vocabulary contains every single character, can WordPiece ever produce [UNK] for known-alphabet text?
[UNK] then only appears for truly unseen characters (e.g. an emoji absent from vocab).In the unigram E-step, what happens to the segmentation [dogs] (the whole word as one token) if P(dogs) is tiny?
[dog, s].What is the tokenization of an empty string, and of a string of only spaces, in SentencePiece?
▁ (each space is real data), so detokenization restores every space exactly.At the extreme, if the target vocabulary size equals the number of distinct characters, what does each algorithm reduce to?
At the other extreme, if the vocabulary is large enough to hold every whole word, what happens on a new rare word at inference?
What if two different segmentations of one word have equal probability under the unigram model?
Can a WordPiece merge ever have negative likelihood gain, and would it be added?
Recall One-line self-check before you leave
WordPiece merges by PMI-weighted likelihood gain (a ladder of upward arrows, hard greedy dart at inference, uses ##); SentencePiece unigram prunes a large vocab by likelihood loss (a spray of soft EM weights, plain substrings, ▁ for spaces).