Skip to content

Sampling Playground: Temperature, Top-p, Top-k and Min-p

Drag temperature and the truncation settings over a distribution you supply, and see the before and after bars, the mass discarded and the entropy that results.

Effective choices after sampling settings
5.45

2^H, where H is the entropy of the final distribution — the number of equally likely candidates this sampler is really choosing between. Before any setting was applied it was 5.45 out of 12 candidates.

the2.90
41.4%
a2.40
25.1%
this1.60
11.3%
that1.20
7.6%
one0.70
4.6%
some0.30
3.1%
its0.10
2.5%
their-0.20
1.9%
each-0.60
1.2%
another-1.10
0.8%
every-1.70
0.4%
no-2.40
0.2%

Faint bar: the distribution at temperature 1 with nothing truncated. Solid bar: after temperature, truncation and renormalisation. Struck-through rows were cut and can never be sampled, whatever their logit was.

Candidates supplied
12
Candidates surviving the filters
12
Probability mass kept before renormalising
100.00%
Most likely candidate
the at 41.4%
Entropy at temperature 1, untruncated
2.447 bits
Entropy after your settings
2.447 bits
Perplexity after your settings
5.45
One draw at seed 7
the
Where these numbers come from: The logits are yours. The twelve on arrival are an illustrative shape, not any model's output for any prompt, and they are there so the sliders have something to act on before you paste your own. Everything computed from them — the softmax, the truncation, the renormalisation, the entropy and the single seeded draw — is exact arithmetic you can check by hand on twelve numbers.
What this assumes: Filters are applied in the order temperature → top-k → top-p → min-p, then the survivors are renormalised once. That is the order the common implementations use, and it matters: top-p computed before temperature would keep a different set. Top-p keeps the smallest set of candidates whose cumulative probability reaches p, including the candidate that crosses the threshold. Temperature 0 is treated as greedy argmax rather than as a division by zero. Repetition and frequency penalties are not modelled; they act on logits before this point and depend on tokens already generated. The seeded draw uses one pseudo-random number so a shared URL always shows the same draw.

What temperature actually does

Temperature is not a creativity dial and it is not a confidence setting. It divides every logit by a constant before the softmax, and because the softmax is exponential, dividing the inputs compresses the ratios between the outputs. Set it to 0.2 and the gaps blow up: the top candidate takes nearly all the mass and the tail vanishes. Set it to 2 and the gaps shrink towards nothing, so a candidate the model scored two logits lower becomes a realistic outcome. The model computed one set of logits; temperature only changes how you read them.

Top-p and top-k do something categorically different, and this is the distinction the two bars above are drawn for. Temperature reshapes the whole distribution and leaves every candidate reachable. Truncation deletes candidates outright — a token below the cut has probability exactly zero and cannot be produced at any temperature. That is why raising temperature under a tight top-p feels like it does nothing: you are redistributing mass inside a set of three survivors. Watch the "candidates surviving" row while you drag temperature with top-p at 0.9: high temperature flattens the distribution, which makes the nucleus wider, which lets more tokens through. The two settings interact, and neither is a monotone knob on its own.

What this page leaves out is the part that decides whether the output is any good: the logits themselves. A well-calibrated model at temperature 1 and a badly-calibrated one at temperature 0.3 can produce identical distributions here. Sampling settings cannot add information the model did not have, and no value of top-p makes a wrong answer less wrong — it only changes how often you see the second-best one.

Sampling Playground: Temperature, Top-p, Top-k and Min-p · Multigrid