The Vocabulary Problem › The Out-of-Vocabulary Problem
Language AI HandbookAll chapters The Vocabulary Problem › The Out-of-Vocabulary ProblemOne section · Sections in this chapter2 / 12 ↓
Reading tools Definitions & inline links
Choose your expertise level to adjust how many terms are explained. Beginners see more tooltips, experts see fewer to maintain reading flow. Hover over underlined terms for instant definitions.
Article links
Make inline references clickable
The out-of-vocabulary (OOV) problem is the most immediate and visible failure mode of word-level models. Any fixed vocabulary, no matter how large, will encounter words it has never seen at inference time. This isn't a pathological edge case: it happens in virtually every production deployment, often dozens of times per sentence in technical or multilingual text.
The fundamental reason is simple: language is infinite, but vocabulary is finite. Natural language allows speakers to create new words freely. A vocabulary compiled from any corpus, however large, is a snapshot of language at a particular moment and in a particular domain. The moment you deploy that vocabulary on new text, from a new time period, a new domain, or a new set of users, the gap between what your vocabulary covers and what users write immediately becomes apparent.
Before we examine the mechanics of the OOV problem, it helps to understand exactly what "vocabulary" means in a word-level NLP system. When training, you collect all words that appear above some frequency threshold in your corpus. Each word gets a unique integer index. The embedding matrix has one row per word; the output projection layer has one column per word. Every component of the model that touches word identity is sized to exactly this vocabulary. There is no room for new words without resizing these tensors and retraining. The vocabulary is a list baked into the architecture itself.
When Models Meet Unknown Words
Consider a sentiment analysis model trained on movie reviews. It learned representations for words like "excellent," "boring," and "cinematography." The embedding for "excellent" is close to "wonderful" and "fantastic." The model learned that these words reliably predict positive sentiment. Now imagine deploying this model and encountering the review: "This movie was amazeballs! The CGI was unreal."
The word "amazeballs" is almost certainly not in the training vocabulary. It entered common use in the early 2010s as internet slang expressing enthusiastic approval. What should the model do? The word carries strong positive sentiment, but the model has no entry for it. Three classic approaches exist, and none of them is satisfactory:
-
Replace with a special
[UNK]token: The model treats all unknown words identically, losing important information. "Amazeballs" and "terrible" both become[UNK], erasing the distinction between positive and negative sentiment. The model has neededly been blinded to a key signal in the text. -
Skip the word entirely: The sentence becomes "This movie was ! The CGI was unreal." Syntactic structure is partially preserved, but the most sentiment-laden word in the sentence is gone. Any analysis of this sentence will be based on incomplete information.
-
Attempt approximate matching: Maybe "amazeballs" is similar to "amazing"? This requires additional infrastructure such as edit-distance lookups or phonetic matching, it's computationally expensive, and it often fails for truly novel words where there is no close neighbor in the vocabulary.
The [UNK] approach is overwhelmingly the most common choice in practice because it requires no extra computation and is simple to implement. But it creates a black hole in your model's understanding. Any word outside the vocabulary collapses to a single undifferentiated representation. The model cannot distinguish between "amazeballs" (very positive), "meh" (neutral), and "unwatchable" (very negative) once they all become [UNK]. The key insight is that [UNK] doesn't just remove information about one word: it actively introduces noise by conflating semantically opposite concepts under a single token.
A word is out-of-vocabulary when it doesn't appear in the fixed vocabulary constructed during training. OOV words must be handled specially, typically by mapping them to a generic [UNK] token, which discards their unique meaning entirely. The OOV rate measures what fraction of tokens in a test set are unknown to the model's vocabulary. High OOV rates systematically degrade performance on all downstream tasks.
Measuring the OOV Rate
Let's quantify how serious this problem is in practice. We'll build a vocabulary from one text corpus and measure how many words from a different corpus fall outside it. This domain-shift scenario is extremely common: a model trained on news articles is deployed to process social media posts, or a model trained on formal academic text must handle informal customer support conversations.
import re
def tokenize(text):
"""Simple whitespace and punctuation tokenization."""
return re.findall(r"\b[a-z]+\b", text.lower())
# Training corpus: classic literature
training_texts = [
"The quick brown fox jumps over the lazy dog.",
"To be or not to be, that is the question.",
"It was the best of times, it was the worst of times.",
"All happy families are alike; each unhappy family is unhappy in its own way.",
"Call me Ishmael. Some years ago, never mind how long precisely.",
"In the beginning God created the heaven and the earth.",
"It is a truth universally acknowledged that a single man in possession of a good fortune.",
"The man in black fled across the desert, and the gunslinger followed.",
]
# Build vocabulary from training corpus
training_tokens = []
for text in training_texts:
training_tokens.extend(tokenize(text))
vocabulary = set(training_tokens)
# Test corpus: modern tech reviews
test_texts = [
"The smartphone's OLED display is absolutely gorgeous with HDR support.",
"I downloaded the app and it synced with my smartwatch seamlessly.",
"The AI-powered chatbot provides surprisingly helpful customer service.",
"This laptop's GPU handles 4K gaming without breaking a sweat.",
"The Bluetooth connectivity works flawlessly with all my devices.",
]
# Count OOV words
test_tokens = []
for text in test_texts:
test_tokens.extend(tokenize(text))
oov_words = [word for word in test_tokens if word not in vocabulary]
oov_unique = set(oov_words)Vocabulary Analysis ============================================================ Training vocabulary size: 65 unique words Test corpus tokens: 50 words OOV tokens: 41 (82.0%) Unique OOV words: 37 Sample OOV words: ['absolutely', 'ai', 'app', 'bluetooth', 'breaking', 'chatbot', 'connectivity', 'customer', 'devices', 'display', 'downloaded', 'flawlessly', 'gaming', 'gorgeous', 'gpu']
Even in this small demonstration, a substantial fraction of test tokens are unknown to the vocabulary built from classic literature. Words like "smartphone," "oled," "bluetooth," and "gpu" are completely absent because they represent modern technology that didn't exist when those texts were written. This illustrates a critical pattern: domain shift between training and deployment data creates OOV problems even when vocabulary sizes seem entirely adequate for the training domain. The same failure occurs in every deployment scenario where the text distribution shifts: a medical model encountering new drug names, a legal model seeing recently enacted legislation, a social media model encountering today's trending slang.
The OOV problem reveals that word-level models treat language as a closed system, a fixed catalog of known atoms. Real language is an open system where new expressions are continuously coined. No training corpus, however extensive, captures all the text that will ever be written. In real applications, the OOV problem never goes away because language continuously evolves and any fixed vocabulary grows stale from the moment training ends.
The Long Tail of Language
The OOV problem stems from a fundamental statistical property of natural language: word frequencies follow Zipf's law. A small number of words appear extremely frequently, while an enormous number of words appear rarely or only once. This isn't a quirk of any particular language or corpus; it has been observed across hundreds of languages and text types, from Ancient Greek to modern Twitter.
Zipf's law states that the frequency of a word is inversely proportional to its rank in the frequency table. The most common word appears roughly twice as often as the second most common, three times as often as the third, and so on. Formally, if words are ranked by decreasing frequency, the frequency of the word at rank satisfies:
where:
- : the frequency of the word ranked -th by frequency
- : the rank of the word (1 = most frequent)
- : a corpus-specific constant proportional to total corpus size
- : an exponent typically close to 1.0 for natural language
For English text with , the most frequent word (typically "the") accounts for roughly 7% of all tokens, the second most frequent word for about 3.5%, and so on.
Why does Zipf's law matter for the vocabulary problem? Because it means the frequency distribution is extremely skewed. The top 100 words typically cover about 50% of all tokens in English text. The top 1,000 words cover about 75%. But the vocabulary of a typical adult speaker contains 30,000 to 50,000 words, most of which appear infrequently. There are hundreds of thousands of words that appear only once or twice per million tokens, and the long tail stretches essentially to infinity when you account for new coinages, proper nouns, technical terms, and spelling variants.

The log-log plot makes the Zipfian structure immediately visible. The top few words appear millions of times; the majority of vocabulary items appear only a handful of times each. The straight line on the log-log plot is the hallmark of a power law: frequency drops off smoothly and steeply as rank increases. The "long tail" region to the right of the chart contains most of the unique word types, but each individual word there is so rare that any reasonably sized corpus will miss many of them entirely.
The key insight is that the long tail is not just large, it is also unbounded. Every day, new words enter English from technology, science, culture, and the internet. Every new product launch creates new proper nouns. Every emerging field generates new technical terms. The tail keeps growing. A vocabulary fixed at training time is racing against an exponentially expanding frontier of new words, and it cannot win. This is not a temporary problem that will go away as we collect more training data: it is a structural consequence of how human language works.