How LLMs Work
Book Labs
All labs
02 Book labs · Tokenization

The vocabulary seesaw

From Chapter 2 of Large Language Models from the Ground Up. The same sentence, chopped at four granularities. Slide from single characters up to whole words and watch the seesaw tip: a tiny menu means long sequences; a huge menu means short sequences but a fortune spent on rare words. Every split below is computed live by greedy longest-match over a hand-built vocabulary — no faking.

Interactive

Chop a sentence four ways

Pick a sentence, then drag the granularity slider (or click a stop). Tokens recompute live; the leading space that travels with each word is shown as ·.

Characters~100
Small subword~1,000
Large subword~50,000
Whole words~170,000
common word, whole word split into fragments punctuation
9tokens in this sentence
~50,000vocabulary size
81n² attention comparisons

Sequence length

Menu size & rare-word risk

What to notice

Slide to Characters and read the count: "The cat sat on the mat." becomes 23 tokens — exactly the figure in Chapter 2, and it means 23² = 529 attention comparisons for six words of meaning, versus 7² = 49 as whole words. Slide to Large subword and the grandmother sentence lands on the book's own nine-token split — My · grandmother · unbeliev · ably · tweeted… — common words kept whole, the rare "unbelievably" and "cryptocurrency" assembled from fragments, and every word still spellable. That's the compromise every modern LLM makes: not the shortest sequence, not the smallest menu, but the row where both problems are bearable at once.

← Back to all labs