Vocabulary
Before a model can see a word, something has to decide that the word exists at all. The vocabulary is that decision written down: the finite list of units a system is prepared to recognise, and a hard boundary around everything it can represent.
A list with consequences
It is the set of distinct types produced by tokenisation, almost always pruned before use:
- a frequency cutoff drops words seen fewer than a handful of times, and a size cap keeps the most common thirty or fifty thousand;
- special entries are added — an unknown-word symbol, padding, sentence boundaries, a mask token;
- normalisation choices are baked in, since lowercasing or stripping accents merges types before they are ever counted.
Its size sets real costs: the width of a document-term matrix, the rows of an embedding table, and the output softmax, which dominates the parameter count of a word-level model.
The open-vocabulary problem
Language refuses to stay inside the list. New names, hashtags, typos and morphological variants keep arriving, so any fixed word-level vocabulary meets unseen strings in production. Those collapse into an out-of-vocabulary token and everything specific about them is lost — which bites hardest on exactly the rare words that carry the message, like a product name in a support ticket. Subword vocabularies such as BPE, WordPiece and the unigram model answer this by listing pieces instead of whole words, so any string can be spelled out from a few tens of thousands of entries.
Why it must be frozen
The vocabulary is part of the model, not of the data: index 7 means one specific token and the embedding at row 7 was trained for it. Rebuilding the list on fresh text, or pairing one tokenizer's vocabulary with another checkpoint's weights, garbles every lookup without raising an error. That is why Hugging Face checkpoints ship their vocabulary files alongside the weights.
A vocabulary is the finite set of distinct units — words, subwords or characters — that a text system recognises, built from tokenised text and usually pruned by a frequency cutoff or a size cap. It fixes the width of count matrices, the rows of an embedding table and the output layer, and anything outside it arrives as an out-of-vocabulary token with its meaning lost. The list belongs to the model and must stay frozen alongside its weights.
A shop's till only scans the products in its catalogue. Bring something that was never listed and the checkout simply cannot ring it up. The item plainly exists — this till has just never been told about it.
Software reading text keeps a catalogue too, and vocabulary is its name: the list of words the system knows. Anything missing from that list — a new brand, an unusual surname, a typo — arrives as nothing more than "some unknown word", and everything specific about it is lost. That is why modern systems store a list of word pieces rather than whole words. Pieces can be slotted together to spell out almost anything, even a word nobody has written before.