# Softmax temperature and min-p: how a language model picks its next word

A language model gives every candidate next token a raw score. Change the temperature and watch the probabilities sharpen or flatten, see the entropy and the number of effective choices, and apply min-p to cut the unlikely tail.

<div data-sim="specx" data-spec="{&quot;head&quot;:&quot;Softmax temperature and min-p sampling&quot;,&quot;sub&quot;:&quot;A language model scores every candidate next token. Temperature reshapes those scores into probabilities; min-p then drops the unlikely tail.&quot;,&quot;params&quot;:[{&quot;id&quot;:&quot;temp&quot;,&quot;label&quot;:&quot;Temperature&quot;,&quot;min&quot;:0.05,&quot;max&quot;:4,&quot;step&quot;:0.05,&quot;value&quot;:1,&quot;note&quot;:&quot;Below 1 sharpens, above 1 flattens&quot;},{&quot;id&quot;:&quot;minp&quot;,&quot;label&quot;:&quot;Min-p&quot;,&quot;min&quot;:0,&quot;max&quot;:1,&quot;step&quot;:0.01,&quot;value&quot;:0.1,&quot;note&quot;:&quot;Keep tokens with at least this share of the top token&#x27;s probability&quot;}],&quot;data&quot;:{&quot;columns&quot;:[&quot;logit&quot;],&quot;rows&quot;:[[3.2],[2.6],[1.9],[1.1],[0.4],[-0.3],[-1.2],[-2.0]],&quot;note&quot;:&quot;Eight candidate tokens and their logits (raw scores). Type your own logits or paste a column of them.&quot;},&quot;row&quot;:[{&quot;id&quot;:&quot;e&quot;,&quot;label&quot;:&quot;exp(logit/T)&quot;,&quot;expr&quot;:&quot;exp(logit/temp)&quot;,&quot;tex&quot;:&quot;e_i = \\exp(z_i / T)&quot;}],&quot;derived&quot;:[{&quot;id&quot;:&quot;zsum&quot;,&quot;label&quot;:&quot;Normaliser Z&quot;,&quot;expr&quot;:&quot;sum(e)&quot;,&quot;tex&quot;:&quot;Z = \\sum_j \\exp(z_j/T)&quot;},{&quot;id&quot;:&quot;emax&quot;,&quot;label&quot;:&quot;Largest exp term&quot;,&quot;expr&quot;:&quot;amax(e)&quot;,&quot;hide&quot;:true}],&quot;row2&quot;:[{&quot;id&quot;:&quot;p&quot;,&quot;label&quot;:&quot;probability&quot;,&quot;expr&quot;:&quot;e/zsum&quot;,&quot;fmt&quot;:&quot;p&quot;,&quot;tex&quot;:&quot;p_i = \\frac{\\exp(z_i/T)}{Z}&quot;},{&quot;id&quot;:&quot;keep&quot;,&quot;label&quot;:&quot;kept by min-p&quot;,&quot;expr&quot;:&quot;ge(e, minp*emax)&quot;,&quot;tex&quot;:&quot;\\text{keep}_i = [\\,p_i \\ge p_{\\min}\\cdot \\max_j p_j\\,]&quot;},{&quot;id&quot;:&quot;pk&quot;,&quot;label&quot;:&quot;kept mass&quot;,&quot;expr&quot;:&quot;p*keep&quot;,&quot;fmt&quot;:&quot;p&quot;},{&quot;id&quot;:&quot;h&quot;,&quot;label&quot;:&quot;-p ln p&quot;,&quot;expr&quot;:&quot;-p*ln(p + 1e-300)&quot;}],&quot;post&quot;:[{&quot;id&quot;:&quot;top&quot;,&quot;label&quot;:&quot;Top token probability&quot;,&quot;expr&quot;:&quot;emax/zsum&quot;,&quot;fmt&quot;:&quot;p&quot;},{&quot;id&quot;:&quot;ent&quot;,&quot;label&quot;:&quot;Entropy (nats)&quot;,&quot;expr&quot;:&quot;sum(h)&quot;,&quot;tex&quot;:&quot;H = -\\sum_i p_i \\ln p_i&quot;},{&quot;id&quot;:&quot;ppl&quot;,&quot;label&quot;:&quot;Effective choices&quot;,&quot;expr&quot;:&quot;exp(ent)&quot;,&quot;tex&quot;:&quot;\\text{perplexity} = e^{H}&quot;,&quot;note&quot;:&quot;how many equally likely tokens would give the same entropy&quot;},{&quot;id&quot;:&quot;kept&quot;,&quot;label&quot;:&quot;Tokens kept by min-p&quot;,&quot;expr&quot;:&quot;sum(keep)&quot;,&quot;fmt&quot;:&quot;i&quot;},{&quot;id&quot;:&quot;mass&quot;,&quot;label&quot;:&quot;Probability mass kept&quot;,&quot;expr&quot;:&quot;sum(pk)&quot;,&quot;fmt&quot;:&quot;p&quot;}],&quot;chart&quot;:{&quot;title&quot;:&quot;Probability of a token against its logit&quot;,&quot;x&quot;:{&quot;var&quot;:&quot;t&quot;,&quot;label&quot;:&quot;Logit (raw score)&quot;,&quot;from&quot;:-3,&quot;to&quot;:4},&quot;series&quot;:[{&quot;label&quot;:&quot;Softmax at this temperature&quot;,&quot;expr&quot;:&quot;exp(t/temp)/zsum&quot;},{&quot;label&quot;:&quot;Min-p cut-off&quot;,&quot;expr&quot;:&quot;minp*top&quot;,&quot;dash&quot;:true}],&quot;fit&quot;:{&quot;x&quot;:&quot;logit&quot;,&quot;y&quot;:&quot;p&quot;,&quot;label&quot;:&quot;Each candidate token&quot;}},&quot;steps&quot;:[{&quot;title&quot;:&quot;Divide by the temperature&quot;,&quot;text&quot;:&quot;Every logit is divided by T = {temp}. A small T stretches the gaps between scores; a large T shrinks them.&quot;,&quot;show&quot;:[]},{&quot;title&quot;:&quot;Exponentiate&quot;,&quot;text&quot;:&quot;exp makes every score positive and rewards the leader: the largest term is now {emax}.&quot;,&quot;show&quot;:[]},{&quot;title&quot;:&quot;Normalise&quot;,&quot;text&quot;:&quot;Dividing by Z = {zsum} makes the probabilities add up to 1. The top token gets {top:p}.&quot;,&quot;show&quot;:[&quot;zsum&quot;,&quot;top&quot;]},{&quot;title&quot;:&quot;Measure the spread&quot;,&quot;text&quot;:&quot;Entropy is {ent} nats, the same as choosing evenly among {ppl} tokens.&quot;,&quot;show&quot;:[&quot;ent&quot;,&quot;ppl&quot;]},{&quot;title&quot;:&quot;Apply min-p&quot;,&quot;text&quot;:&quot;Tokens below {minp} × the top probability are dropped: {kept} remain, carrying {mass:p} of the probability, which is then renormalised before sampling.&quot;,&quot;show&quot;:[&quot;kept&quot;,&quot;mass&quot;]}],&quot;level&quot;:&quot;intermediate&quot;,&quot;bars&quot;:{&quot;title&quot;:&quot;Probability of each candidate token&quot;,&quot;y&quot;:&quot;p&quot;,&quot;label&quot;:&quot;logit&quot;}}"><p>Interactive simulation. It needs JavaScript; the text below explains what it shows.</p></div>

