Applied AI Vol. 1

Temperature Scaling: A One-Parameter Fix for Overconfident Models

Divide the logits by a single number fitted on held-out data. It leaves predictions unchanged and often improves calibration.

Applied AI Vol. 1 · 4 min read

Many classifiers produce probabilities that are too extreme. Temperature scaling is the simplest widely used repair, and it comes with a clear reason it works.

How it works

A classifier’s final layer produces logits, and a softmax turns them into probabilities. Temperature scaling divides every logit by a single positive number T before the softmax. When T is greater than one, the probabilities become less extreme. When T is less than one, they sharpen.

Because dividing all logits by the same positive number does not change which one is largest, the predicted class, and so the accuracy, stay exactly the same.

Fitting T

Choose T to minimize the negative log-likelihood on a held-out calibration set. It is a one-dimensional, smooth problem, so a simple search or a few gradient steps will do. With one parameter, overfitting the calibration set is much less of a worry than with richer methods.

What it cannot fix

  • If the model is miscalibrated differently for different groups or regions, one global T cannot fix both.
  • It does not improve ranking quality, because ranking is unchanged for the top class.
  • If the deployment data shift, T fitted earlier may not fit now. Re-check calibration periodically.

A good habit

Report the before and after reliability diagram on data not used to fit T, along with the learned value. A T well away from one is itself a useful diagnostic: it tells you the original training objective left the model confident in ways the data did not support.

More guides from this book