induwara.lk
induwara.lkAI · Sampling

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.

By Induwara AshinsanaUpdated Jul 11, 2026
Min-p & typical sampler
Runs in your browser · no API key
Sampler

Keeps every token with probability ≥ min_p × (top token's probability).

Distribution preset

A moderately peaked distribution — the worked-example set.

Cutoff = 5% of the top token's probability

Most likely token
cat
57.93%
min_p cutoff
2.9%
min_p × p_max
Effective choices
4
surviving tokens
Entropy
1.6 bits
Spread out

Tempered probability & min_p cutoff

cat
57.93%
dog
21.31%
bird
12.93%
fish
7.84%

Right now min_p keeps 4 of 4 tokens. The same min_p on a perfectly flat distribution of 4 tokens would keep all 4 — because the cutoff is relative to the top token, min-p truncates hard when the model is confident and barely at all when it is unsure. That adaptiveness is what sets it apart from top-p.

Step-by-step math

TokenLogit zSoftmax p≥ cutoff?SurvivesFinal prob
cat257.93%57.93% vs 2.9%57.93%
dog121.31%21.31% vs 2.9%21.31%
bird0.512.93%12.93% vs 2.9%12.93%
fish07.84%7.84% vs 2.9%7.84%

Order: temperature → softmax → min-p → renormalize. .

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.

  1. Tempered softmax. Each logit is divided by temperature T and 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. At T = 0 the math collapses to greedy decoding — the top token gets probability 1.
  2. Min-p truncation. Let p_max be the highest probability. Compute the cutoff θ = min_p × p_max and keep every token with p_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; HF MinPLogitsWarper).
  3. Typical truncation. Compute the distribution's entropy H = −Σ p_i ln p_i (nats). Score each token by s_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 reaches typical_p. This drops both the over-confident and the wildly surprising tokens (Meister et al., 2022; HF TypicalLogitsWarper).
  4. 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.

A · Min-p on a peaked distribution

min_p = 0.2 then 0.4

  1. min_p = 0.2 → cutoff θ = 0.2 × 0.5793 = 0.1159
  2. Keep p ≥ 0.1159: cat 0.5793 ✓, dog 0.2131 ✓, bird 0.1293 ✓, fish 0.0784 ✗
  3. Renormalize over 0.9216 → cat 62.85%, dog 23.12%, bird 14.03%, fish 0% (3 choices)
  4. min_p = 0.4 → θ = 0.2317: only cat survives (dog 0.2131 now falls below) → cat 100%

B · Min-p on a flat distribution (adaptiveness)

logits [1.0, 0.9, 0.8, 0.7], min_p = 0.4

  1. Softmax → p = [0.2887, 0.2612, 0.2363, 0.2138], p_max = 0.2887
  2. Cutoff θ = 0.4 × 0.2887 = 0.1155
  3. Smallest token 0.2138 is still above θ → all four survive
  4. The same min_p = 0.4 kept only 1 token in Example A — min-p adapts to the top token

C · Typical sampling on the peaked distribution

typical_p = 0.9

  1. Entropy H = −Σ p ln p = 1.1097 nats
  2. Typicality |−ln p − H|: dog 0.436, cat 0.564, bird 0.936, fish 1.436 → sort asc
  3. Cumulative in that order: dog 0.2131 → +cat 0.7924 → +bird 0.9216 (≥ 0.9, stop)
  4. Keep dog, cat, bird; drop fish → cat 62.85%, dog 23.12%, bird 14.03% (dog ranks first!)

Frequently asked questions

Sources & references

Related tools

Rate this tool
Be the first to rate

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.