N-Gram Language Models, Laplace/Kneser-Ney Smoothing & Perplexity
Markov chain N-gram MLE probabilities, Add-1 (Laplace) & Add-k smoothing formulas, Interpolation vs Backoff, Kneser-Ney continuation probability, and Cross-Entropy / Perplexity numericals.
1. Chain Rule & -Gram Markov Assumption
Exact joint probability of a token sequence factors via the chain rule . An -gram model applies a -th order Markov assumption, looking back only tokens:
- Unigram ():
- Bigram ():
- Trigram ():
2. Handling Zero Counts: Smoothing & Kneser-Ney
Any unseen test -gram gives !
- Add- Smoothing: ( is Laplace). Note .
- Linear Interpolation: with .
- Absolute Discounting & Kneser-Ney: Subtracts a fixed discount (e.g., ) from non-zero counts and backs off to continuation probability (how versatile is across distinct preceding contexts β solves the "San Francisco" trap where "Francisco" has high raw frequency but only ever follows "San"!).
3. Worked Perplexity Numerical
Suppose a language model assigns probabilities over tokens: Intuitively, Perplexity equals the weighted average branching factor of the language model ( for a uniform model ).
Practice Questions on This Chapter (2)
A corpus has vocabulary size . The unigram data occurs times, and the bigram data science occurs times. Under Laplace (Add-1) Smoothing, what is ?
A language model achieves a per-token Cross-Entropy of (base- log) on a held-out evaluation corpus. What is the Perplexity () of the language model?