A language model scores every possible next token; a sampler turns those scores into one choice. Edit the scores, change temperature, top-k and top-p, and watch each step of the pipeline. All the maths is exact and runs in your browser; no model is called.
The cat sat on the ▁▁▁
A spread of plausible endings with a long tail of odd ones. The ten candidates stand in for a real vocabulary of 100,000+ tokens.
Drag a bar or type a value. Logits are unbounded scores: negative just means “less likely than a logit of 0”, not “impossible”.
Shifting every logit by the same amount changes nothing downstream: softmax only sees differences.
Drops tokens below min-p × the top token’s probability, so the cut adapts to how confident the model is.
Hugging Face transformers and vLLM scale by temperature first. llama.cpp’s default chain truncates first. With a high temperature the two give different survivors.
Tokens are sorted by logit. Temperature never changes that order, so every truncation step cuts from the bottom. Struck-through red rows are what that step removed; faded rows were removed earlier.
The model's unnormalised scores. Any real number, including negatives.
T < 1 stretches the gaps between logits, so softmax will be peakier.
Exponentiate and normalise: every token gets a probability in (0, 1), summing to 1.
Removed 4 tokens holding 0.6% of the probability.
Removed 3 tokens holding 6.7% of the probability.
Survivors are rescaled to sum to 1. This is the distribution we sample from.
A logprob is the natural log of a softmax probability. Because softmax is exp-then-normalise, the log undoes the exp: ln pi = zi − ln Σj ezj. Here ln Σ ez = 5.687, so each model logprob is just its logit minus 5.687.
| Token | Logit z | Model p (T = 1) | ln p | Sampling q | ln q |
|---|---|---|---|---|---|
| mat | 5.20 | 0.615 | -0.487 | 0.775 | -0.255 |
| floor | 3.90 | 0.168 | -1.787 | 0.153 | -1.880 |
| sofa | 3.30 | 0.092 | -2.387 | 0.072 | -2.630 |
| bed | 2.90 | 0.062 | -2.787 | 0 | −∞ |
| roof | 2.20 | 0.031 | -3.487 | 0 | −∞ |
| windowsill | 1.70 | 0.019 | -3.987 | 0 | −∞ |
| keyboard | 1.00 | 0.0092 | -4.687 | 0 | −∞ |
| fence | 0.40 | 0.0051 | -5.287 | 0 | −∞ |
| moon | -1.60 | 0.0007 | -7.287 | 0 | −∞ |
| banana | -3.20 | 0.0001 | -8.887 | 0 | −∞ |
Sampling lays the final distribution end to end on [0, 1], draws a uniform random number u, and picks the token whose segment contains it.
No samples yet. Changing any setting clears the tally.
Perplexity here scores the sampled tokens with the model’s own T = 1 logprobs. Low temperature picks the tokens the model rates highest, so its output has low perplexity; greedy output has the lowest of all, which is also why it tends to be bland and repetitive over long texts.
Greedy decoding makes each token locally as likely as possible, but it commits to one path and cannot recover from an early wrong turn. Self-consistency samples several whole reasoning chains at T > 0, throws the reasoning away and majority-votes the final answers. It wins when the right answer has the most total probability spread over many paths, even though no single path to it is the likeliest.
3 boxes hold 6 eggs each, plus 6 loose eggs. How many eggs?
| Opening | P | then → 24 | → 18 |
|---|---|---|---|
| 3 × 6 = 18 … | 0.40 | 0.25 | 0.75 |
| 6 loose + 3 boxes of 6 … | 0.35 | 0.80 | 0.20 |
| Count: 6, 12, 18, 24 … | 0.25 | 0.84 | 0.16 |
Greedy takes the likeliest opening, then the likeliest answer: 18, wrong, every time. That single path is also the most probable complete path (0.30). But adding up all paths, P(24) = 0.59: the right answer is reachable by more routes.
Exact: P(more than n/2 of n chains say 24) = 71.2% at n = 9.