Handling Unknown Words in Tokenization
A word the tokenizer has never encountered is not a problem at this stage, because each of its letters already has an entry.
Why a Fixed Vocabulary Struggles With New Words
A language model does not read raw text one letter at a time the way a person does. Instead, text is split into units called tokens, and each token is looked up in a fixed vocabulary. The hard design question is what those units should be, and the answer decides what the model can and cannot represent.
Consider the two obvious choices. If every whole word were a unit, the vocabulary would have to list every word that might ever appear, and any word missing from that list would have no representation at all. If every single character were a unit, the vocabulary would be tiny, but every word would become a long sequence of pieces that carries little meaning on its own.
What do you think happens?
If a whole-word vocabulary meets a word it has never seen, what happens to that word?
Reveal answer
The word has no representation at all
A whole-word vocabulary can only represent words it already lists. Any word missing from the list has no entry to map to, which is the problem BPE is designed to avoid.
Byte Pair Encoding, usually abbreviated BPE, sits between these two extremes. Its strategy is to build a vocabulary that begins with small pieces and grows by combining the pieces that appear together most often. The result can contain common whole words, useful fragments of longer words, and single characters as a fallback. This article follows that construction one stage at a time, so you can see what the tokenizer is doing rather than memorizing its outcome.
Starting From Single Characters
The first stage of BPE is deliberately simple. Before any merging happens, the vocabulary is filled with every individual single character, such as the letters a, b, and so on. At this point nothing has been combined, so the vocabulary is just the alphabet the tokenizer has to handle.
Because every character is present, the tokenizer always has a way to represent any text built from those characters, even text it has never seen before. A word the tokenizer has never encountered is not a problem at this stage, because each of its letters already has an entry.
The diagram shows the starting point in miniature. The word low is split into the characters l, o, and w, and each of those characters already has an entry, so low can be represented before a single merge has occurred. Merging only adds new entries on top of this alphabet; it never removes the ability to spell anything out letter by letter.
Merging Frequent Pairs Into Subwords
After the characters are in place, BPE begins merging character combinations that frequently occur together. The source gives a concrete case: the characters d and e may be merged into the subword de. This is a useful merge because de shows up in many common English words, including define, depend, made, and hidden. A single stored piece can stand in for a recurring fragment across many different words.
Notice what caused the merge. The decision does not come from treating d and e as special letters or from a hand-written rule about English spelling. It comes from how often the two characters occur together in the text. Subwords are shaped by frequency, and later they can be merged further into frequent whole words.
Now trace one merge step on the word define. Before the merge it is six separate character tokens. After the pair d and e is merged into de, the same word is five tokens. The diagram below shows that change.
The before row has six tokens and the after row has five. The pair de now appears as one token, and every other letter is unchanged. The merge did not change the meaning of define to the tokenizer; it only changed how many pieces the word is cut into. The same reasoning applies to made, which becomes m, a, de, and to hidden, which gains a single de token where the d and e were.
The Frequency Cutoff Decides Which Merges Happen
The source states that the merges are determined by a frequency cutoff. A cutoff is a threshold: a combination of characters or subwords has to occur often enough to pass it before it is merged. This is what turns the general idea of merging frequent things into a concrete rule. Without a cutoff, the tokenizer would have no stated criterion for deciding when a combination is common enough to deserve its own entry.
Read the flowchart as a per-pair test. A candidate pair is counted across the text, and the count is compared with the cutoff. If the pair passes, it is merged into a subword. If it falls short, it is skipped and remains as the smaller pieces it was built from. Each candidate is judged on its own count, so the same rule applies to a pair of letters and to a pair of longer subwords.
The cutoff also explains why the final vocabulary is a mix of sizes. Combinations that clear the threshold become subwords or even whole words, while combinations that fall short remain as smaller pieces. The cutoff therefore controls the balance between compact pieces and longer, more specific units.
Tracing How Unknown Words Fall Back
Here is what the construction gives you when a word arrives that the vocabulary does not hold whole. A common word that cleared the cutoff can be stored directly and become a single token. A rare or unseen word is instead cut into whatever pieces the vocabulary does contain, which can be subwords, and in the worst case individual characters. Because the characters are always present, the word is still representable.
The rare word dewed is an illustrative case, not a word the source discusses. Suppose the vocabulary holds the characters d, e, and w, and the merged subword de. The tokenizer can cover dewed with de, then w, then the single characters e and d, so the word is represented without any entry for dewed itself. The common word define is a different story: it can be a single token only because it appeared often enough to be stored directly.
Mistakes Beginners Make With Merges
Common mistake Believing an unknown word causes the tokenizer to fail
What it looks likeA word like dewed never appeared in the training text, so it has no whole-word entry.
Why it failsBecause the vocabulary starts with every single character, any word built from those characters can still be split into pieces.
Do this insteadAn unseen word falls back to known subwords and characters rather than being rejected.
Common mistake Thinking a merge creates a meaning for the merged piece
What it looks likeAfter d and e merge into de, it is tempting to assume the tokenizer now knows that de means something.
Why it failsThe merge is decided only by how often the characters occur together in the text, not by any meaning.
Do this insteadTreat de as a frequent fragment whose value comes from how often it recurs, not from a definition.
Common mistake Assuming every frequent combination is merged regardless of count
What it looks likeA pair that appears only a couple of times is assumed to be merged because it looks like a real fragment.
Why it failsA frequency cutoff is a threshold, and a pair that falls short of it is skipped and kept as smaller pieces.
Do this insteadCheck the pair's count against the cutoff before deciding whether it becomes a subword.
Common mistake Confusing the number of tokens with the number of characters, when merges only reduce the token count for the words that contain the merged pair
Practice Tracing a Merge
Suppose the pair d and e has been merged into de. Using the word list define, depend, made, and hidden, which of these words have fewer tokens after the merge, and which stays the same length? Write the token sequence for hidden before and after the merge.
Hints
- Look for every place where the letter d is immediately followed by the letter e.
- A word with no occurrence of the pair keeps its original token count.
- Each occurrence of de replaces two tokens with one.
A candidate pair appears fewer times than the frequency cutoff. Explain what happens to the pair, and what the vocabulary still contains for the characters that make it up.
Hints
- Recall what the cutoff compares against.
- Think about what remains when a merge is skipped.
Key Takeaways
- BPE starts its vocabulary with every individual single character, so any text built from those characters can be represented, including unseen words.
- Frequently co-occurring character combinations are merged into subwords, such as d and e becoming de, and the merge is driven by frequency rather than hand-written rules.
- A frequency cutoff is the threshold a combination must reach before it is merged, which is why the final vocabulary is a mix of characters, subwords, and whole words.
- A merge reduces the token count only for words that contain the merged pair, and a rare word falls back to known subwords or single characters.