n-Gram Language Models and Smoothing: From Laplace to Kneser–Ney
Every smoother is a guess about the words we have not seen — read three ways as empirical Bayes: a Dirichlet prior fit to the data, Robbins' formula on word counts, and Kneser–Ney as a hierarchical Pitman–Yor posterior
Overview & Motivation
A language model assigns a probability to the next word given the words before it. The simplest kind looks back a fixed distance: a trigram model predicts each word from the two before it, and estimates those predictions by counting. Train one on the finance corpus of the previous topics — sentences, predicted tokens — and test it on fresh documents from the same generator. Of the held-out trigrams, never occur in training; so do of the bigrams and of the words. The counting model gives every one of them probability zero, and a single zero makes the probability of the whole held-out text zero.
So a language model must reserve probability for events it has never seen, and take it from events it has. How much, from which events, and given to which unseen ones? Each classical smoother is an answer, and this topic reads them as one idea seen three ways — empirical Bayes, estimating a prior from the data it will be applied to:
- A Dirichlet prior fit to the data. Adding pseudo-counts is a Bayesian posterior mean. Its one free strength can be fit by maximizing the probability of the training data — Type-II maximum likelihood.
- Robbins’ formula on word counts. Good and Turing’s estimate of a word’s true frequency from how many other words share its count turns out to be the empirical-Bayes formula Robbins derived for insurance claims. We prove the identity behind it exactly.
- Kneser–Ney as a hierarchical Pitman–Yor posterior. The best classical smoother uses a peculiar count — how many different words a word follows. We derive it from a constraint on marginals, and then show it is exactly what a hierarchical Pitman–Yor model predicts when every word type sits at a single table.
Along the way we prove that Katz backoff normalizes, that the familiar discount is an upper bound on the leave-one-out optimum rather than the optimum itself, and that interpolated Kneser–Ney matches a reference implementation to twelve decimals. A laboratory after the Pitman–Yor section puts every smoother side by side on five contexts. Its second panel plots the one curve that connects them all: how much each method subtracts from a count of .
Counting and the zero-count problem
Pad each sentence with copies of a start symbol <s> in front and one end symbol </s> behind. Every word and the final </s> is a predicted token; <s> only ever serves as context. The vocabulary is the set of training word types together with </s> and an unknown-word symbol <unk>, which stands in for every held-out word never seen in training; here .
Definition 1 (n-gram model and its maximum-likelihood estimate).
An order- model gives each predicted token a probability that depends only on its context , the tokens before it. Write for the number of times the -gram occurs in training, for the number of times occurs as a context, and for with its oldest word dropped. The maximum-likelihood estimate (MLE) is the relative frequency .
Lower-order counts are always taken as marginals of the top-order ones, so the bigram count is the number of trigrams ending in . That bookkeeping matters twice below.
Proposition 1 (The MLE is the relative frequency).
For a context and any distribution on the vocabulary,
with equality only at .
Proof.
Substitute : the difference becomes , which is times the Kullback–Leibler divergence. Gibbs’ inequality (formalML, KL divergence) makes it nonnegative, and zero only when the two distributions agree.
∎We judge a model by its held-out log-loss, the average of over the predicted tokens of text it did not train on, in nats per token. (Its exponential is perplexity, the subject of the next language-modeling topic.)
Proposition 2 (The zero-frequency catastrophe).
The maximum-likelihood model’s held-out log-loss is infinite if and only if some held-out -gram never occurs in training.
Proof.
The log-loss is an average of the terms . It is finite exactly when every term is, that is, when for every held-out token, which says that every held-out -gram has a positive training count.
∎With a third of the held-out trigrams unseen, the catastrophe is not a corner case. On the trigrams that were seen, the MLE’s log-loss is finite; the problem is entirely the unseen ones.
Smoothing as shrinkage
Picture the MLE for a context as a point in the probability simplex — the set of all distributions on . A context seen a handful of times puts its point on a low-dimensional face of the simplex: every word not yet seen after it has coordinate zero. Smoothing moves the point into the interior. The cleanest way is to slide it along a straight line toward a sensible default, and the sensible default for a trigram context is the bigram model one order down.
Definition 2 (Hierarchical Dirichlet smoothing).
With a strength for each order , set
where is the number of predicted tokens. With the uniform distribution in place of this is additive (Lidstone) smoothing with pseudo-counts per word, and Laplace smoothing at one pseudo-count.
This is a posterior mean. Put a prior on the next-word distribution of the context ; after observing the counts , the posterior mean is exactly — the theorem behind Dirichlet smoothing in formalRAG’s query-likelihood language models, applied here once per context instead of once per document (MacKay and Peto 1995).
Proposition 3 (Shrinkage is interpolation).
Definition 2 can be written as
and for a context never seen in training.
Proof.
Split the fraction: , and . If , then and only the lower order remains.
∎So the estimate moves along the segment from the MLE to the lower-order model, and how far it moves depends on how much evidence the context has: a context seen ten thousand times barely moves, one seen once moves a long way. What remains is the strength . Empirical Bayes picks it by asking which prior makes the training data most probable.
Theorem 1 (The Dirichlet–multinomial evidence).
Under independent priors for the contexts, where each context’s center is a distribution on fixed in advance — in Definition 2, — the probability of the training word sequences is
Proof.
For one context with next-word distribution , the probability of its word sequence is . Integrate against the Dirichlet density , where :
where is the vector of counts after . Since , the logarithm is the bracketed context term plus one term per word; a word with contributes . Contexts have independent priors, so their log-probabilities add.
∎Maximizing this evidence over is Type-II maximum likelihood — the parametric empirical Bayes of formalStatistics’ hierarchical Bayes and partial pooling (§28.7), where it fits the spread of eight schools’ effects. Fit order by order, each order’s centers taken from the orders already fitted below it, it gives for unigrams, bigrams, and trigrams, and a held-out log-loss of nats per token — far better than Laplace’s . Laplace here is flat add-one on the trigram counts with no lower orders, so that gap measures the hierarchy as well as the fitted strengths. The companion code checks Theorem 1 against SciPy’s Dirichlet–multinomial distribution.
Remark.
The evidence does not choose the best for held-out text. Tuning on the held-out data itself — an oracle we cannot use in practice — gives and a log-loss of . At the unigram and bigram orders the oracle’s strength is about sixty-two times the evidence’s, and there the difference has a cause: the evidence is computed on training text, which contains no unseen words at all, so it never pays for the mass that <unk> will need, and it under-smooths. At the trigram order the comparison reverses: the oracle’s is below the evidence’s , so held-out text wants less trigram smoothing than the evidence chooses. We report that reversal as measured; we do not have a mechanism for it. Type-II maximum likelihood answers the question it is asked — which prior best explains the training data — and that is not the question held-out text asks.
Good–Turing: Robbins’ formula on word counts
The Dirichlet approach assumes a shape for the prior. Turing, working on wartime codebooks, had a different idea, published by his assistant Good (1953): estimate a word’s probability from how many other words share its count. Let be the number of distinct types seen exactly times in a sample of tokens — the spectrum of the Zipf–Heaps topic — and the total true probability of those types. Good–Turing replaces a count of with
and gives the types never seen the total probability . On our trigrams the spectrum begins with equal to , , , , ; so singleton trigrams are each worth of an occurrence, and the unseen trigrams share a large part of the mass. Why should the next count up tell us about this one? Because of an exact identity.
Theorem 2 (Good–Turing, exact).
For independent draws from any distribution on a countable set of types, and every ,
Proof.
A type is seen exactly times with probability , so
Now , so the sum is , and the last sum is the expected number of types seen exactly times in draws.
∎Both sides are linear in the distribution of the sample, so the identity also holds for mixtures of independent draws — exchangeable sequences such as the Pitman–Yor process of the Zipf–Heaps topic. Setting says the mass of the unseen types is, in expectation, . The usable estimate is off by very little:
Corollary 1 (The missing-mass estimate is nearly unbiased).
Proof.
Expand: and ; their difference is , which is nonnegative. The function on peaks at with value , so the difference is at most .
∎The missing mass also concentrates around its estimate (McAllester and Ortiz 2003, cited). The companion code checks Theorem 2 exactly on random distributions and Corollary 1 by simulation.
Remark.
Good–Turing is Robbins’ formula. Let each type’s count be Poisson, , and read the spread of the rates across the vocabulary as a prior . Robbins’ formula (formalStatistics, Empirical Bayes, §33.3, Theorem 2) gives the posterior mean rate of a type seen times as , where is the probability that a type is seen times — estimated by up to a constant. That is Turing’s : word types in place of insurance policy holders, the spectrum in place of the claim counts. Run on Topic 33’s insurance table, the companion code’s Good–Turing function reproduces its Robbins row, , , , , , , , to the printed digits. The frame is Robbins’ compound decision problem (§33.2): estimate every type’s frequency at once, judged by total error.
The kinship carries a warning with it. Robbins’ estimate is erratic where the next count is small (Topic 33, Remark 5), and so is Turing’s: on our trigrams the discount runs , , , for , then jumps to , falls to — a negative discount — and climbs to . Simple Good–Turing (Gale and Sampson 1995) repairs the tail: it averages over the gaps between observed counts to get , fits a straight line to against — plausible because the spectrum is a power law, as the Zipf–Heaps topic showed — and switches from Turing’s to the fitted one at the first where the two agree within standard errors (here ). The resulting discount — Turing’s for , the fit’s from then on — is close to constant: , , , , , , , for . Church and Gale (1991) saw the same thing on English bigrams. Hold on to it; it is the reason for absolute discounting. The companion code’s Simple Good–Turing matches NLTK’s to fifteen decimals; that check runs on the bigram spectrum, through the same function that gives the trigram figures above.
Backoff
Good–Turing says how much mass to take from the seen -grams. Backoff says where to send it: to the next order down.
Definition 3 (Katz backoff).
With Turing’s discount ratios for small counts (Katz 1987 renormalizes them so that counts above a cutoff are left alone, for ),
with Laplace smoothing at the unigram level and for a context never seen.
Proposition 4 (The backoff weight that normalizes).
If
and the denominator is positive, then sums to one.
Proof.
Induct on the order; the Laplace unigram sums to one. The seen words of carry , the numerator’s complement. The unseen words carry by the induction hypothesis, which is the numerator. The two parts sum to one.
∎On our corpus every lies strictly between and — for trigrams , , , , — and the model normalizes for every context tested. But the cutoff has a cost on text like ours, which is generated from templates. Take the context in osaka: it occurs seven times in training, followed by </s> every time. Seven is above the cutoff, so nothing is discounted and the numerator of is zero: Katz has no mass to reserve for any other continuation. Here the denominator is zero too — the bigram osaka is also always followed by </s>, and gives it probability one — so is , undefined; we keep the MLE, which reserves nothing. Of the seen contexts ( bigram and trigram), reserve nothing. In of them the cutoff does it alone: the numerator is zero, the denominator is not, and . The other , in osaka among them, are trigram contexts whose seen followers already hold all of the lower order’s mass, so the denominator is zero and is undefined. They reserve nothing because we keep the MLE there — of them would free some mass under discounting, but it would have nowhere to go. Three held-out tokens fall into zero-reserve contexts and get probability zero: after across aerospace and of fairhaven, where the cutoff makes , and after in osaka, where is undefined. Katz’s held-out log-loss is infinite: the zero-count problem, back through the cutoff. On the other held-out tokens it scores .
Absolute discounting
Simple Good–Turing found that the discount is roughly the same for every count. Then why not subtract one constant from every count and interpolate with the lower order, as the Dirichlet model does?
Definition 4 (Interpolated absolute discounting).
With a discount and the number of distinct words seen after ,
with for a context never seen, and the uniform distribution below the unigram level.
Proposition 5 (Absolute discounting normalizes).
If sums to one, so does .
Proof.
Because , every seen word has , so the first terms sum to . The second terms sum to . The numerators sum to ; induct down to the uniform base.
∎Every subtracted unit of count reappears as mass for the lower order. The one parameter is , and Ney, Essen, and Kneser (1994) proposed choosing it by leave-one-out: delete each training token in turn, ask how well the model trained on the rest predicts it, and maximize the total. The answer usually quoted is , with the number of -grams seen times. What the leave-one-out argument actually proves is weaker, and more interesting.
Theorem 3 (The leave-one-out discount).
Consider the backing-off form of absolute discounting, in which a seen -gram gets and an unseen one gets the freed mass shared in proportion to a fixed lower-order distribution. Let count the singletons whose context occurs at least twice. Then the leave-one-out log-likelihood is
with independent of . If , then is strictly concave on , has a unique maximizer , and
Proof.
Remove one occurrence of an -gram seen times. If it is still seen, with probability . If and its context occurs at least twice, it becomes unseen in a context that still exists, and its probability is times a factor from the lower-order distribution; only the factor depends on . If and the context occurred once, the context disappears and the probability comes from the lower order alone, free of . Summing logarithms over all occurrences gives .
Each is concave in and is strictly concave, so is strictly concave. Its derivative tends to as and to as (the term), so it has exactly one root . At that root,
which rearranges to . Finally increases in , and .
∎So is an upper bound on the leave-one-out optimum, reached only if the counts above two are ignored and every singleton’s context occurs at least twice, so that . The difference is not small here. For bigrams, against the familiar ; for trigrams against , and over half of the trigram singletons ( of ) sit alone in their context and drop out of entirely. The companion code checks that differs from the exact leave-one-out log-likelihood by a constant, and the bound on random spectra.
Kneser–Ney
Absolute discounting sends the freed mass to the lower-order distribution. Look at what that distribution believes. In the finance corpus, industrial occurs times, and every one of them follows halvorsen: it is the second word of a company name, Halvorsen Industrial. A unigram model built from raw counts ranks industrial as the th most likely word. But the lower order is only consulted when the trigram and bigram are unseen — that is, in a context that is not halvorsen, where industrial almost never appears. The lower order should answer a different question: not how often does occur? but how likely is to appear after a context it was not seen in? Kneser and Ney’s answer counts contexts instead of tokens.
Definition 5 (Continuation counts and interpolated Kneser–Ney).
The continuation count of an -gram is , the number of distinct words that precede it. Interpolated Kneser–Ney is Definition 4 with raw counts at the top order and continuation counts at every lower order:
where at a lower order means the continuation count. With one discount per order, . Modified Kneser–Ney (Chen and Goodman 1999) uses three discounts per order, , , and , for counts of one, two, and more.
industrial has continuation count , and drops from rank to rank . The choice of count is not a trick, though: it is forced by a requirement.
Theorem 4 (The marginal constraint).
Take the top order as in Definition 5, with discounts satisfying for , and an unknown lower-order distribution in place of . The model reproduces the training data’s marginals,
if and only if
With one discount per order, this is : the continuation distribution.
Proof.
Multiply out:
Because lower-order counts are marginals, , so the constraint holds exactly when . When for every , the right side is times the number of with , which is , and .
∎Kneser and Ney (1995) derived the backing-off version of this approximately; in the interpolated form it is exact. The companion code confirms it on the corpus, and confirms the converse too: with modified Kneser–Ney’s three discounts, the marginal-preserving lower order is the discount-weighted count of Theorem 4, not the continuation count, and continuation counts miss the bigram marginals by more than one percent. Modified Kneser–Ney uses continuation counts anyway; that part of it is a heuristic. Our interpolated Kneser–Ney, configured the way NLTK’s KneserNeyInterpolated is (one discount at every order, no uniform base), equals NLTK’s to twelve decimals on sixty held-out predictions.
Kneser–Ney as a hierarchical Pitman–Yor posterior
Continuation counts came out of a constraint. They also come out of a prior. In the Zipf–Heaps topic, word types arrived through a Pitman–Yor Chinese restaurant with discount and strength : each customer (token) joins an occupied table with probability proportional to its occupancy minus , or opens a new table, whose dish (word type) is drawn from a base distribution, with probability proportional to plus times the number of tables. Teh (2006) stacks these restaurants into a hierarchy.
Definition 6 (The hierarchical Pitman–Yor language model).
Put a Pitman–Yor restaurant in every context , with parameters for contexts of order , whose base distribution is the restaurant of ; the restaurant of the empty context draws from the uniform distribution on . Each table in sends one customer to . Given a seating — customers at tables serving in restaurant , totals and — the predictive probability is
The predictive already has Kneser–Ney’s shape: subtract per table, and give the subtracted mass, plus , to the parent. The parent’s counts are tables, not tokens. That is the bridge.
Proposition 6 (Kneser–Ney is the one-table seating).
Let the bottom restaurants hold the raw counts as customers, seat every word at exactly one table in every restaurant, , and set . Then (i) the customers of a restaurant below the top are the continuation counts, , and (ii) the predictive of Definition 6 is interpolated Kneser–Ney with at every order.
Proof.
(i) Restaurant receives one customer for each table serving in each child restaurant , and with one table per type that is one customer for each with . Directly below the top, is the raw count , so . Further down, by induction exactly when , which happens exactly when because counts are marginals; so again . (ii) With and , the predictive is , which is Definition 5 with , the same counts by (i), and the same uniform base.
∎The companion code checks the identity to thirteen decimals on held-out predictions. One table per type is a single, extreme seating, though. The model’s posterior spreads frequent words over several tables. Teh’s Gibbs sampler explores it: remove each training token from its table in turn and reseat it — at an occupied table with weight , or at a new one with weight , which sends a customer to the parent — then resample each order’s given the seating. Started from the Kneser–Ney seating and run for forty sweeps, it gives:
- Strengths near zero. The posterior means are for orders one to three: above the unigram, the data choose pure discounting — Kneser–Ney’s regime.
- A discount that grows with the count. A singleton always sits at one table, so its discount is exactly . A trigram seen times sits at more tables as grows, so its effective discount climbs: , , , , , , , for — far past modified Kneser–Ney’s top discount of . Good–Turing’s measured discount stayed near ; the two are not the same quantity, because in the Pitman–Yor model the subtracted mass flows to the parent, which in a templated context predicts the same word again.
- The best held-out score. Averaging the predictive over sweeps to gives nats per token, ahead of modified Kneser–Ney’s . That is one chain from one random seed; the harness does not test how far the score moves from seed to seed.
This is Markov chain Monte Carlo run for forty sweeps; we report averages and claim no convergence guarantee.
The smoothers side by side
The laboratory puts the classical smoothers on five trigram contexts. In panel A, pick a context and a smoother and read the next-word distribution: the eight likeliest words, filled if they followed the context in training and hollow if not, then the remaining mass on words that did and did not. The context in osaka shows Katz reserving nothing; machinery as, seen once, shows how much each method takes from a singleton; the ⟨unk⟩ has only the unigram level left, where absolute discounting ranks industrial in the top and Kneser–Ney ranks it past . The slider sets one discount at every order for absolute discounting and interpolated Kneser–Ney; their held-out log-loss bottoms out near and rises again at . Panel B plots the discount each method takes from a trigram seen times — every curve on this page in one picture. Hover a count to light up, in panel A, the words seen exactly that often after the context.
Filled bars: words seen after this context (×count). Hollow: never seen here. For reference, the sampled hierarchical Pitman–Yor model reaches 2.822 nats/token.
The slider applies one D at every order (the page's tables use Ney's per-order discounts). Turing's raw estimate is erratic once N_(r+1) is small; the HPYLM curve is an average over 20 Gibbs sweeps.
Held-out log-loss in nats per token, with the per-order discounts :
| smoother | held out, same generator ( tokens) | EDGAR MD&A ( tokens) |
|---|---|---|
| maximum likelihood | ||
| Laplace | ||
| hierarchical Dirichlet, Type-II | ||
| Katz backoff | ( on tokens) | |
| absolute discounting | ||
| interpolated Kneser–Ney | ||
| modified Kneser–Ney | ||
| hierarchical Pitman–Yor (sampled) |
In domain the ordering is the textbook one, strictly. The second column is a warning. On three public MD&A excerpts, of tokens are words the model never saw and of trigrams are new; there, Laplace’s indiscriminate pseudo-counts beat every careful smoother, because the careful ones learned how this generator’s text continues and that knowledge does not transfer.
Finance case study: what each estimate estimates
Where this goes next
- Perplexity. The held-out log-loss of this page, exponentiated, is perplexity; the next language-modeling topic connects it to cross-entropy and to compression, and handles the subword-versus-word normalization the previous topic raised.
- Markov chains with hidden states. An -gram model is a Markov chain on words. Putting the chain on hidden tags and emitting words from them gives the hidden Markov models of sequence labeling, whose emission and transition tables need exactly the smoothing developed here.
- Association instead of prediction. Continuation counts measure how many contexts a word completes; collocation measures ask which word pairs occur together more than chance, with likelihood-ratio tests in place of discounts.
- Overlap metrics. BLEU and ROUGE score generated text by its -gram overlap with references — counting again, with its own zero-count problem at higher orders.
Honest caveats
Implementation
The companion notebook (notebookPath) imports n_gram_models_smoothing.py, which owns every number on this page. Running it as a script executes a harness of assertion-based tests in about fifteen seconds on a laptop CPU, including forty Gibbs sweeps of the hierarchical Pitman–Yor model. The tests cover:
- Propositions 1–3 and Theorem 1, with the evidence checked against SciPy’s Dirichlet–multinomial distribution.
- Theorem 2 exactly on random distributions, Corollary 1 exactly and by simulation, and the Robbins row of Topic 33’s insurance table.
- Simple Good–Turing against NLTK’s implementation, and Katz’s normalization and its zeros.
- Theorem 3’s concavity and bound on the corpus and on random spectra, and its objective against the exact leave-one-out likelihood.
- Continuation counts against brute force, Theorem 4’s marginal constraint (and its failure for modified Kneser–Ney), normalization at every order, and agreement with NLTK’s
KneserNeyInterpolated. - Proposition 6 on held-out predictions, the sampler’s seating invariants, the growth of its discounts, the held-out ordering of all smoothers, and the finance case study.
The laboratory reads its data from a JSON file that one of those tests requires to equal the module’s viz_payload() exactly, so the figure cannot drift from the code.
References & Further Reading
- paper The Population Frequencies of Species and the Estimation of Population Parameters — I. J. Good (1953) Biometrika 40 (3/4): 237–64. The Good–Turing estimate
- paper An Empirical Bayes Approach to Statistics — Herbert Robbins (1956) Proceedings of the Third Berkeley Symposium on Mathematical Statistics and Probability, vol. 1, 157–63. Robbins' formula
- paper Estimating the Number of Unseen Species: How Many Words Did Shakespeare Know? — Bradley Efron and Ronald Thisted (1976) Biometrika 63 (3): 435–47. Good–Turing on words, read as empirical Bayes
- book Computer Age Statistical Inference — Bradley Efron and Trevor Hastie (2016) Cambridge University Press. Table 6.1, the insurance claims behind Robbins' formula
- paper Estimation of Probabilities from Sparse Data for the Language Model Component of a Speech Recognizer — Slava M. Katz (1987) IEEE Transactions on Acoustics, Speech, and Signal Processing 35 (3): 400–401. Katz backoff
- paper A Comparison of the Enhanced Good–Turing and Deleted Estimation Methods for Estimating Probabilities of English Bigrams — Kenneth W. Church and William A. Gale (1991) Computer Speech & Language 5 (1): 19–54. Good–Turing discounts are nearly constant
- paper On Structuring Probabilistic Dependences in Stochastic Language Modelling — Hermann Ney, Ute Essen, and Reinhard Kneser (1994) Computer Speech & Language 8 (1): 1–38. Absolute discounting and its leave-one-out discount
- paper Improved Backing-Off for M-Gram Language Modeling — Reinhard Kneser and Hermann Ney (1995) ICASSP 1995, vol. 1, 181–84. Continuation counts from a marginal constraint
- paper Good–Turing Frequency Estimation without Tears — William A. Gale and Geoffrey Sampson (1995) Journal of Quantitative Linguistics 2 (3): 217–37. Simple Good–Turing
- paper A Hierarchical Dirichlet Language Model — David J. C. MacKay and Linda C. Bauman Peto (1995) Natural Language Engineering 1 (3): 289–308. Dirichlet shrinkage toward the lower order
- paper The Two-Parameter Poisson–Dirichlet Distribution Derived from a Stable Subordinator — Jim Pitman and Marc Yor (1997) Annals of Probability 25 (2): 855–900. The Pitman–Yor process
- paper An Empirical Study of Smoothing Techniques for Language Modeling — Stanley F. Chen and Joshua Goodman (1999) Computer Speech & Language 13 (4): 359–94. Interpolated and modified Kneser–Ney
- paper Concentration Inequalities for the Missing Mass and for Histogram Rule Error — David McAllester and Luis Ortiz (2003) Journal of Machine Learning Research 4: 895–911. The missing mass concentrates
- paper A Hierarchical Bayesian Language Model Based on Pitman–Yor Processes — Yee Whye Teh (2006) COLING/ACL 2006, 985–92. The HPYLM, its Kneser–Ney limit, and its Gibbs sampler
- documentation nltk.lm — Language Models — Steven Bird, Ewan Klein, and Edward Loper (2026) NLTK 3.10. The reference implementation our Kneser–Ney is checked against