Shannon's N-gram Model (1948) › The Data Sparsity Problem and Its Solutions

Michael BrenndoerferMarch 25, 20254 min read
History of Language AIAll chapters
Part 1 of 9Signals & Symbols
Chapter 1Shannon's N-gram Model (1948) › The Data Sparsity Problem and Its Solutions
Reading section 4 of 6 · The Data Sparsity Problem and Its Solutions · 4 minSection 4 of 6 · 4 min

Book contents

Section 4 of 6 · 4 min read

Shannon's N-gram Model (1948) › The Data Sparsity Problem and Its SolutionsOne section · Sections in this chapter4 / 6 ↓
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

As researchers began deploying n-gram models in practical systems, they encountered a fundamental challenge that would shape decades of subsequent research. The problem arises from a simple mathematical reality: the number of possible n-grams grows exponentially with n. A vocabulary of 10,000 words yields 10,000 possible unigrams, 100 million possible bigrams, and a trillion possible trigrams. Even with large training corpora, the vast majority of these theoretically possible combinations never appear in the data. Yet when a system encounters an unseen n-gram during actual use, it has no way to assign it a reasonable probability.

This data sparsity problem becomes more severe as n increases. Longer n-grams provide richer context and better predictions when they have been observed in training, but they also become increasingly rare. You might see "peanut butter" thousands of times in a corpus, but "peanut butter and jelly sandwich" only dozens of times, and "my grandmother's homemade peanut butter and jelly sandwich" perhaps never. The question became: how do you handle prediction when your specific context hasn't been seen before?

The solution that became most influential was introduced by Slava Katz in 1987, a technique called Katz back-off. The core insight is elegantly practical: if you haven't observed a particular n-gram, don't give up entirely. Instead, back off to a shorter context. If you haven't seen the trigram "homemade peanut butter," look at the bigram "peanut butter." If that's also unseen, fall back to the unigram "butter." This hierarchical fallback strategy ensures the model can always produce a probability estimate, even for novel combinations, while still preferring longer contexts when they're available.

Katz back-off represented just one approach to smoothing, the general problem of adjusting probability estimates to account for unseen events. Other techniques emerged, each with different mathematical foundations and performance characteristics. Good-Turing smoothing uses information about n-grams seen once to estimate probabilities for n-grams seen zero times. Kneser-Ney smoothing goes further, recognizing that the probability of a word should depend not just on how often it appears, but on how many different contexts it appears in. A word that shows up in many diverse contexts is more likely to appear in a new, unseen context than a word that appears frequently but only in very specific phrases.

Despite these sophisticated solutions to data sparsity, n-gram models retained fundamental limitations that no amount of smoothing could overcome. Their restricted context window, enforced by the Markov assumption, meant they could not capture the kind of long-range dependencies that pervade natural language. Pronouns separated from their antecedents by multiple sentences, thematic coherence across paragraphs, and subtle patterns of style and register all lay beyond the reach of these models. N-gram models also operated at the surface level of word sequences without any representation of semantic similarity. The model saw "car" and "automobile" as entirely distinct, unrelated tokens, missing the obvious semantic connection that any human would recognize immediately.

The computational and storage costs also became prohibitive as systems scaled. A competitive language model might need to store billions of n-grams with their associated counts and probabilities. Query time could be fast, but building and maintaining these massive probability tables required substantial infrastructure. Despite these limitations, n-gram models found enduring applications where their strengths aligned well with task requirements: they remain interpretable and easy to debug, unlike the black-box nature of neural models; they perform well on tasks where local context suffices; they require no specialized hardware or extensive training time; and they provide a strong baseline for evaluating more complex approaches.

The Curse of Dimensionality

The exponential growth of possible n-grams is an instance of the curse of dimensionality, a fundamental challenge in machine learning and statistics. As the number of dimensions increases (in this case, the length of the n-gram), the amount of data needed to maintain adequate coverage grows exponentially. This forces a difficult tradeoff: longer contexts provide more information but require exponentially more data and storage. This tension between context length and data requirements motivated much of the subsequent search for better representations of language.