Temperature and top_p Playground

Drag temperature, top_k and top_p over a small vocabulary of logits and watch the real softmax math reshape the distribution, one pipeline stage at a time. Everything runs in your browser.

Sampling controls

This tool applies the pipeline in one common order: temperature, then top_k, then top_p, then renormalize. Providers differ on that order. The explainer below says exactly what that means.

Presets
1.00

Divides every logit before the softmax. Below 1 sharpens, above 1 flattens, 0 is greedy argmax.

Slider covers 0 to 2. The box accepts up to 10.

5

A rank cut. Keeps exactly the k highest ranked tokens, whatever the shape of the distribution.

Slider stops just past the vocabulary size. The box goes higher.

0.90

A mass cut. Keeps the smallest set of top tokens whose probabilities sum to at least p.

At least one token always survives, even at p = 0.

Edge cases
Ready.

Vocabulary and logits

These logits are made up. They are a toy vocabulary chosen so each lesson is visible, not measurements from any real model. Edit any of them, add tokens, or remove tokens, and every number on the page recomputes.

Pipeline

Tokens removed by a stage stay visible and get marked, so you can see which control did the cutting rather than guessing from a shorter bar chart.

kept cut by top_k cut by top_p Every cut bar is also labeled in text, so color is never the only signal.

Numbers

All figures are computed exactly from the distribution shown. Nothing here is estimated or rounded before display.

Token Logit p after T Nucleus cum. Final p Change Status

Sampling demo

Draw N tokens from the final distribution and compare the observed frequencies with the theoretical probabilities. The generator is seeded, so the same seed and sample count always give the same counts.

Small N shows sampling variance. Large N converges on the theory.

The honest explainer

Why temperature 0 is still not fully deterministic in practice

In exact arithmetic, greedy decoding is deterministic: the highest logit wins, every time. The nondeterminism you actually see does not come from the maths. It comes from how the maths is executed.

Practical version: temperature 0 buys you much more reproducible output than temperature 1. It does not buy you bitwise identical output across calls, across time, or across providers. If you truly need identical bytes, cache the result rather than re-requesting it.

top_k and top_p interact, and the order is not standard

top_k is a rank cut and top_p is a mass cut. top_k keeps exactly k tokens no matter how the probability is spread. top_p keeps as few as one token on a confident step and dozens or hundreds on a flat one. Load the long-tail preset and move one knob at a time with the other one out of the way: at k = 5 you get exactly 5 candidates no matter what p does, while with top_k raised to 17 or above, p = 0.90 keeps 14 of the 17 tokens.

Run them together and the tighter filter wins at each step. That is why a (temperature, top_k, top_p) triple that behaves well on one stack can behave differently on another.

Order matters because the second filter usually reads a renormalized distribution. This tool applies temperature, then top_k, then top_p, and it measures p against the distribution renormalized over the top_k survivors. That is what happens in the common implementation where top_k masks the losing logits to negative infinity and top_p then reads the softmax of what is left. The visible consequence: after a tight k, the same p keeps more tokens than it would have on the full distribution, because the surviving mass was rescaled up to 1. Stage 3 on this page shows the exact cumulative sums p is compared against.

Providers differ and most hosted APIs do not document the internal order. In Hugging Face transformers, the default generation pipeline builds a list of logits processors and applies temperature scaling before top_k and top_p. In llama.cpp the sampler chain is explicit and user-configurable, so the order is whatever you set it to, and stacks in that family often add min_p, typical sampling, or repetition penalties into the same chain. Assume the order is different somewhere, and do not port a knob triple between providers expecting identical behavior.

The parameter surfaces themselves also differ, and they change over time:

Three providers, three different answers, and two of them changed in the last year. The lesson is not "memorise the table", it is "check the current docs for the provider you are actually calling, because both the ranges and the availability move". Everything in this list was true when the page was written and is exactly the kind of claim that goes stale.

Why "raise temperature for creativity" is a crude description

What temperature actually does: it divides every logit by T before the softmax. That is a monotone transform, so it never changes the ranking of tokens. It only changes the ratios between them. As T goes to 0 the distribution collapses onto the argmax. As T grows it flattens toward uniform over the whole vocabulary, and it never reaches exactly uniform for any finite T.

What this page is, and what it is not

Every number here is computed in the page from the logits in the editor above, using the same steps a real sampler uses: subtract the max for numerical stability, divide by temperature, exponentiate, normalize, truncate by rank, truncate by mass, renormalize. There are no libraries and no network requests.

The logits are invented and editable. They are chosen to make each lesson visible on a vocabulary of a handful of tokens instead of a hundred thousand. Nothing on this page reports a measurement from any specific model, and no benchmark figures are quoted. The sampling demo uses a seeded pseudo-random generator, so it reproduces exactly and is not a source of hidden randomness.

Real vocabularies run from roughly 30,000 tokens to a little over 250,000 depending on the tokenizer (Llama 2 uses 32,000, Llama 3 uses 128,256, Gemma uses 256,000), so a real top_p nucleus on an uncertain step can contain hundreds of tokens where this page shows a handful. The shape of the behavior is the same. The scale is not.