## What you are looking at

The table lists eight candidate next tokens with their logits: the raw scores a language model's last layer produces. The orange columns show what happens to each one: its exponential at the current temperature, its probability, whether min-p keeps it, and its share of the entropy.

The chart draws the softmax curve: the probability any logit would get at this temperature. The orange rings are the eight candidates sitting on that curve. The dashed line is the min-p cut-off: tokens below it are dropped before sampling. The results panel gives the top token's probability, the entropy, the number of effective choices and how much probability min-p keeps.

## The algorithm

Softmax turns scores into probabilities in three moves. First each logit is divided by the temperature T. Then each result is exponentiated, which makes every value positive and magnifies the gaps between them. Finally each value is divided by their sum Z, so the probabilities add up to one.

Temperature only changes the first move, but its effect is large. With T below 1 the gaps between logits grow, so the leader takes more of the probability; as T approaches 0 the model always picks the top token, which is greedy decoding. With T above 1 the gaps shrink and the distribution flattens towards uniform, so unlikely tokens are sampled more often.

Entropy, the sum of −p × ln p, measures how spread out the choice is. Its exponential, the perplexity, reads as the number of equally likely tokens that would give the same uncertainty: 1 means the model is certain, 8 here would mean it cannot tell the candidates apart.

Min-p sampling then removes the tail: it keeps only tokens whose probability is at least min-p times the top token's, renormalises what is left and samples from it. Because the cut-off scales with the top probability, it keeps many options when the model is unsure and few when it is confident. That is the difference from top-p, which keeps a fixed share of total probability.

The bar chart under the curve shows the same eight probabilities side by side, with the most likely token highlighted. Watching the bars is often the quickest way to feel what a temperature does: at 0.3 one bar towers over the rest, at 2 they level out.

## Things to try

- Slide the temperature down to 0.1: the top token takes almost all the probability and the effective choices fall towards 1.
- Raise it to 3: the curve flattens, entropy rises and min-p keeps nearly every token.
- Set min-p to 0.3 at temperature 1 and then at 2. The number of kept tokens grows with the temperature, which is the behaviour min-p was designed for.
- Make two logits equal: they always get equal probability, whatever the temperature.
- Paste logits from a real model's output to see its own distribution.

## How it works in real systems

Every chat model samples its reply token by token this way. Serving engines such as vLLM and llama.cpp apply the steps in a fixed order: penalties and logit biases first, then temperature, then truncation filters such as top-k, top-p or min-p, then a random draw. Reasoning and coding tasks often use low temperatures for stable answers, while creative writing uses higher ones with min-p or top-p to avoid incoherent tails.

Temperature also appears in training. Knowledge distillation softens a teacher model's probabilities with a temperature above 1 so the student learns how the teacher ranks the wrong answers too, not just the right one.

## Sources

- [Nguyen et al.: Turning Up the Heat: Min-p Sampling for Creative and Coherent LLM Outputs (arXiv)](https://arxiv.org/abs/2407.01082)
- [Hinton, Vinyals and Dean: Distilling the Knowledge in a Neural Network (arXiv)](https://arxiv.org/abs/1503.02531)
- [Holtzman et al.: The Curious Case of Neural Text Degeneration (arXiv)](https://arxiv.org/abs/1904.09751)
- [Wikipedia: Softmax function](https://en.wikipedia.org/wiki/Softmax_function)
