FreqProb
Turn frequency counts into probability estimates.
FreqProb converts a mapping of elements to observed counts into smoothed probabilities that handle unseen elements sensibly. It's a general-purpose statistical tool — natural language processing is one consumer among many (information retrieval, ecology, genomics, categorical analytics, ML features).
import freqprob
counts = {"the": 100, "cat": 50, "dog": 30, "bird": 10}
laplace = freqprob.Laplace(counts, bins=10_000, logprob=False)
laplace("cat") # 0.0050 — an observed element
laplace("elephant") # 0.0001 — an unseen element still gets non-zero mass
That last line is the whole point: a raw relative-frequency estimate would
assign probability 0 to "elephant" and break any model that multiplies or
takes logs of probabilities. Smoothing reserves a bit of mass for what you
haven't seen yet — and FreqProb gives you a dozen well-tested ways to do it
behind one consistent interface.
Install
pip install freqprob
The interface
Every estimator follows the same contract: construct it with a frequency distribution, then call it to score an element.
import freqprob
bigram_counts = {("the", "cat"): 5, ("the", "dog"): 3, ("a", "cat"): 2}
scorer = freqprob.KneserNey(bigram_counts, discount=0.75)
scorer(("the", "cat")) # score one element
scorer.predict([("the", "cat"), ("a", "dog")]) # score many (scikit-learn-style)
freqprob.perplexity(scorer, [("the", "cat"), ("a", "cat")]) # evaluate a model
fit/predict/score aliases are available for scikit-learn familiarity, and
any fitted estimator can be saved with .save(path) and reloaded with
.load(path) without re-fitting.
Choosing a method
| Method | Use it for | Key parameter |
|---|---|---|
MLE |
raw relative frequencies (no smoothing) | — |
Laplace / Lidstone / ELE |
simple, robust additive smoothing | bins, gamma |
SimpleGoodTuring |
heavy-tailed count data (many rare items) | p_value |
KneserNey / ModifiedKneserNey |
n-gram language models | discount |
WittenBell |
parameter-free discounting by distinct-type count | bins |
Bayesian |
Dirichlet-prior smoothing | alpha |
Interpolated |
combining models of different orders | lambda_weight |
CertaintyDegree |
reserving mass by how fully the support is observed (experimental) | bins |
Uniform / Random |
non-informative baselines | — |
For large or streaming data, FreqProb also provides vectorized batch scoring, lazy evaluation, streaming (incremental) estimators, and memory-efficient compressed/sparse representations.
Why FreqProb
- One consistent API across a dozen smoothing methods — swap estimators without rewriting your code.
- Mathematically validated against reference implementations (NLTK, SciPy) and checked with property-based tests.
- Typed and production-ready — full type hints (
py.typed), strict linting and type-checking, and a test suite run across Python 3.10–3.12 on Linux, macOS, and Windows.
Documentation
- Documentation site — user guide and full API reference.
- User Guide — concepts, choosing a method, and worked examples across text, ecology, genomics, and categorical data.
- API Reference — every public class and function, generated from the source with a runnable example.
Citation
If you use FreqProb in academic research, please cite:
@software{tresoldi_freqprob_2026,
author = {Tresoldi, Tiago},
title = {FreqProb: A Python library for probability smoothing and frequency-based estimation},
url = {https://github.com/tresoldi/freqprob},
version = {0.6.2},
year = {2026}
}
License
MIT — see LICENSE.
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file freqprob-0.6.2.tar.gz.
File metadata
- Download URL: freqprob-0.6.2.tar.gz
- Upload date:
- Size: 105.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via:
twine/6.1.0 CPython/3.13.14
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
8874eed5eddbbadb42c6f5ca88a9f06e1aeb7219fead2e06a8680465ec471fde
|
|
| MD5 |
26f2c7806000c225d9c163be047d2cb7
|
|
| BLAKE2b-256 |
94e1644a6b458022224a2ed3b14ee3a344b01844d8a4665fb970a553c58c3a9d
|
Provenance
The following attestation bundles were made for freqprob-0.6.2.tar.gz:
Publisher:
release.yml on tresoldi/freqprob
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
freqprob-0.6.2.tar.gz -
Subject digest:
8874eed5eddbbadb42c6f5ca88a9f06e1aeb7219fead2e06a8680465ec471fde - Sigstore transparency entry: 2273153991
- Sigstore integration time:
-
Permalink:
tresoldi/freqprob@b9043d101ad47a42a9d8fd5a95c17c282b3b00f2 -
Branch / Tag:
refs/tags/v0.6.2 - Owner: https://github.com/tresoldi
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@b9043d101ad47a42a9d8fd5a95c17c282b3b00f2 -
Trigger Event:
push
-
Statement type:
File details
Details for the file freqprob-0.6.2-py3-none-any.whl.
File metadata
- Download URL: freqprob-0.6.2-py3-none-any.whl
- Upload date:
- Size: 62.9 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via:
twine/6.1.0 CPython/3.13.14
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
061a0fe9ea3c346a33ff31a0d96de688d6541c7420d2c2b39c05580f50f12936
|
|
| MD5 |
4ac669b89f20dc342aa7a90833f67bcb
|
|
| BLAKE2b-256 |
9f8961f4b1535a1bba28fa6e79b8c0618da388f71656cc7ec7cc569bb404a6d5
|
Provenance
The following attestation bundles were made for freqprob-0.6.2-py3-none-any.whl:
Publisher:
release.yml on tresoldi/freqprob
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
freqprob-0.6.2-py3-none-any.whl -
Subject digest:
061a0fe9ea3c346a33ff31a0d96de688d6541c7420d2c2b39c05580f50f12936 - Sigstore transparency entry: 2273154154
- Sigstore integration time:
-
Permalink:
tresoldi/freqprob@b9043d101ad47a42a9d8fd5a95c17c282b3b00f2 -
Branch / Tag:
refs/tags/v0.6.2 - Owner: https://github.com/tresoldi
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@b9043d101ad47a42a9d8fd5a95c17c282b3b00f2 -
Trigger Event:
push
-
Statement type: