Softmax: how numbers become probabilities and what temperature is
Softmax is a formula that turns a heap of arbitrary numbers into probabilities. A language model, such as the one in ChatGPT, builds text out of tokens, pieces of words, as the first part of the series How artificial intelligence computes showed. The next token is suggested by a neural network, a huge calculation that turns numbers into more numbers. It is explained in the second part, but you do not need to know it here. At the end, though, it does not hand out probabilities directly, but a score (called logits) for every token it knows: the higher the score, the better the token would fit as the next one. Scores can be positive or negative and they do not add up to one, so they are not probabilities. Softmax converts them by making every score positive, favouring larger scores even more, and dividing everything by the total, so that the result adds up to one. The model then draws the next token according to the resulting probabilities, and the temperature decides how boldly.
To keep things simple, from here on we will work with whole words instead of tokens. The network calculates the scores from the text so far: the better a word fitted such a beginning in the texts the network learned from, the higher the score it gives it.
The softmax formula
We will use the sentence “The cat sat on the” and three candidates to continue it. A real model would have a score for each of the roughly 200,000 tokens in its vocabulary, but three will do for us:
| word | mat | sofa | floor |
|---|---|---|---|
| score x | 2 | 1 | 0 |
If you are only after the formula, the probability of the i-th word is
where e ≈ 2.718 is Euler’s number. The index i is just the position of the word: x1 is the score of “mat”, x2 the score of “sofa” and p1 the probability of “mat”. The capital Greek sigma
The power ex is nothing to be afraid of: e1 is just e, e0 = 1 as for any number, and e2 = e · e. For non-integer scores, such as e0.5, a calculator does the job.
Now with the numbers. First the powers:
We add them up:
And we divide each power by the total:
| word | mat | sofa | floor |
|---|---|---|---|
| score x | 2 | 1 | 0 |
| ex | 7.39 | 2.72 | 1 |
| probability p | 0.67 | 0.24 | 0.09 |
So after “The cat sat on the”, the model gives the word “mat” a probability of about 67%, “sofa” 24% and “floor” 9%. We can check that 0.67 + 0.24 + 0.09 = 1. That is no coincidence: every power also appears in the denominator, so the fractions add up to the total divided by the same total, which is exactly one. It holds for any scores and any number of words.
Why the exponential?
It is tempting to try a simpler idea: why not just divide the scores by their sum? Let’s try it on three sets of scores:
- 2, 1 and 0: we get
, and 0. The word “floor” would never be chosen, even though it only lags a little behind. - 2, 1 and −1: the sum is 2, so we get 1, 0.5 and −0.5. A negative probability is nonsense, and “mat” would be a certainty even though it has competition.
- 2, 1 and −3: the sum is zero and we cannot divide at all.
And negative scores are an everyday matter for a network.
The exponential function ex copes with all three problems thanks to these properties:
- it is always positive, even for negative x: e−1 ≈ 0.37. Every word therefore gets some chance, however small. For the scores 2, 1 and −1, softmax gives 0.705, 0.259 and 0.035,
- it is increasing, so it preserves the order: a higher score always means a higher probability,
- a difference of scores turns into a ratio. Since ex + 1 = e · ex, adding one to a score is the same as multiplying the power by e. If one word has a score 1 higher than another, it is e ≈ 2.72 times as likely. In our table 7.39:2.72 ≈ 2.72 and 2.72:1 = 2.72, and the probabilities keep the same ratio, because we divided them all by the same number. A difference of 2 means a ratio of e2 ≈ 7.4.
It also follows that only the differences between scores matter. If we added ten to all three, we would get 12, 11 and 10, but every power would be multiplied by the same number e10, which cancels in the fraction. The probabilities do not budge.
Instead of e we could raise, say, 2 to the powers. Only the scale would change, as if we had multiplied all the scores by the same number. We prefer e because it gives the simplest derivative, and that is what the network’s learning needs.
And where does the name come from? If the model always picked just the word with the highest score, it would be a plain maximum: “mat” one, the others zero. Softmax turns it into a softer version: the highest score wins, but the others do not drop out of the game entirely.
Temperature: sharpen or blur
The formula has one more knob, a number called the temperature T. Before exponentiating, we divide all the scores by it:
With T = 1 we get the ordinary softmax, as we calculated it above. Dividing by a small number magnifies the differences between the scores, dividing by a large one shrinks them. For T = 0.25 the scores 2, 1 and 0 become 8, 4 and 0, so neighbouring scores no longer differ by one but by four. With T = 4, on the other hand, they shrink to 0.5, 0.25 and 0. The calculation then goes on as before. For T = 0.25 we exponentiate:
The total is about 3,037, so:
We work out the rest of the table in the same way:
| temperature | mat | sofa | floor |
|---|---|---|---|
| T = 0.25 | 0.98 | 0.02 | 0.0003 |
| T = 1 | 0.67 | 0.24 | 0.09 |
| T = 4 | 0.42 | 0.33 | 0.25 |
At a low temperature the model will almost certainly write “mat”. The closer T is to zero, the more softmax resembles a plain maximum. A temperature of exactly zero cannot be plugged in, as we would be dividing by zero, so programs usually interpret T = 0 precisely like this: take the word with the highest score. A high temperature, on the other hand, evens out the probabilities; if T grew beyond all bounds, each candidate would get the same third.
The temperature is chosen by whoever runs the model or calls it from their own program, so for an ordinary user of the ChatGPT app it has been picked by the operator. Developers can choose it: for example, OpenAI in its API, the interface through which other programs call the models, allows a temperature from 0 to 2 with a default of 1, but for the newest models, which “think” before answering, it cannot be set (according to the documentation as of 6 December 2026). A low temperature is useful when we want an answer that is reliable and as consistent as possible, a higher one when we want ideas and variety. But if we overdo it, words that do not belong at all start to appear and the text falls apart into nonsense.
Why does ChatGPT answer differently every time?
Probabilities alone do not choose any word. The model draws one of the candidates at random, as if rolling a loaded die: with T = 1, out of a hundred repetitions of the sentence “The cat sat on the” it would continue with “mat” roughly sixty-seven times, with “sofa” twenty-four times and with “floor” nine times.
The draw is made anew for every word. Once “floor” comes up instead of “mat”, the sentence continues differently, the next draws build on a different beginning, and within a few sentences you have a completely different answer. That is why you usually do not get the same text twice for the same question, even if you touch nothing in the app. The way you phrase the question matters too: a different beginning of the text means different scores for the network, and therefore different probabilities. This is not a bug but a deliberate choice: if the model always took only the most probable word, it would often sound mechanical and repeat the same turns of phrase over and over.
Entropy: how sure the model is
This section and the last one are for the curious. If all you wanted to know is how the model chooses words and what the temperature does, you are done.
The table with temperatures shows that sometimes the model is almost certain and sometimes it hesitates. This uncertainty can be measured with a single number, the entropy:
It is measured in bits, and log2 is the logarithm to base 2. We can think of −log2 p as a measure of surprise: an event with probability
Logarithms of numbers smaller than one are negative. The minus in front of the sum flips their sign, so the entropy comes out positive and it is enough to multiply the logarithms without the minus by the probabilities:
We multiply and add up:
The model’s uncertainty is therefore about 1.2 bits. It hesitates here roughly as if it were choosing among two or three equally probable words, because 21.2 ≈ 2.3. For comparison, two extreme cases:
- complete certainty: one word has probability 1, the others zero. Since log2 1 = 0, the entropy is 0 bits. Zero probabilities are not counted, they add no uncertainty.
- three equally probable words:
1.58 bits. With three words we cannot get any higher.
| temperature | T = 0.25 | T = 1 | T = 4 |
|---|---|---|---|
| entropy H | 0.13 bits | 1.20 bits | 1.56 bits |
As the temperature rises, the entropy approaches the maximum of 1.58 bits, and as it falls, zero. For a real model choosing from 200,000 tokens, the maximum would be log2,200,000 ≈ 17.6 bits. After “The cat sat on the”, though, it is nowhere near such a ceiling, as there are only a few dozen sensible continuations. After “My favourite food is”, on the other hand, it shoots up, because the model has no way of knowing what you like.
The loss is minus the logarithm
From the part on gradient descent we know that a network learns by reducing its loss, and that the loss of a language model grows the smaller the probability it gave to the word that really followed in the text. Now we have the formula for it. If the model gave the correct word a probability p, the loss is
If the real text had the word “mat” after “The cat sat on the”, the loss comes out as −log2 0.665 ≈ 0.59. If it had “floor”, the loss is −log2 0.090 ≈ 3.47, almost six times larger. And if the model gave the correct word a certainty of 1, the loss would be zero. Why a logarithm and not, say, 1 − p? The logarithm punishes a confident mistake harshly: as p approaches zero, the loss grows beyond all bounds, whereas 1 − p would never exceed one. Averaged over all the words in the text, this loss is called the cross-entropy. In practice the natural logarithm ln is used instead of log2, which merely changes the units, and gradient descent then shifts the weights so that the scores of the correct words grow.
Softmax, however, does not sit in the network only at the end. Inside a language model it also decides which words in a sentence the model should pay attention to when it looks for what “it” refers to. That is the subject of the part on transformer and attention. And why a high probability does not yet mean truth is explained in the part on AI hallucinations.
Chapters: How ChatGPT and artificial intelligence work: the maths inside, Neural network: what it is and how it computes, Gradient descent: how a neural network learns, Softmax: how numbers become probabilities and what temperature is, Transformer and attention: how a model knows what a word refers to, AI hallucination: why artificial intelligence confidently writes falsehoods