NLP & Speech

Smoothing: Laplace and Kneser-Ney

See why add-one smoothing is only the first repair, then predict how Kneser-Ney uses continuation contexts to allocate backoff mass.

status: reviewimportance: importantdifficulty 3/5math: undergraduateread: 16mlive demo

Concept Structure

Smoothing: Laplace and Kneser-Ney

01Intuition

Start with the picture, metaphor, or geometric mechanism.

02Math

Make the objects explicit and connect them with notation.

03Code

Mirror the equations with runnable implementation details.

04Interactive Demo

Manipulate the mechanism and watch the idea respond.

2prerequisites
3next concepts
3related links

Learner Contract

What this page should let you do.

You are here becauseSee why add-one smoothing is only the first repair, then predict how Kneser-Ney uses continuation contexts to allocate backoff mass.

This NLP & Speech concept is the current idea: keep the same invariant visible across Intuition, Math, Code, Interactive Demo.

By the end4/4 sections ready | runnable code expected | live demo

Explain the mechanism, trace the main notation, and test one prediction in the live demo.

Do this firstIntuition

Read the intuition before the notation; the math should name a mechanism you already felt.

Test the linkManipulate one control and predict the visible change.Then continue to Beam Search and Sequence Decoding (review)

Claim/source review status

Substantive review recorded

1/1 claims have bounded review metadata; still check caveats and source scope.Metadata-derived; review may be AI-assisted. Not a human certification.
Claims1/1 reviewed
Sources4 cited
Codeattached
Demolive
Reviewed2026-07-03
Updatedpage 2026-07-03

Learning item flow

4/4 sections readyAsk about thisResearch room
ConceptSmoothing: Laplace and Kneser-NeyNLP & Speech
4 sources attachedLocal snapshot ready
concept:nlp-speech/smoothing-laplace-kneser-ney
01

01

Intuition

Build the mental picture first so the rest of the page has something to attach to.

Section prompt

An n-gram table can look confident for the wrong reason: it has never seen many perfectly reasonable events.

If the training corpus contains new york and new models but never new san, maximum likelihood gives san after new probability zero. One unseen transition can make a whole sentence score zero.

Laplace smoothing is the first repair. Add one imaginary count to every possible next word:

  • observed words lose some probability mass
  • unseen words no longer get zero
  • every unseen word gets the same gift

That last point is why add-one is usually a teaching smoother, not the final answer.

Kneser-Ney asks a sharper question: "If I need to back off, which words have shown they can follow many different histories?"

In a tiny corpus, francisco may appear often, but only after san. The word york may appear after new, old, and near. Kneser-Ney treats that continuation diversity as evidence. When probability mass has to be reserved for backoff, it gives more of that mass to words that have appeared in more distinct left contexts.

Source spine: Jurafsky and Martin, SLP3 Chapter 3 and Appendix C; Chen and Goodman, An Empirical Study of Smoothing Techniques for Language Modeling.

02

02

Math

Translate the story into symbols, assumptions, and a derivation you can inspect.

Section prompt

Let hh be a context, ww be the next word, and c(h,w)c(h,w) be the count of that bigram. The maximum-likelihood estimate is:

PMLE(wh)=c(h,w)c(h)P_{\text{MLE}}(w \mid h) = \frac{c(h,w)}{c(h)}

where

c(h)=wc(h,w).c(h)=\sum_{w'} c(h,w').

If c(h,w)=0c(h,w)=0, then PMLE(wh)=0P_{\text{MLE}}(w \mid h)=0.

Laplace smoothing with pseudo-count α=1\alpha=1 uses:

PLaplace(wh)=c(h,w)+1c(h)+V.P_{\text{Laplace}}(w \mid h) = \frac{c(h,w)+1}{c(h)+|\mathcal V|}.

It repairs zero probability, but it does not ask whether an unseen word is a plausible continuation. Every vocabulary item receives the same pseudo-count.

Interpolated bigram Kneser-Ney uses a discount DD on observed counts and sends the reserved mass to a continuation distribution:

PKN(wh)=max(c(h,w)D,0)c(h)+λ(h)Pcont(w).P_{\text{KN}}(w \mid h) = \frac{\max(c(h,w)-D,0)}{c(h)} + \lambda(h)P_{\text{cont}}(w).

The reserved mass is:

λ(h)=DN1+(h,)c(h).\lambda(h)=\frac{D\,N_{1+}(h,*)}{c(h)}.

Here N1+(h,)N_{1+}(h,*) is the number of distinct next words observed after hh.

The continuation probability is:

Pcont(w)=N1+(,w)N1+(,).P_{\text{cont}}(w) = \frac{N_{1+}(*,w)}{N_{1+}(*,*)}.

