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
Example
import freqprob
counts = {"the": 100, "cat": 50, "dog": 30, "bird": 10}
model = freqprob.Laplace(counts, bins=10_000, logprob=False)
model("cat") # 0.0050 observed element
model("elephant") # 0.0001 unobserved, yet non-zero
A maximum-likelihood estimate would assign probability
zero to "elephant", which is undefined under a logarithm and
collapses any product of probabilities. Smoothing reserves a small amount of
probability mass for the unobserved; the estimator is selected by construction
and the call site does not change.
The estimate
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 |
| Bayesian | a Dirichlet prior is assumed | alpha |
| Interpolated | a specific and a general model are combined | 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
Citation
@software{tresoldi_freqprob_2026,
author = {Tresoldi, Tiago},
title = {FreqProb: A Python library for probability smoothing
and frequency-based estimation},
year = {2026},
version = {0.6.2},
url = {https://github.com/tresoldi/freqprob}
}