Part 3 · The Maths I: Tokens and the Objective
From bytes to tokens: BPE
Start from raw bytes: 256 possible values, every text representable, no unknown-token problem ever. The cost is length — one English word is four to five bytes, so sequences are long and attention is quadratic in length.
Byte-pair encoding buys length back. Count every adjacent
pair in the corpus, merge the most frequent one into a new symbol, and repeat.
Frequent sequences ( the, ing) become single
tokens; rare ones stay in pieces. After k merges the vocabulary is 256 + k.
The trade is now visible. More merges means fewer tokens per document (cheaper attention, more text per context) but a larger vocabulary, and a larger vocabulary means a harder prediction at every step and a bigger embedding matrix. Compression and per-token difficulty move together.