N1+(,w)N_{1+}(*,w) counts how many distinct left contexts have been seen before ww. N1+(,)N_{1+}(*,*) counts distinct bigram types overall.

This page uses the single-discount bigram form because it is inspectable. Production n-gram language models often use modified Kneser-Ney with multiple discounts and recursive higher-order interpolation.

03

03

Code

Keep the implementation aligned with the notation so the algorithm is legible.

Section prompt

This small script compares MLE, Laplace, and interpolated Kneser-Ney on the same context.

pairs = {
    ("new", "york"): 1,
    ("new", "models"): 1,
    ("old", "york"): 1,
    ("near", "york"): 1,
    ("old", "san"): 1,
    ("near", "san"): 1,
    ("san", "francisco"): 3,
    ("smart", "models"): 1,
}

candidates = ["york", "models", "san", "francisco"]
context = "new"
D = 0.75

def count(h, w):
    return pairs.get((h, w), 0)

def total(h):
    return sum(n for (left, _), n in pairs.items() if left == h)

def histories(w):
    return {left for (left, right), n in pairs.items() if right == w and n > 0}

V = len(candidates)
T = total(context)
types_after_context = sum(1 for w in candidates if count(context, w) > 0)
bigram_types = sum(1 for n in pairs.values() if n > 0)
reserved = D * types_after_context / T

for w in candidates:
    mle = count(context, w) / T
    laplace = (count(context, w) + 1) / (T + V)
    continuation = len(histories(w)) / bigram_types
    kn = max(count(context, w) - D, 0) / T + reserved * continuation
    print(f"{w:10s} MLE={mle:.3f} Laplace={laplace:.3f} KN={kn:.3f}")

The important comparison is not just "zero or nonzero." It is whether the smoother has a reason to prefer one unseen continuation over another.

04

04

Interactive Demo

Use direct manipulation to connect the explanation to a moving system.

Section prompt

Prediction check: inspect the tiny bigram corpus, then predict which smoothing method separates york from models after new and which unseen candidate receives more Kneser-Ney backoff mass before revealing the probability table.

The lab hides the final probabilities, reserved mass, continuation counts, and explanation until you commit. The goal is to feel why add-one is a blunt repair and why Kneser-Ney changes the meaning of a good backoff distribution.

Live Concept Demo

Explore Smoothing: Laplace and Kneser-Ney

The stage is code-native and interactive. Use it to test the explanation against the mechanism.

difficulty 3/5undergraduatecode-aligned
Demo Prediction Checkpoint

Manipulate one control and predict the visible change.

Commit to what Smoothing: Laplace and Kneser-Ney should make visible before reading the result.

After The First Pass

Turn the concept into an inspected object.

Once the invariant is visible in the intuition, math, code, and demo, use these panels to inspect the mechanism visually, check source support, practice the idea, and attach a grounded research question.

Mechanism Storyboard

See the idea move before the page explains it

See why add-one smoothing is only the first repair, then predict how Kneser-Ney uses continuation contexts to allocate backoff mass.

Prediction open01 / Intuition
Prediction lens

Start with the picture, metaphor, or geometric mechanism.

Commit first

Before reading further, choose the kind of change Smoothing: Laplace and Kneser-Ney should make visible.

Visual Inquiry

Make the image answer a mathematical question

See why add-one smoothing is only the first repair, then predict how Kneser-Ney uses continuation contexts to allocate backoff mass.

4/4 stages readyLive demo connected
Prediction

Which visible object should carry the first intuition?

Commit first

Pick the cue that should make Smoothing: Laplace and Kneser-Ney easier to reason about before the page gives the answer.

Source Grounding

Canonical references for the mechanism on this page.

book · 2026Speech and Language Processing, Chapter 3: N-gram Language ModelsJurafsky and Martin

Source for n-gram maximum-likelihood estimates, zero-probability sparsity, add-one smoothing as a simple repair, interpolation, backoff, and perplexity framing.

Open source
book · 2025Speech and Language Processing, Appendix C: SmoothingJurafsky and Martin

Source for absolute discounting, Kneser-Ney continuation probability, and the intuition that lower-order probability should depend on how many contexts a word follows.

Open source
paper · 1998An Empirical Study of Smoothing Techniques for Language ModelingChen and Goodman

Primary comparative source for smoothing methods, including the empirical strength of Kneser-Ney and modified Kneser-Ney style estimators.

Open source
paper · 1996An Empirical Study of Smoothing Techniques for Language ModelingChen and Goodman

