Trace one byte-pair merge
Watch the spaces around tokens and probability values. · 167 words
Byte-pair encoding, or BPE, learns frequent adjacent symbol pairs and replaces a selected pair with one new symbol. This lets a tokenizer represent many words with a compact vocabulary. To keep the trace small, pretend the training symbols are ASCII characters. Use the words "low", "lower", "lowest", and "newest". The pair ("l", "o") occurs three times. The pairs ("o", "w") and ("w", "e") also occur three times. In this toy trainer, ties go to the first pair in alphabetic order. It therefore merges ("l", "o") into the new symbol "lo".
After the merge, the affected words become "lo w", "lo w e r", and "lo w e s t"; "newest" stays "n e w e s t". The vocabulary now includes "lo". At use time, the tokenizer applies learned merges in order. For the unseen word "lovely", this merge turns its opening "lo" into one symbol, giving "lo v e l y". BPE compresses repeated character patterns. It does not mean that "lo" has learned a concept.
Check your recall
Which pair is merged in the example, and what new symbol does it create?
Check your answer
The pair ("l", "o") is merged because it ties for the highest count and wins the alphabetical tie break, creating the new symbol "lo".
Sources and credits
Original KeyTouch lesson. Background reading · Hugging Face · LLM Course.