N-gram Language Models › The Markov Assumption
Language AI HandbookAll chapters N-gram Language Models › The Markov AssumptionOne section · Sections in this chapter3 / 15 ↓
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 chain rule gives us an exact decomposition, but it demands something impractical: reliable estimates of probabilities conditioned on arbitrarily long histories. The key insight of n-gram models is to make a simplifying assumption that trades some accuracy for tractability.
The Markov assumption states that the probability of a word depends only on a fixed-length history of preceding words, not the entire sequence. An n-gram model assumes the probability of word depends only on the previous words.
The assumption is named after the Russian mathematician Andrey Markov, who studied stochastic processes with this "memoryless" property in the early 20th century. In a Markov chain, the probability of the next state depends only on the current state, not on the full history of how you arrived there. In the context of language, it means we assume the future depends only on the recent past, not the distant past.
For a unigram model (), each word is treated as completely independent of all others:
The unigram model ignores all context. It assigns the same probability to "cat" whether the preceding words were "the fluffy" or "the entire concept of." This is obviously a poor approximation, but unigrams are useful as a baseline and as a component in more sophisticated models.
For a bigram model (), each word depends only on the single word immediately before it:
where:
- : the true conditional probability given the full history (left side)
- : the bigram approximation using only the immediately preceding word (right side)
- : indicates this is an approximation, not an equality
For a trigram model (), the memory extends to two previous words:
where:
- : the word two positions before the current word
- : the word immediately before the current word
- The context forms a two-word history window
In general, for an n-gram model, the Markov approximation is:
where the context window spans exactly preceding words. We discard information from the distant past to make estimation tractable from finite data.
Why does this help? Consider the difference in what we need to estimate for the sentence "the cat sat on the mat":
- Full history: We need , requiring counts of the specific five-word context.
- Trigram: We need , requiring only counts of the two-word context.
- Bigram: We need , requiring only counts of the single word "the."
Shorter contexts appear far more frequently in training data, giving us more reliable probability estimates. The Markov assumption is an approximation, but it works surprisingly well in practice because language has enough local structure that nearby words carry most of the predictive information. The word that most immediately constrains "mat" is likely "the" (or "on the"), not the first word five positions back.
# Compare full history vs Markov approximations
sentence = "the cat sat on the mat"
words = sentence.split()
approximations = [
(
"Full history (n=6)",
"P(mat | the cat sat on the)",
"exact but impractical",
),
("Trigram (n=3)", "P(mat | on the)", "considers 2 previous words"),
("Bigram (n=2)", "P(mat | the)", "considers 1 previous word"),
("Unigram (n=1)", "P(mat)", "ignores all context"),
]Markov Approximations for the final word 'mat': ----------------------------------------------------------------- Full history (n=6): P(mat | the cat sat on the) -> exact but impractical Trigram (n=3): P(mat | on the) -> considers 2 previous words Bigram (n=2): P(mat | the) -> considers 1 previous word Unigram (n=1): P(mat) -> ignores all context