In natural language processing, a vocabulary is the complete, finite set of discrete tokens—words, subwords, or characters—that a model can understand and generate. Constructed during the tokenizer's training phase, it serves as the lookup table that maps every recognizable text unit to a unique token ID, the numerical index fed into the model's embedding layer. The vocabulary is the model's linguistic boundary; any sequence not decomposable into its constituent tokens is considered out-of-vocabulary (OOV) and cannot be processed.
Glossary
Vocabulary

What is Vocabulary?
The vocabulary is the fixed set of unique tokens that a language model recognizes, mapping each token to a unique integer identifier during training.
The vocabulary size is a critical hyperparameter that directly impacts model performance and efficiency. A larger vocabulary captures more unique terms but increases the embedding matrix's memory footprint, while a smaller vocabulary forces heavier reliance on subword composition. Modern subword algorithms like Byte-Pair Encoding (BPE) and WordPiece construct vocabularies that balance this trade-off, enabling open-vocabulary processing where rare and unseen words are represented as sequences of known subword units, effectively eliminating the OOV problem.
Key Characteristics of a Model Vocabulary
The vocabulary is the fixed set of unique tokens a language model recognizes, mapping each token to a unique integer identifier. Its construction is a critical hyperparameter choice that directly impacts model size, encoding efficiency, and the ability to handle rare or unseen words.
Fixed Token Set
A vocabulary is a static lookup table constructed during the tokenizer's training phase and remains frozen during model training and inference. It defines the complete universe of tokens the model can understand. Any input text must be segmented into sequences of these known tokens. The vocabulary maps each unique token to a Token ID, a unique integer index that serves as the numerical input to the model's embedding layer.
Vocabulary Size Trade-off
The vocabulary size is a critical hyperparameter representing a fundamental trade-off:
- Larger vocabularies: Allow for shorter sequence lengths (higher compression ratio) and can represent whole words, but increase the model's embedding matrix parameters and memory footprint.
- Smaller vocabularies: Reduce the number of trainable parameters but force the tokenizer to split text into more subword units, increasing sequence length and potentially losing semantic granularity. Typical sizes range from 32k (SentencePiece) to 50k+ (GPT models).
Special Tokens
Vocabularies reserve specific integer IDs for control and structural tokens that are not part of natural language. These are essential for model formatting and task-specific behavior:
- [CLS]: A classification token whose final hidden state represents the entire sequence.
- [SEP]: A separator token used to demarcate sentence boundaries.
- [MASK]: A placeholder token for masked language modeling objectives.
- [PAD]: A padding token used to standardize sequence lengths within a batch.
- [UNK]: An unknown token representing out-of-vocabulary words (largely obsolete with subword tokenization).
Out-of-Vocabulary Problem
An Out-of-Vocabulary (OOV) condition occurs when a word or character sequence is absent from the model's fixed vocabulary. In early word-level tokenizers, this was a critical failure mode, forcing the model to map all unknown words to a single [UNK] token, resulting in total information loss. Modern subword tokenization strategies like BPE and WordPiece largely mitigate this by segmenting unknown words into known subword units, ensuring every input can be represented.
Encoding and Decoding
The vocabulary is the central component in two inverse processes:
- Encoding: The conversion of a raw text string into a sequence of Token IDs by applying the tokenizer's merge rules and vocabulary lookup. This produces the numerical input for the model.
- Decoding: The inverse process of converting a sequence of Token IDs back into a human-readable text string. In lossless tokenizers like SentencePiece, the original input can be perfectly reconstructed without information loss.
Token Embedding Layer
Each Token ID in the vocabulary is associated with a learned, dense vector representation called a Token Embedding. This embedding matrix is the first layer of the neural network and is trained jointly with the rest of the model. The dimensionality of these vectors is the model's hidden size. The embedding layer captures the semantic and syntactic properties of each token, positioning similar tokens close together in the high-dimensional vector space.
Vocabulary vs. Related Concepts
Distinguishing the static vocabulary from the dynamic processes and structures that use it in a tokenization pipeline.
| Feature | Vocabulary | Tokenization | Token Embedding |
|---|---|---|---|
Definition | A fixed set of unique tokens mapped to integer IDs | The process of segmenting text into tokens | A learned dense vector representing a token's meaning |
Nature | Static lookup table | Dynamic algorithm | Learned parameter matrix |
Output | Token ID (integer) | Sequence of token IDs | High-dimensional vector |
Created during | Training (BPE merge rules) | Inference (applying rules) | Model training (backpropagation) |
Stored in | tokenizer.json or vocab.txt | Tokenizer code/rules | Model weights (embedding layer) |
Primary function | Defines the model's known symbols | Converts raw text to model inputs | Captures semantic and syntactic properties |
Handles OOV words | |||
Size trade-off | Efficiency vs. coverage | Speed vs. segmentation quality | Expressiveness vs. memory |
Frequently Asked Questions
Clear, technical answers to the most common questions about how language models build and use their internal dictionaries.
A vocabulary is the fixed set of unique tokens that a language model recognizes, constructed during training and mapping each token to a unique integer identifier. It serves as the model's complete dictionary—every input must be segmented into tokens present in this set, and every output token the model generates is drawn from it. The vocabulary is a critical architectural component, not an afterthought: its size directly determines the embedding matrix dimensions, and its composition governs how efficiently the model can encode text. A well-constructed vocabulary balances coverage (representing rare words and characters) against granularity (avoiding excessively long token sequences for common words).
Enabling Efficiency, Speed & Accuracy
Intelligent Analysis, Decision & Execution
We build AI systems for teams that need search across company data, workflow automation across tools, or AI features inside products and internal software.
Talk to Us
Search across company data
Give teams answers from docs, tickets, runbooks, and product data with sources and permissions.
Useful when people spend too long searching or get different answers from different systems.

