The central difficulty in working with frequency counts is the unobserved: how much probability to assign to events that never appeared in the data. FreqProb converts counts into smoothed probability estimates that address this directly — reserving a principled share of mass for what was not seen — and offers a range of classical smoothing methods, from Laplace and Lidstone to Simple Good-Turing and Kneser-Ney, behind a single, consistent interface.
Installation
pip install freqprob
Quick start
>>> import freqprob >>> counts = {"the": 100, "cat": 50, "dog": 30, "bird": 10} >>> freqprob.MLE(counts, logprob=False)("elephant") 0.0 >>> laplace = freqprob.Laplace(counts, bins=10_000, ... logprob=False) >>> round(laplace("cat"), 4) # observed 0.005 >>> round(laplace("elephant"), 4) # unseen 0.0001
A raw relative-frequency estimate gives the unseen
"elephant" probability 0, which breaks any model that multiplies
probabilities or takes their logarithm. Smoothing reserves some mass for what
has not been seen yet; every estimator is built from counts and called the
same way, so swapping methods does not change the call site.
The estimate
import this): 85 distinct words, 60
of them seen only once. Bars show the relative frequency of the eleven words
seen at least three times; the line shows their Simple Good–Turing
estimates. Because so many words are singletons, the estimator infers that
many more remain unseen and moves 42% of the probability mass to them (strip
below), taking it mostly from the rarer observed words.Methods
| Estimator | Appropriate when | Parameter |
|---|---|---|
| MLE | relative frequencies are wanted, without smoothing | — |
| Laplace, Lidstone, ELE | simple additive smoothing suffices | bins, gamma |
| SimpleGoodTuring | the distribution is heavy-tailed with many rare types | p_value |
| WittenBell | a parameter-free discount tied to the number of distinct types is wanted | bins |
| KneserNey, ModifiedKneserNey | estimating an n-gram language model | discount |
| AbsoluteDiscounting, PitmanYor | bigram discounting with back-off to a unigram model | discount, strength |
| KatzBackoff, StupidBackoff | bigram back-off, normalised (Katz) or fast and unnormalised (Stupid) | k, alpha |
| Bayesian | a Dirichlet prior is assumed | alpha |
| Interpolated, JelinekMercer | a specific and a general model are combined, with a fixed or EM-fitted weight | lambda_weight |
| CertaintyDegree | mass is reserved by how fully the support has been observed (experimental) | bins |
| Uniform, Random | a non-informative baseline is needed | — |
Beyond text
The problem — estimating probabilities from counts, including for the unobserved — recurs across fields. FreqProb is domain-neutral:
- Text. n-gram and word-frequency models; term weighting.
- Ecology. species-abundance data and the classical unseen-species problem.
- Genomics. k-mer frequencies over the space of possible subsequences.
- Categorical data. smoothed category priors for features and event counts.
Documentation
Related projects
- nltk.probability. several of the same estimators (Laplace, Lidstone, ELE, Simple Good–Turing, Kneser–Ney, Witten–Bell) within a broader NLP toolkit; FreqProb is standalone, works on any frequency counts, and is tested against NLTK.
- ASymCat. uses FreqProb for smoothing and bias-corrected entropy in its directional measures of association between categorical variables.
Citation
Please cite the version you used. See How to cite for APA and classic BibTeX forms, and References for the papers behind each method.
@software{tresoldi_freqprob,
author = {Tresoldi, Tiago},
title = {{FreqProb}: A {Python} library for probability smoothing
and frequency-based estimation},
year = {2026},
version = {0.9.0},
doi = {10.5281/zenodo.23917393},
url = {https://freqprob.tresoldi.org/}
}