Min-p & Typical Sampling Calculator
Drag min_p or typical_pand watch which of a language model's next-token candidates survive, get zeroed, and renormalize — with the exact math token by token. No API key, no cost, runs in your browser.
How it works
A language model outputs a raw score — a logit — for every token in its vocabulary. Sampling parameters turn those logits into a probability distribution and then decide how much of the tail to keep. This tool covers the two samplers that the temperature & top-p visualizer leaves out — min-p and locally-typical— in the common reference order used by Hugging Face's generation code: temperature → softmax → truncate → renormalize.
- Tempered softmax. Each logit is divided by temperature
Tand run through softmax:p_i = exp(z_i / T) / Σ_j exp(z_j / T). We subtract the maximum scaled logit before exponentiating (the log-sum-exp trick) so large logits never overflow. AtT = 0the math collapses to greedy decoding — the top token gets probability 1. - Min-p truncation. Let
p_maxbe the highest probability. Compute the cutoffθ = min_p × p_maxand keep every token withp_i ≥ θ. Because the cutoff is relative to the top token, a confident (peaked) distribution truncates aggressively while an uncertain (flat) one keeps more candidates — the defining behaviour of min-p (Nguyen et al., 2024; HFMinPLogitsWarper). - Typical truncation. Compute the distribution's entropy
H = −Σ p_i ln p_i(nats). Score each token bys_i = |−ln p_i − H|— the distance of its surprisal from the entropy — then keep the smallest set, sorted by that score, whose cumulative probability reachestypical_p. This drops both the over-confident and the wildly surprising tokens (Meister et al., 2022; HFTypicalLogitsWarper). - Renormalize. Divide the surviving probabilities by their sum so they total 1 — the actual probabilities the sampler draws from.
As a credibility check, the tool verifies the min-p cutoff two ways: once on the softmax probabilities (p_i ≥ min_p·p_max) and once directly in logit space (z_i/T ≥ ln(min_p) + z_max/T), which is algebraically the same test. The summary chips add an entropy readout in bits and an effective choices count. Backends differ in whether temperature is applied before or after truncation and in tie-breaking, so this tool states its reference order rather than claiming to mirror any one implementation exactly. Everything is deterministic and runs entirely in your browser.
Worked examples
All three use the base distribution cat=2.0, dog=1.0, bird=0.5, fish=0.0 at T = 1.0, whose tempered softmax is p = [0.5793, 0.2131, 0.1293, 0.0784] (so p_max = 0.5793), except Example B, which uses a deliberately flat distribution.
Frequently asked questions
Sources & references
- Nguyen, Baker et al. (2024) — Turning Up the Heat: Min-p Sampling for Creative and Coherent LLM Outputs
- Meister, Pimentel, Wiher & Cotterell (2022) — Locally Typical Sampling
- Hugging Face Transformers — MinPLogitsWarper & TypicalLogitsWarper (reference implementations)
- llama.cpp — sampling documentation (--min-p default 0.05)
- Goodfellow, Bengio & Courville (2016) — Deep Learning (tempered softmax)
The formulas above were last cross-checked against these sources on 2026-07-11. The sampling math is standard; the worked examples double as the tool's reconciliation fixtures (tolerance 1e-4).
Related tools
Comments & feedback
Spotted a bug or want an improvement? Tell us — our team reviews every comment, and good ideas get built. Comments are public and anonymous.
Found a bug, edge case, or want to suggest an improvement?
Email me at [email protected] — most fixes ship within 24 hours.