Automate internal workflows
Use AI to route work, draft outputs, trigger actions, and keep approvals and logs in place.
Useful when repetitive work moves across multiple tools and teams.

Add AI to products and internal tools
Build assistants, guided actions, or decision support into the software your team or customers already use.
Useful when AI needs to be part of the product, not a separate tool.
Related Terms
Master the core components that interact with a model's vocabulary, from foundational algorithms to critical pre- and post-processing steps.
Byte-Pair Encoding (BPE)
The dominant subword algorithm that constructs the vocabulary by iteratively merging the most frequent adjacent pairs of bytes or characters. Starting with individual characters, BPE builds a set of subword units that efficiently represent a corpus. This directly determines the final vocabulary size and the list of token IDs the model will recognize, balancing encoding efficiency against the risk of fragmenting rare words into many tokens.
Special Tokens
Reserved vocabulary entries with specific control functions, added to the core vocabulary derived from the training data. These are not natural language but structural signals for the model. Key examples include:
- [CLS]: Marks the start of a sequence for classification.
- [SEP]: Separates segments, like question and context.
- [MASK]: Hides a token for masked language modeling.
- [PAD]: Ensures uniform sequence length in a batch.
Encoding & Decoding
The two-way mapping process governed by the vocabulary.
- Encoding: Converts a raw text string into a sequence of token IDs by applying normalization, pre-tokenization, and the subword merge rules defined in the vocabulary.
- Decoding: The inverse process of converting a sequence of token IDs back into a human-readable string. A lossless tokenization model like SentencePiece guarantees perfect reconstruction of the original text.
Out-of-Vocabulary (OOV) Problem
A condition where a word or character sequence is absent from a model's fixed vocabulary. A core purpose of subword tokenization is to eliminate this issue. By segmenting unknown words into known subword units (e.g., 'un' + 'known'), the model can still process and represent any input text. A byte-level BPE strategy provides a definitive solution by operating on raw bytes, guaranteeing a base vocabulary of 256 tokens and zero unknown tokens.
Padding & Attention Mask
Critical post-processing steps for efficient batch processing. Since sequences have different lengths, a [PAD] token (with a specific token ID) is appended to shorter sequences to create a uniform tensor. The attention mask is a binary tensor generated simultaneously, instructing the model's self-attention mechanism to ignore these padding tokens (value 0) and only process genuine content tokens (value 1), preventing computation on meaningless data.
Vocabulary Size Trade-off
A critical hyperparameter defining the total number of unique tokens. It represents a fundamental trade-off:
- Larger Vocabulary: Encodes text with fewer tokens (higher compression ratio), but increases the model's embedding matrix size and parameter count.
- Smaller Vocabulary: Reduces model parameters but forces longer token sequences to represent the same text, potentially losing nuanced meaning as words are heavily fragmented. Typical sizes range from 32k to 250k tokens.

About the author
Prasad Kumkar
CEO & MD, Inference Systems
Prasad Kumkar is the CEO & MD of Inference Systems and writes about AI systems architecture, LLM infrastructure, model serving, evaluation, and production deployment. Over 5+ years, he has worked across computer vision models, L5 autonomous vehicle systems, and LLM research, with a focus on taking complex AI ideas into real-world engineering systems.
His work and writing cover AI systems, large language models, AI agents, multimodal systems, autonomous systems, inference optimization, RAG, evaluation, and production AI engineering.
Partnered with leading AI, data, and software stack.
How We Work
Custom AI workflows for your Business
One-fit-all AI don't work for modern businesses. At Inferensys, we aim to understand your business & custom requirements; which we use to define most efficient agentic workflows, the data, and the tools for your business.
01
Review the use case
We understand the task, the users, and where AI can actually help.
Read more02
Pick the right approach
We define what needs search, automation, or product integration.
Read more03
Build the first useful version
We implement the part that proves the value first.
Read more04
Improve from there
We add the checks and visibility needed to keep it useful.
Read moreThe first call is a practical review of your use case and the right next step.
Talk to Us