Answers · How models work
Why can't I fit temperature on the same data I trained the model on?
In shortBecause training predictions are already too confident, fitting temperature there confirms that confidence instead of correcting it.
You cannot fit temperature on the data the model trained on because the model is not overconfident there in the way it is on new data; it is usually already right and very sure. Fitting on that data minimises the same loss the model was trained on, and the minimum sits at a temperature of one or below, so the search confirms the overconfidence instead of repairing it.
Temperature is one positive number shared by every option. It divides every score before the softmax is applied. At equal to one nothing changes. Above one the gaps between scores shrink and the reported distribution flattens. Below one the gaps stretch and the reported distribution sharpens. The method is worth using because it is a single scalar and because division by a positive number cannot reorder the options, so no decision based on the top answer changes.
Take two options with scores 6 and 0, and let the first option be the correct one. At the first option gets probability , so the training loss for that example is . Raise to 2: the same lead becomes , and the loss rises to , about twenty times larger. Lower to 0.5: the lead becomes , and the loss falls to , about four hundred times smaller than at . On training cases that are already correct, softening the distribution only makes the loss worse.
| T | leader probability | training loss |
|---|---|---|
| 0.5 | 0.999994 | 0.00000614 |
| 1 | 0.99753 | 0.00248 |
| 2 | 0.95257 | 0.04859 |
| 4 | 0.81757 | 0.20141 |
Why the training fit goes the wrong way
The natural guess is to use the training labels because they are available and plentiful. That is exactly the problem. The model has already fitted those labels; its training predictions are optimistically overconfident. A temperature fitted there measures how well the model reproduces labels it has already seen, not how often it is right on inputs it has not seen. For a correct training example the model is already near probability 1, so any above one moves the probability away from 1 and increases the loss; any below one moves it closer to 1 and decreases the loss. The search therefore returns a temperature at or below one. That sharpens the distribution rather than softening it, which is the opposite of the repair an overconfident model needs.
The fit has to use data the model did not train on. On held-out examples some predictions are wrong, and softening a high-confidence mistake reduces the penalty enough to lower the total loss. That is the mechanism that can return a temperature above one when the model is systematically overconfident. The quantity being minimised is still the usual loss, the negative log probability assigned to the correct answer, but it is now measured on cases the model has not memorised. A temperature fitted on one distribution is only right for that distribution, so the held-out set should resemble the traffic the system actually serves.
If no held-out data exists, the answer is not to reuse the training set. A separate calibration split has to be carved out before fitting, or the fit has to be done by cross-validation. The training set can still train the model. It cannot also serve as the evidence that the numbers beside its answers are honest, because the model has already been rewarded for making those particular numbers large.
What one number cannot repair
The correction is uniform. It applies the same division to a question the model has seen a thousand variants of and to one from a subject that was not in the training data at all. If a model is well calibrated on English and wildly overconfident on Portuguese, one temperature will land somewhere between, making Portuguese somewhat better and English somewhat worse. If confidence is honest on common cases and absurd on rare ones, the same applies. Fitting separate temperatures per segment is the obvious response, and it works where the segments are known and each has enough held-out data to fit on. It also does nothing about uncertainty that comes from the model never having known the answer, or about confident invention where the scores are high and the answer does not exist.
The number is a property of the fitted model and the traffic it is scored on, not of the training set. A temperature that repairs the tilt on one distribution leaves the pattern on another distribution untouched.
Worth keeping
- Temperature is fitted by minimising loss on data the model did not train on; training loss rewards certainty and returns a temperature at or below one.
- Dividing every score by the same positive temperature cannot change the ranking of options, only the probabilities printed beside them.
- One temperature corrects a uniform tilt, not a pattern that differs by segment or by whether the model ever knew the answer.
Where this goes next
This question is one step of When a Model Is Sure and Wrong, a course that works through its subject from the beginning. The page that teaches this part of it is One Number That Fixes Most of It, and it reads the whole way through whether or not you have an account.
What an account changes is the practice: problems standing under every idea, marked with a reason rather than a tick, in a copy of the course that is yours.
Read that pageThe whole courseOther questions people ask about this
- Why can a completely made-up answer come with high confidence?Because the confidence score measures how likely the words are, and a fluent invention is built from likely words, not because the fact was checked.
- When a model says it is 90% sure, what is that 90% a probability of?It is the share of the model's score mass given to that option out of the options it was offered, not the chance that the answer is correct.
- Why doesn't temperature scaling change which answer the model picks?Temperature scaling changes how confident the model sounds, not which answer it ranks first, because dividing every score by the same positive number preserves their order.
- When should a model refuse to answer instead of guessing?Refuse when the chance of being wrong times the cost of an error is higher than the cost of handing the case to a person.
- Why does the model get stuck repeating the same sentence over and over?The model is not stuck in a memory loop: once it has written a phrase, that phrase is in its context and makes writing it again more likely, so a decoder that always picks the top word cannot leave.
- Why does diffusion add Gaussian noise instead of any random corruption?Diffusion adds Gaussian noise because Gaussian errors combine exactly: each step keeps the spread fixed and gives a closed-form noisy picture at any later step, which makes the reverse step learnable.