1. Everything is bytes
A computer stores text as bytes: numbers from 0 to 255. The letter a is 97, a space is 32,
and an emoji takes four bytes. The simplest tokenizer gives every byte its own token, so the model's
vocabulary is just 256 entries and any text at all can be written down. There is no
"unknown word".
The cost is length. A sentence of 40 letters becomes 40 tokens, and a model reads a fixed number of tokens at a time, so short tokens waste its attention on spelling. Try it: type below with the slider all the way to the left.
3. Byte-pair encoding: learning to merge
To shorten the token list, we let the tokenizer learn from text. It looks for the pair of neighbouring
tokens that appears most often, glues them into one new token, and repeats. Early merges are common letter
pairs (h + e becomes he); later ones build up pieces and whole words
such as ·the (the dot stands for a space). Each merge is one step of the slider above.
Merges are applied in the order they were learned, which is why shrinking the vocabulary is the same as keeping only the first merges. The widget below shows the most recent merge the slider has reached, and the whole recipe.
5. Why not just use words?
Whole words need a huge vocabulary and fail on names, typos and new words. Single bytes never fail but make sequences long. Byte-pair encoding sits in between: common words become one token, rare words are spelled from pieces, and nothing is ever unknown. Drag the slider to 256 merges (the small model's setting) and compare bytes per token with the slider at 0: every extra byte a token covers lets the model's fixed 64-token window see more text.
Try it: paste a word that is not English, or an emoji, and watch it fall back to single bytes
(shown as \xNN). Next chapter: turning these token numbers into vectors the model can learn from.