ACL Anthology record for the conference version of the smoothing study; useful as a stable bibliographic anchor for Kneser-Ney comparisons.

Open source

Claim Review

See why add-one smoothing is only the first repair, then predict how Kneser-Ney uses continuation contexts to allocate backoff mass.

Status1 substantive review recorded

Claims without a substantive review badge still need exact source-support review.

Sources4 references

jurafsky-martin-slp3-ngram, jurafsky-martin-slp3-appendix-c-smoothing, chen-goodman-1998-smoothing, chen-goodman-1996-kneser-ney

Local checks4 local checks

Use equations, runnable code, and demos to check whether the source support is operational.

Substantively reviewedLaplace smoothing repairs zero probabilities by adding a uniform pseudo-count, while interpolated Kneser-Ney uses discounting and continuation probability so backoff mass favors words that have appeared after more distinct histories.Claim metadata: source checked

SLP3 Chapter 3 supports the MLE zero-probability failure, add-one smoothing, and the role of smoothing in perplexity evaluation. SLP3 Appendix C and Chen-Goodman support absolute discounting, interpolation/backoff, Kneser-Ney continuation counts, and the empirical importance of Kneser-Ney variants.

Sources: Speech and Language Processing, Chapter 3: N-gram Language Models, Speech and Language Processing, Appendix C: Smoothing, An Empirical Study of Smoothing Techniques for Language Modeling, An Empirical Study of Smoothing Techniques for Language ModelingThe page implements a tiny single-discount interpolated bigram Kneser-Ney example. It is not a full modified Kneser-Ney implementation, does not estimate discounts from held-out data, and does not claim count smoothing is how neural LLMs allocate probability.A bounded review summary is present; still check caveats and exact reference scope.

Checked SLP3 Chapter 3 and Appendix C plus Chen-Goodman smoothing sources. Built a hand-computable corpus where MLE and Laplace tie two observed candidates, while Kneser-Ney breaks the tie through continuation diversity and allocates unseen mass by distinct left contexts. GPT Pro/Oracle critique remains unavailable because 127.0.0.1:51672 is closed.

Reviewer: codex-local-primary-source-audit; reviewed 2026-07-03

Practice Loop

Try the idea before it explains itself

See why add-one smoothing is only the first repair, then predict how Kneser-Ney uses continuation contexts to allocate backoff mass.

Readiness0/3 checks ready
Predict

Before touching the demo, predict one visible change that should happen in Smoothing: Laplace and Kneser-Ney.

Hint 1

Reveal when your model needs a nudge.

Hint 2

Reveal when your model needs a nudge.

Hint 3

Reveal when your model needs a nudge.

Grounded research drawerClose
ConceptSmoothing: Laplace and Kneser-NeyNLP & Speech

Research Room

Attach the question to a claim, equation, code, or demo

Pick the concept, equation, source, runnable code, claim, misconception, or demo state before asking for help. The handoff keeps that page item in context.
Next local actionNo local draft saved yet

Open the draft below to save one note and next action in this browser.

conceptNLP & Speech

Smoothing: Laplace and Kneser-Ney

Attached question

What is the smallest example that makes Smoothing: Laplace and Kneser-Ney click without losing the math?

Local action draftNo local draft saved yetExpand only when ready to capture one local next action
Local action draft

This draft stays in this browser, attached to the selected learning item.

No local draft saved.
Evidence to inspect
  • References to inspect: attached references on this page.
  • Definition, prerequisite, and contrast concept links
  • The equation or runnable code that makes the concept operational
  • One demo state that shows the invariant instead of a slogan
What would resolve this
  • The learner can state the mechanism in their own words
  • The learner can name the prerequisite that would repair confusion
  • The learner can predict how the mechanism changes under one perturbation
Grounded AI handoff

I am working in Continuous Function's research reading room. Object: concept - Smoothing: Laplace and Kneser-Ney Selected item key: recorded for copy. Context: NLP & Speech Page anchor: recorded for copy. Open question: What is the smallest example that makes Smoothing: Laplace and Kneser-Ney click without losing the math? Evidence to inspect: - References to inspect: attached references on this page. - Definition, prerequisite, and contrast concept links - The equation or runnable code that makes the concept operational - One demo state that shows the invariant instead of a slogan What would resolve this: - The learner can state the mechanism in their own words - The learner can name the prerequisite that would repair confusion - The learner can predict how the mechanism changes under one perturbation Answer as a careful research tutor: stay source-grounded, separate verified evidence from assumptions, name the relevant math objects, and end with one next action.

View it in context
concept/concept-notebook/nlp-speech/smoothing-laplace-kneser-ney concept:nlp-speech/smoothing-laplace-kneser-ney