4.2.4 · D1Tokenization & Language Modeling

Foundations — Vocabulary size tradeoffs

1,705 words8 min readBack to topic

Before you can read Vocabulary size tradeoffs, you need to own every symbol it throws at you. This page builds each one from absolute zero: plain words → the picture → why the topic needs it. We go in order, so each symbol leans only on the ones before it.


1. Text, characters, and tokens

Look at the top of the first figure: the same sentence is cut three different ways. The scissors show where each tokenizer decides to make a break.

Figure — Vocabulary size tradeoffs

2. Vocabulary and its size

Picture a numbered list: entry 0, entry 1, ..., entry . Every token that comes out of the tokenizer must be one of these rows — nothing off-menu is allowed.

The topic needs because it is the first of the two dial settings we trade off. Turning up makes the menu longer (costs memory) but the sequences shorter (saves compute). See 4.2.02-Byte-pair-encoding and 4.2.03-WordPiece-and-SentencePiece for how the menu is actually built.


3. Sequence length

The second figure shows the same fixed text becoming different as changes. Notice: bigger → smaller for the same text, because each fatter token swallows more characters.

Figure — Vocabulary size tradeoffs

The topic needs because it is the second dial — and it appears squared in the compute cost, which is why it matters so much.


4. Average token length

This links and together:

The picture: imagine laying tiles of width over a strip of fixed length (the text). Wider tiles → fewer tiles → smaller . Bigger empirically makes grow (more common groups get their own menu entry), but only slowly — doubling nudges up ~20–30%, not double.


5. Embedding dimension

Picture each token as an arrow floating in a space with directions. is how many independent "meaning-knobs" each token gets.


6. The embedding table:

Now the first cost falls out for free.

Third figure: the grid literally, with the row-count and column-count labelled.

Figure — Vocabulary size tradeoffs

7. Big-O notation and the cost

The fourth figure draws the grid of "who-looks-at-whom" and shows it exploding as grows.

Figure — Vocabulary size tradeoffs

8. Batch and layer counts: and batch size

Why the topic needs them: the memory saved by a shorter sequence gets multiplied by and by every batch you ever run. Small per-batch savings compound into large totals over a training run — that is what tips the breakeven toward large . See 5.1.03-Memory-optimization-techniques.

Recall Quick sanity check on units

Attention score memory for one batch . The scores are scalars (one number per token-pair), so there is no here — a very common mis-step.


Prerequisite map

Characters and tokens

Vocabulary size V

Sequence length n

Average token length ell-bar

Embedding dimension d

Embedding table V times d

Attention cost O of n squared d

Layers L and batch b

Vocabulary size tradeoffs

The two arrows into the topic node T are the whole story: the memory branch () and the compute branch () meet, and choosing is choosing where on that seesaw to sit. This carries straight into 6.2.01-Multilingual-models, where many languages force upward.


Equipment checklist

Cover the right side and answer each before opening the parent note.

What is a token?
A chunk of text the model treats as one indivisible unit — could be a character, word-piece, or whole word.
What does stand for and what does it measure?
Vocabulary size — the number of distinct entries on the tokenizer's fixed menu.
What does measure, and how does it differ from ?
is how many tokens a specific text became; is the size of the menu. Menu size ≠ number of courses ordered.
If a 2000-character text uses , roughly what is ?
tokens.
What is and why does every token need one?
The embedding dimension — the length of the number-vector each token gets so the model can do maths on meaning.
How many parameters does the embedding table hold?
— one row per menu entry, columns per row.
Why does attention cost scale as ?
Every one of tokens compares against all tokens: comparisons.
When goes up, which way does move for the same text, and why?
goes down, because larger raises so each token swallows more characters.
Does the attention-score memory include a factor of ?
No — scores are scalars, one number per token-pair.