A tokenizer vocabulary is the fixed, finite set of tokens that a tokenizer can produce, with each token mapped to a unique integer ID. In language models, this list defines the only units the model can ever read or generate: every input string is split into vocabulary entries, and every output is assembled from them one ID at a time.
The vocabulary is built once, before model training, and is then frozen together with the weights. Its size and composition shape sequence length, memory use, multilingual fairness and arithmetic behavior, so choosing it is one of the most consequential and least reversible design decisions in building a large language model.
What a tokenizer vocabulary contains
A tokenizer vocabulary contains subword pieces, whole words, single characters or bytes, and special tokens, each paired with an integer index. The index is what the model actually sees: the tokenizer converts text into a sequence of IDs, and the model looks up each ID in its embedding matrix, a table with one learned vector per vocabulary entry.
Most modern vocabularies also store merge rules or piece scores that tell the tokenizer how to segment unseen text. A byte-level vocabulary starts from all 256 byte values, which guarantees that any string can be encoded without an unknown token, while character-based schemes may need a dedicated unknown token for symbols outside the training corpus.
The following table lists the typical categories of entries and their role.
| Entry type | Example | Purpose |
|---|---|---|
| Base units | Single bytes or characters | Guarantee full coverage of any input |
| Subword pieces | “ization”, “pre”, “ing” | Compose rare words from frequent parts |
| Whole words | ” the”, ” model” | Encode common words in one step |
| Whitespace-prefixed forms | ” data” versus “data” | Preserve word boundaries |
| Special tokens | Beginning-of-sequence, end-of-sequence, padding | Mark structure and control generation |
| Reserved slots | Unused placeholder IDs | Allow later additions without resizing |
How the vocabulary is built
The vocabulary is learned from a representative training corpus by a segmentation algorithm that balances coverage against size. The builder sets a target vocabulary size in advance, and the algorithm selects the pieces that compress the corpus most efficiently within that budget.
Byte-pair encoding starts from bytes and repeatedly merges the most frequent adjacent pair until the target size is reached. WordPiece chooses merges that most increase the likelihood of the training data. Unigram tokenization, usually run through the SentencePiece library, works in the opposite direction: it starts from a large candidate set and prunes pieces whose removal costs the least likelihood.
| Algorithm | Build direction | Segmentation at inference | Common in |
|---|---|---|---|
| Byte-pair encoding | Bottom-up merging | Apply merges in learned order | GPT-style decoder-only models |
| WordPiece | Bottom-up, likelihood-guided | Greedy longest match | BERT and encoder-only models |
| Unigram | Top-down pruning | Most probable segmentation | T5 and many multilingual models |
| Byte-level fallback | Fixed 256 bytes | Bytes for unseen characters | Added to most of the above |
Corpus composition matters as much as the algorithm. A corpus dominated by English web text yields a vocabulary full of English words and fragments, so other languages and source code are split into many more pieces. Builders therefore rebalance the sampling across languages, domains and code before training the tokenizer.
How vocabulary size affects a model
Vocabulary size sets a trade-off between sequence length and parameter cost. A larger vocabulary encodes text in fewer tokens, which shortens sequences, fits more content into the context window and reduces generation steps. It also enlarges the embedding matrix and the output layer, because both scale linearly with the number of entries.
Typical sizes have grown over time. Early encoder models used about 30,000 entries, the GPT-2 family used 50,257, and many current multilingual models use 100,000 to 260,000 entries. The table summarizes the effects of moving along this range.
| Property | Small vocabulary (about 32,000) | Large vocabulary (about 200,000) |
|---|---|---|
| Tokens per English word | About 1.3 to 1.5 | About 1.1 to 1.3 |
| Coverage of other scripts | Often fragmented into bytes | Many whole words and syllables |
| Embedding parameters | Modest share of the model | Large share in small models |
| Training signal per entry | Frequent and well estimated | Rare entries may be undertrained |
| Output softmax cost | Lower per step | Higher per step |
For a model with a hidden size of 4,096, a 200,000-entry vocabulary needs about 820 million parameters for the embedding table alone, and roughly the same again if the output head is not tied. This is why small language models often keep vocabularies smaller than frontier systems do.
Vocabulary design choices that change behavior
Beyond size, several design decisions inside the vocabulary have visible effects on model behavior. They are rarely documented in product material, yet they explain many surprising errors in counting, spelling and arithmetic.
- Digit handling: splitting numbers into single digits gives consistent arithmetic, while multi-digit tokens such as “2024” make carrying and comparison harder.
- Whitespace treatment: keeping leading spaces inside tokens preserves boundaries, and dedicated tokens for runs of spaces greatly improve code efficiency.
- Case sensitivity: separate entries for “Apple” and “apple” retain meaning but consume more slots.
- Pre-tokenization rules: regular expressions that split on punctuation and script boundaries stop merges from crossing words.
- Special token set: chat templates rely on reserved tokens for message roles and the end-of-sequence signal.
Because the model only sees IDs, it has no direct view of the characters inside a token. A question such as how many letters a word contains must be answered from patterns learned in training, which explains why character-level tasks remain weak points even for capable models.
Limitations, risks and common mistakes
The most serious limitation is lock-in: once a model is trained, its vocabulary cannot be swapped without retraining or careful embedding surgery. Adding domain tokens later is possible, but the new embeddings start untrained and need continued pretraining to become useful.
| Symptom | Cause | Remedy |
|---|---|---|
| Glitch tokens | Entries seen often in tokenizer data but rarely in model data | Align corpora and audit rare entries |
| Token tax on languages | English-heavy vocabulary corpus | Rebalance corpus and enlarge vocabulary |
| Wrong token counts | Mixing tokenizers from different models | Always use the model’s own tokenizer |
| Prompt injection via special tokens | Raw user text parsed as control tokens | Escape or disable special-token parsing |
| Poor domain efficiency | Medical or legal terms split into many pieces | Extend vocabulary and continue training |
A frequent operational mistake is to estimate cost or context use with the wrong tokenizer. Different vocabularies can produce token counts that differ by 20 percent or more on the same text, which distorts billing forecasts and truncation limits.
Understanding it simply
A tokenizer vocabulary is like a box of building blocks. Every piece of text must be built only from blocks in that box. Common words get their own large block. Rare words are built from several smaller blocks.
The box is filled once, before the model learns anything. After that, it stays the same. A bigger box means fewer blocks per sentence, but it costs more memory. The key point is simple: the model never sees letters, only block numbers.
Applied in practice
A team building an assistant for Czech and Slovak legal documents starts from an open-weight model with a 32,000-entry vocabulary trained mostly on English. Their tests show that a typical contract needs about 2.4 times more tokens than an English text of similar length, so long contracts overflow the 8,000-token context window and every answer is slow and costly.
The engineers train a new tokenizer on a balanced corpus of Czech, Slovak and English legal text and add about 12,000 new entries to the existing vocabulary. They initialize the new embeddings as averages of the pieces each new token replaces, then run continued pretraining on several billion tokens of legal text.
After the change, the same contracts use roughly 40 percent fewer tokens. Full documents now fit into the context window, response latency drops noticeably, and the per-document processing cost falls in line with the shorter sequences.