N-gram Language Model
Your phone suggests three words before you have typed a letter of them, and it is right surprisingly often. The oldest working answer to how that is possible is also the plainest: look at what people wrote after these same words before, and count.
How the probability is built
The probability of a sentence is the product of each word's probability given everything before it, which is unusable as written — no corpus contains the full history. An n-gram language model makes the Markov assumption that only the previous n−1 words matter, then estimates each factor by counting: P(down | the heating) is how many times “the heating down” occurred divided by how many times “the heating” occurred. A trigram model over a few billion words is a few gigabytes of counts that answers in microseconds.
The zeros problem
Most sequences a user produces never appeared in training, and a count of zero makes a whole sentence impossible rather than merely unlikely. Every usable model therefore redistributes probability mass:
- Laplace smoothing — add one to every count; crude, and the standard first illustration.
- Good-Turing — reassign mass using how many n-grams were seen exactly once.
- Backoff — no trigram evidence, so fall back to the bigram, then the unigram.
- Interpolation — blend all orders with learned weights instead of switching.
- Kneser-Ney — weight a word by how many distinct contexts it continues; the strongest of the family.
Why it still matters
KenLM and SRILM models still sit inside speech recognition and translation decoders, and perplexity — the evaluation measure neural models inherited — was defined here. The limits are just as instructive: counts of “cat” teach the model nothing about “dog”, and nothing beyond the window exists at all.
An n-gram language model assigns a probability to the next word from only the previous n−1 words, estimated by counting sequences in a training corpus under the Markov assumption. Smoothing and backoff give probability to sequences never seen, and perplexity measures how well the result predicts held-out text. It remains the baseline language model — fast, inspectable, still embedded in speech and translation decoders — and it cannot generalise between words of similar meaning.
Think of a clerk who has read an enormous pile of letters and remembers, for every pair of words, which word usually came next. Ask what follows “happy new” and the answer comes back instantly, because it has been counted thousands of times.
That is an n-gram language model: software that guesses the next word purely from how often short word sequences appeared in the text it was trained on. It is what made phone keyboards and early voice dictation usable. Its weakness is its memory — it only looks back a word or two, so it keeps a sentence locally plausible while losing track of what the sentence was about.