Zenaique

A tokenizer has a 'vocabulary'. What is it, and why does its size matter for the model?

Flashcard·Easy·4.0 · 0·~30s·Asked atAccentureFiddler AiPromptlayer·Relevant atOpenAI
Attempt it
TL;DR

A tokenizer vocabulary is the fixed numbered list of token ids the tokenizer can emit. Its size is set at training time and directly determines the row count of the embedding matrix and the column count of the lm_head.

Memory aid
Sign in to see the mnemonic that makes this stick.
Easy to grasp

Imagine the language model only knows a finite list of stamps it can use, like a kid with a sticker book. The sticker book is the vocabulary. Every sticker has a number printed on it, and the model can only ever stick stickers it owns. When the tokenizer reads your prompt, it figures out which stickers to lay out to represent your text. When the model replies, it picks stickers one at a time from the same book. The number of pages in the book is the vocabulary size. A bigger book lets the model represent more things with single stickers (so common words become one sticker instead of three), but every page in the book costs memory inside the model. Picking a vocabulary size is picking how big the sticker book should be before you start training.

Concept explanation~2 min read

Everything you need to truly understand this topic: intuition, mechanics, step by step explanation, code, formulas, and worked example. Click to expand.

The vocabulary is one of the most concrete and least glamorous parts of a language model. It is a numbered list of byte sequences that defines exactly what the model can read and write. Get it wrong at training time and you cannot fix it later; get it right and most users of the model will never have to think about it.

This deep dive defines the vocabulary precisely, identifies the two model components that depend on its size, walks the tradeoff space for picking the size, and names the typical 2026 values for the model families you are likely to encounter.

The vocabulary, defined precisely

The vocabulary of a tokenizer is the fixed, ordered set of all token ids that the tokenizer can ever produce. It is a list indexed from 0 to vocab_size minus 1, where each entry is a specific byte sequence. The tokenizer maps text to ids on encode and ids back to bytes on decode, using this list as the lookup table.

For a byte-level BPE tokenizer, the vocabulary is built constructively at training time. The starting vocabulary is the 256 byte values, occupying ids 0 through 255 (or some permutation). Then each merge rule in the training procedure adds a new id whose entry is the concatenation of the byte sequences of the two ids being merged. Training stops when the vocabulary reaches the target size, at which point the list is frozen.

Special tokens are added separately, typically after the BPE merges. BOS, EOS, PAD, and any role markers (such as the chat template tokens <|im_start|> and <|im_end|> in OpenAI models, or [INST] in Mistral) each get their own id, occupying entries in the vocabulary alongside content tokens. The total vocab_size includes both.

This numbered list is what the model actually computes over. Every probability the model assigns is a probability over these ids. Every embedding the model looks up is keyed by one of these ids. The vocabulary is the discrete bridge between text and tensor.

Why vocab_size matters for model architecture
The vocab-size tradeoff
Typical 2026 vocabulary sizes
Three practical consequences
Sign in to unlock the full deep dive.

Situations where this technique stops working.

Sign in to see when this approach fails.

2–4 min · Everything important, quickly.

Sign in to see the quick scan of the deep dive.

Real products, models, and research that use this idea.

  • OpenAI's tiktoken cl100k_base has 100,256 tokens (used by GPT-4 and GPT-3.5-turbo); o200k_base has approximately 200,019 tokens (used by GPT-4o, o1, o3, GPT-5, GPT-5.5).
  • Meta's Llama 3 and Llama 4 use a 128K-token byte-level BPE vocabulary, expanded from Llama 2's 32K SentencePiece vocabulary primarily to improve multilingual and code performance.
Sign in to see more production examples.

What an interviewer would ask next. Try answering before peeking at the approach.

QIf you wanted to add a new special token to a pretrained model, what would actually have to happen?
A

You would add the token id to the tokenizer (extending vocab_size by one), add a new row to the embedding matrix and a new column to the lm_head (both randomly initialized), and fine-tune to give the new token meaningful weights. Skipping the fine-tune produces garbage outputs for that token.

2 more follow-ups an interviewer would ask next. Sign in to reveal them.

Red flags & common mistakes

The phrases that signal junior thinking. Click to expand.

Most common mistake

Confusing vocabulary size with context-window size. Vocabulary is how many distinct tokens exist; context window is how many tokens fit in one prompt. They are unrelated parameters.

Sign in to see all red flags and common mistakes.

60 second bullets to scan on the way to the call.

  • Define the vocabulary as the numbered, fixed set of token ids the tokenizer can emit.

  • Identify the two model components whose shape depends on vocab_size.

Sign in to unlock the revision sheet.

Primary sources. Browse if you want the original framing.

Similar questions

Same topic, related formats. Practice these next.

4 curated
Next question
Why does BPE tokenization use subwords instead of words or characters?
Flashcard·Easy