Lab

Softmax

Softmax: A function that turns a list of numbers into probabilities that add up to 1, by exponentiating each one and dividing by the total.

Softmax takes a list of numbers of any size and sign and turns it into a list of probabilities. It raises e to the power of each number, then divides each result by the sum of them all. Every output is positive, and together they add up to 1.

The exponent gives softmax its character. Adding the same amount to every input changes nothing, so only the gaps between inputs matter. And a gap becomes a ratio: if one input is larger than another by a fixed amount, its probability is larger by a fixed factor. Big gaps produce one clear winner; small gaps produce a close race.

Language models use softmax in two places. At the output, it turns the model’s logits into the probabilities a sampler chooses from. Inside every attention layer, it turns attention scores into weights that decide how much each earlier token contributes.

Temperature works through softmax. Dividing every logit by a temperature T before softmax stretches the gaps when T is small and squashes them when T is large. As T approaches 0, all the probability goes to the top token, which is greedy decoding. As T grows very large, every token approaches the same probability.

In code, softmax subtracts the largest input before exponentiating. The answer is the same, but very large inputs no longer overflow. The explainer shows the formula with temperature and lets you watch the curve change as you move it.

See it working

Explore it in How a model picks the next token

See how temperature, top-k, top-p, min-p and penalties turn a model's logits into one token, and why their order matters.

Open the explainer