tokenization -- Byte-Pair Encoding builds the vocab
A model does not read letters. Before anything else your text is cut into tokens, a fixed list of somewhere between fifty thousand and a quarter of a million whole words and word fragments, each with a number of its own. That list is built by starting from single characters and repeatedly gluing together whichever pair of neighbours turns up most often across a large pile of text, so common words end up as one token while rare ones get chopped into several. It is why you are billed per token rather than per word, and why an unusual name, or a language the list was not built around, costs several times more to send than ordinary English.
Interactive page: Byte-Pair Encoding (BPE) -- the step that turns text into the integer token IDs a model consumes, the step before embedding. Anchor: C (transformer block input). Family C.
What it shows
BPE starts from raw characters and repeatedly does one thing: find the most frequent adjacent pair of symbols across the whole corpus (weighted by each word's frequency), merge that pair into a single new symbol, and record a merge rule. Frequent letter sequences ("e"+"s"→"es", "es"+"t"→"est") thus become single tokens — the vocabulary grows and the token count shrinks.
- left: each corpus word as its current sequence of symbol boxes (the just-merged symbol highlighted), with a draggable
×freq; - right-top: the pair-frequency table at this step, the winner (next/just merged) highlighted;
- right-bottom: the merge rules learned so far, in order;
- bottom: the vocab size, the token count (vs the original character count), and the compression.
This is the BPE training loop itself — but not, exactly, the alphabet the production tokenizers run it over. GPT-2/3/4 and Llama-3 train byte-level BPE: the base alphabet is the 256 bytes, after a pre-tokenization regex split, not the characters shown here; Llama-1/2 use SentencePiece BPE with a ▁ word-start marker rather than this page's trailing _. The merge rule is identical; the starting vocabulary, and therefore the merges actually learned, are not. At inference the learned merge rules are simply replayed on new text. The trailing _ marks a word boundary (so a merge can't cross between words).
Step / play the transport to watch the merges form; drag a word's ×freq ↕ to change which pairs win (make lowest frequent and watch est merge sooner); pick a corpus; hover a pair for its count.
Render tier
T1 (Canvas2D: the symbol-segmentation rows + the pair-frequency bars + the merge-rule list + counts).
Wiring
layout.mount + a transport over the merge steps + a corpus select onPointer drag-the-frequency + hover. ?corpus / ?step hooks. Source: page.js.