Techniqueintro
Laplace smoothing
Also called add-one smoothing, add-k smoothing, Lidstone smoothing, additive smoothing.
Add one, or a constant k, to every count before normalizing, so no event gets zero probability. Simple, but with a large vocabulary it takes too much mass from seen events.
Laplace smoothing turns counts into probabilities by adding a small constant to every count first, so that an event never seen in the sample still gets a probability above zero. With the constant 1 it is called add-one smoothing; with a general constant it is add-k or Lidstone smoothing. It is used wherever a table of counts must give probabilities for events that may be missing from it: next-word tables in an n-gram language model, word counts in a naive Bayes classifier, and base counts in DNA motif profiles, where the added counts are called pseudocounts (see greedy motif search and motif information content). It is the easiest smoothing to state and to prove correct, and with a large vocabulary it is one of the least accurate.
In plain words
You count what you saw and divide by the total. Anything you did not see then gets a chance of zero, and one such zero can make a whole sentence impossible.
The fix is to pretend that you saw every possible outcome a few extra times, the same number of times for each. Add that number to every count, also the counts that are zero, and divide by the new total. Outcomes you saw keep most of their share, and outcomes you did not see get a small equal share.
The cost is that every unseen outcome gets the same extra share. When there are many more possible outcomes than observations, the unseen ones together take most of the total.
When it applies
It applies to a table of counts for a fixed, finite set of outcomes and a set of contexts , where each row must become a distribution on . In a language model, is the history and is the vocabulary of predicted tokens, which holds the end marker </s> and the unknown-word token <unk> but not the start marker <s>. The set must be fixed before counting, since enters every probability.
It works well when is small compared with the number of observations per context: a few classes, four DNA bases, the letters of an alphabet, or the features of a text classifier where only the ratio of two probabilities matters. It works badly for word n-grams, where is in the tens of thousands and most contexts are seen only a few times.
The template
Fix . For a context with total count ,
Every value is positive, and the row sums to . The names of the special cases are:
| name | |
|---|---|
| Laplace, or add-one | |
| Jeffreys-Perks, or expected likelihood estimation | |
| any | Lidstone, or add-k |
The estimate is a weighted mean of the maximum likelihood estimate and the uniform distribution:
so it is a fixed form of interpolation, with a weight that depends only on . A context never seen, with , gets the uniform distribution. The count that the estimate acts as if it saw, the adjusted count, is
In Bayesian terms, is the posterior mean of the row when the prior on the row is a symmetric Dirichlet distribution with parameter for each outcome (see conjugate prior and Bayes' theorem). The case is a uniform prior on the simplex.
Classic examples
Laplace's rule of succession. With two outcomes and , an event that happened times in trials gets the probability for the next trial. Laplace used it for the chance that the sun rises tomorrow, given that it has risen every day on record.
A base after a DNA context. In a model of DNA with , the context CG is seen 5 times, followed by A twice and by G three times. The maximum likelihood estimate gives C and T the probability 0. Add-one smoothing divides by :
| base | count | |
|---|---|---|
| A | 2 | 3/9 |
| C | 0 | 1/9 |
| G | 3 | 4/9 |
| T | 0 | 1/9 |
Here is small, so the seen bases keep of the mass.
A word bigram row. In a word model with , a history seen 10 times and followed by 3 different words has 49 997 unseen followers. Add-one smoothing gives each of them , and all of them together , more than 99.9% of the row. A follower seen 5 times gets , against from the counts. Gale and Church (1994) compared add-one estimates of English bigram counts with the counts in held-out text and found them far worse than the alternatives, mostly for this reason.
Text classification. A naive Bayes classifier multiplies over the words of a document. A single word never seen in the training documents of a class would make that class impossible. Add-one smoothing over the word list prevents this, and since the decision compares classes, the overall shrinkage matters less than in a language model.
Variations
- Tuned . Choose on held-out text, for example by minimizing the perplexity. For word models the best is often much smaller than 1, but the result is usually still worse than Good-Turing estimation, Witten-Bell smoothing or absolute discounting.
- Non-uniform pseudocounts. Add for a distribution on , so that with a lower-order model. This is the form of Dirichlet prior smoothing in retrieval, where is the collection model; a fixed weight in place of gives Jelinek-Mercer smoothing.
- Pseudocounts in profiles. Motif finders add a pseudocount to each base in each column of a profile, so that a base never seen in a column does not make a candidate motif impossible.
- Add to the unigrams only. Many n-gram systems smooth only the unigram level by adding , and handle the higher orders with discounting or interpolation.
Pitfalls
- Too much mass to unseen events. With , the unseen words take most of every row, as in the bigram example. The perplexity of a word model with add-one smoothing is usually much worse than with any discounting method.
- The same share for every unseen event. An unseen word gets whether it is common or rare in general. A lower-order model, as in interpolation or backoff, gives better shares.
- The vocabulary must be fixed. must count every token that can be predicted, with
</s>and<unk>. Values computed with different are not comparable, and a value of that misses a token gives rows that do not sum to 1. - Do not add to only. The denominator must grow by , the sum of the added counts, not by .
- Raw counts after smoothing. The adjusted counts of seen events are lower than the counts, often much lower. Report probabilities, or adjusted counts, not the sum of the two.
Exercises
- Show that sums to 1 over and that it equals the uniform distribution when .
- For the CG context above, compute the add-k estimates with , and check that they sum to 1.
- In the word bigram example, find the value of for which the unseen words get half of the row.
- Show that as for , and as .
- Show that the posterior mean of a Dirichlet distribution with parameters is .
References
- Christopher D. Manning and Hinrich Schütze, Foundations of Statistical Natural Language Processing, MIT Press, 1999, Chapter 6, Section 6.2 (statistical estimators, with Laplace's law, Lidstone's law and the Jeffreys-Perks law)
- Gale and Church 1994, the comparison of add-one estimates of English bigram counts with held-out counts
- Daniel Jurafsky and James H. Martin, Speech and Language Processing, third edition draft, chapter N-gram Language Models (draft of January 2026), Laplace smoothing and add-k smoothing
Where this leads
About this page
The build computes these levels from the evidence in the repository. Each row says what the next level needs. Read what the levels mean.
| Ladder | Level | What the next level needs |
|---|---|---|
| Human proof | H0 no proof |
|
| Lean | L0 no Lean part |
|
| Visual | V0 none |
|
| Writing | W2 basic |
|
Tag 8JPVRM Edit this page History Report an error Markdown