What is an AI vocabulary?
A vocabulary is the fixed list of all tokens a tokeniser recognises and a language model can read as input and produce as output, each with an ID number.
It is also called a vocab. A token is one unit of split text, while the vocabulary is the full set of units. Despite the name it is not only whole words; it also holds subword pieces, single characters, bytes and special tokens.
- Topic
- Core concepts
- Also known as
- Vocab, token vocabulary
How an AI vocabulary works
- A subword algorithm such as Byte Pair Encoding learns a vocabulary of the target size from a training corpus.
- Each token gets an integer ID; text enters the model as a sequence of these IDs.
- Each ID maps to a vector in the embedding table and to an output-layer score that softmax turns into a probability, so both layers grow with the vocabulary.
- Special tokens are added for jobs such as sequence start and end, padding or chat roles.
In more detail
The memory cost of large vocabularies and weight tying
Large modern vocabularies (often 128K to 256K tokens compared with 32K in earlier models) shrink token counts per document, especially for non-English languages, but shift substantial parameter count and memory into the embedding and output (unembedding) matrices. In smaller models, these two tables are often weight-tied to halve memory, yet softmax computation over a huge vocabulary remains a noticeable latency cost during decoding.
Measuring token fertility
Token fertility measures the average number of tokens needed to represent one word in a given language or domain. Comparing fertility on Turkish domain or customer-support samples gives enterprises a fast, hardware-free benchmark for how efficiently candidate models pack context and generate text before running expensive GPU evaluations.
Commonly confused terms
| Term | How it differs |
|---|---|
| Tokeniser | A vocabulary is the static lookup table mapping every known token ID to a string or byte piece; a tokeniser is the algorithm plus rules (normalisation, pre-tokenisation, merge rules) that converts raw input text into a sequence of IDs from that vocabulary. |
| Context window | The context window is the maximum number of tokens a model can attend to in a single forward pass (e.g. 128K positions), whereas vocabulary size is the number of distinct symbols in the dictionary (e.g. 128K entries) from which each position draws. |
Why an AI vocabulary matters for on-premises AI
The vocabulary is fixed when a model is trained, so how efficiently an on-premise model represents Turkish and domain terms depends largely on it. A vocabulary with few Turkish pieces writes the same text in more tokens, which raises token fertility, narrows context and slows inference. It is versioned with the model: after a tokeniser change, embeddings and token counts are not comparable with the old ones.
A telecom operator checks how candidate models' vocabularies represent tariff and product names and favours the model that writes frequent names in few tokens for its in-house customer correspondence system.
Common questions
Can a vocabulary be changed after a model is trained?
Not directly. New tokens can be added, but their embedding vectors have to be learned with further training; this is called vocabulary extension.
How does vocabulary size affect a model?
A large vocabulary writes text in fewer tokens but enlarges the embedding table and output layer. A small one lightens the model but makes sequences longer.
Related terms
- AI token
- AI tokeniser
- Subword tokenisation
- Byte pair encoding (BPE)
- AI tokenisation
- AI vocabulary extension
- Token fertility
- AI embedding
Sources
- Speech and Language Processing, 3rd edition draft
- Neural Machine Translation of Rare Words with Subword Units, 2016
In the glossary: Glossary, R to Z