Inferensys

Glossary

Vocabulary

The fixed set of unique tokens that a language model recognizes, typically constructed during training and mapping each token to a unique integer identifier.
ML engineer managing model training cluster on laptop, GPU utilization visible, technical deep learning setup.
DEFINITION

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.

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.

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.

Vocabulary

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.

01

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.

02

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).
03

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).
04

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.

05

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.
06

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.

TOKENIZATION COMPONENTS

Vocabulary vs. Related Concepts

Distinguishing the static vocabulary from the dynamic processes and structures that use it in a tokenization pipeline.

FeatureVocabularyTokenizationToken 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

VOCABULARY FUNDAMENTALS

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).

Prasad Kumkar

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.