Kolkata ·  
AI engineering
foundations
short · 3 min

Softmax

Turns the model's raw scores into probabilities that add up to 1.

updated 23 Sept 2026

Say a model has just read "I want to" and has to pick the next word. Let's pretend it only knows three words, and it has given each one a score: "learn" gets 3, "predict" gets 2, "make" gets 1.

We want to pick one at random, weighted by how good each is. So what's the chance of "learn"? We can't say from these numbers. They don't add up to anything in particular, and they could just as easily have been 7.2, 0.3 and −4.1. Negative scores are normal. You can't draw a word "with 30% chance" from a list like that. We need numbers that are all positive and add up to 1.

These raw scores are called logits. A real model makes one for every token in its vocabulary at every step. For GPT-3 that was 50,257 of them. Softmax is the small function that turns them into probabilities.

Two moves

First, raise e to the power of each score. e to any power is positive, so a negative score just becomes a small positive number, and bigger scores stay bigger. Then divide each result by the total of all of them. Now they add up to 1.

Here's our example, worked through:

WordLogitelogite^{\text{logit}}÷ total (30.19)
learn320.090.665
predict27.390.245
make12.720.090

Written as a formula, for scores o1,o2,…,ono_1, o_2, \ldots, o_n:

softmax(o)i=eoieo1+eo2+⋯+eon\text{softmax}(o)_i = \frac{e^{o_i}}{e^{o_1} + e^{o_2} + \cdots + e^{o_n}}

What it did to our scores

Look at the table again. The order didn't change: the top score is still the top probability. That's always true, so if all you want is the single most likely token, you can skip softmax and take the biggest logit.

But the gaps changed. "learn" was one point ahead of "predict", and it ended up with almost three times the probability. Raising e to the power favours whoever is ahead.

Now try adding 10 to every score: 13, 12, 11. You might expect "learn" to look even surer. It doesn't. You get exactly the same 0.665, 0.245 and 0.090. Only the differences between scores count. Double the gaps (6, 4, 2) and "learn" jumps to 0.867. Halve them (1.5, 1, 0.5) and it drops to 0.506.

That's all temperature is. It divides every logit by one number before softmax runs, which pulls the scores apart or pushes them together. (The name comes from physics. Boltzmann and Gibbs used the same exponential to describe how likely a gas is to be in each energy state, with a temperature in the formula.)

Two things to watch for

Nothing ever comes out as exactly 0. e to any finite power is above zero, so every token in the vocabulary keeps some tiny chance. To get exactly 1, a score would have to be infinite. That long tail of tiny chances is why picking purely at random can go off the rails, which is what sampling is about.

And e to a big number is too big for a computer to store. Deep learning libraries handle that for you. You'd only run into it writing softmax by hand.

One more thing, more about how we read the output than the math. Softmax always hands back a neat distribution, even when the model has no good idea what comes next. A 0.665 for "learn" says the model preferred "learn" here. It doesn't say "learn" is right.

So the next time an API shows you token probabilities, or their logs as logprobs, you're looking at the far end of these two moves, for every token the model could have picked.

Further reading

  • Softmax Regression, Zhang, Lipton, Li and Smola, Dive into Deep Learning, 2023. The textbook version, with the formula and the physics history. Do the temperature exercises at the end.
  • Transformers, the tech behind LLMs, 3Blue1Brown, 2024. Shows where softmax sits in a real LLM, at the very end, turning 50,000 scores into the next-token probabilities.