TL;DR
In 2017 Chuan Guo and three co-authors reported that modern deep networks, unlike those from a decade earlier, are systematically overconfident: when they say 90 percent, they are right far less often than 90 percent of the time. They showed that greater depth and width, Batch Normalization and weaker weight decay are associated with this, and that a single learned number, a temperature that divides the network's logits before the softmax, repairs most of the problem without changing a single predicted class.
Builds on: Model Calibration, Softmax Temperature, Cross-Entropy Loss, Maximum Likelihood Estimation · Leads to: Simple and Scalable Predictive Uncertainty Estimation using Deep Ensembles (a different fix for the same problem)
Why it mattered
The paper made calibration a routine check for deployed classifiers. Its temperature scaling method is a few lines in a deep learning framework: one scalar is fitted on a validation set, and the logits are divided by it at test time. It has more than 14,000 citations on OpenAlex, which is a rough measure of how widely the question of confidence has been taken up.
The stakes are concrete. The authors open with a self-driving car whose detection network should hand control to other sensors when it is unsure, and with a diagnosis network that should pass a case to a doctor when its confidence is low. Both policies only work if the confidence number means what it says. A network that reports 0.99 when it is right 80 percent of the time sends the wrong signal to whatever sits downstream of it.
The history is short. In 2005 Niculescu-Mizil and Caruana found that neural networks of that time were usually well calibrated on binary tasks. Their reliability diagrams and the earlier work of DeGroot and Fienberg set the vocabulary this paper uses. Guo and colleagues asked whether the networks of 2017, trained with newer methods, still had that property. They did not.
The problem
A classifier outputs a predicted class and a confidence. The confidence should be calibrated: among all the predictions that carry confidence p, a fraction close to p should be correct. The paper's Figure 1 shows the failure. A 5-layer LeNet on CIFAR-100 has average confidence that matches its accuracy. A 110-layer ResNet on the same data has average confidence well above its accuracy. The reliability diagram, which plots accuracy against confidence for bins of predictions, shows the LeNet bars close to the diagonal and the ResNet bars sitting below it.
The ideas the paper needs from the prerequisites are these. Calibration is the property defined in Model Calibration. The network's raw scores are logits, and the softmax in Softmax turns them into probabilities. Temperature, which appears in Softmax Temperature, rescales those logits. The fitting criterion is the negative log-likelihood, which is the same quantity as Cross-Entropy Loss, and fitting by it follows Maximum Likelihood Estimation.
How it works
The paper has two parts. Part one measures and explains miscalibration. Part two compares post-processing fixes, and the winning one is temperature scaling. Follow one tiny network through the fix.
- Train the network as usual. Suppose a three-class network has finished training on its training split. Its logits for one image are z = (2, 1, 0). These are raw scores, not probabilities.
- Turn the logits into probabilities with the softmax. Each logit is exponentiated and the results are divided by their sum. exp(2) is about 7.39, exp(1) is about 2.72 and exp(0) is 1. The sum is about 11.11. The probabilities are about 0.665, 0.245 and 0.090. The confidence is the largest of these, 0.665. Check: the three numbers add to 1.00.
- Measure miscalibration on held-out data. The paper uses a validation set that the network never trained on. Its predictions are binned by confidence, and in each bin the accuracy is compared with the average confidence. A bin where the network says about 0.66 but is right only half the time is a miscalibrated bin.
- Choose one number to fix it. Temperature scaling replaces z by z divided by T, where T is a positive scalar. The network's weights are not touched. T is picked on the validation set to minimise the negative log-likelihood.
- Apply the chosen T at test time. Suppose the validation set picks T = 2. Then z becomes (1, 0.5, 0). The exponentials are about 2.72, 1.65 and 1. Their sum is about 5.37. The new probabilities are about 0.506, 0.307 and 0.186. The confidence has dropped from 0.665 to 0.506, while the predicted class is still the first one, because dividing all logits by the same positive number cannot change which logit is largest.
Figure 2 in the paper shows the same pattern at scale. As depth, width or the amount of Batch Normalization increases, the expected calibration error goes up while accuracy improves. The plot below shows the effect of step 4 for a binary network with a single logit. The unscaled curve is steep; dividing by T = 2 pulls it toward one half.
- T = 1 (uncalibrated)
- T = 2 (scaled)
The whole method is short enough to draw:
flowchart LR A[Train network on training split] --> B[Get logits on validation split] B --> C[Find T that minimises validation NLL] C --> D[At test time divide logits by T] D --> E[Softmax gives calibrated confidence] D --> F[Argmax gives the same predicted class]
The math
A classifier is perfectly calibrated when, for every confidence value p in , the probability that its prediction is correct, given that its confidence is p, equals p. In symbols, .
This is the ideal in the paper's equation (1). It cannot be checked directly, because the confidence is continuous and each exact value of p is seen at most once. So the paper approximates it with bins.
Step 2 in symbols: softmax
For a logit vector with K entries, the softmax probability of class k is
The predicted class is , and the confidence is .
Step 3 in symbols: bins and the calibration gap
Split the interval from 0 to 1 into M bins of equal width. Let be the set of samples whose confidence falls in bin m. Their average accuracy and average confidence are
Here is 1 when the statement is true and 0 otherwise. The gap in bin m is the difference between these two averages. A perfectly calibrated model has zero gap in every bin.
The expected calibration error weights each gap by the share of samples in its bin, with n the total number of samples:
The maximum calibration error keeps only the worst bin:
The paper uses ECE as its main metric with M = 15 bins, and MCE in the supplement.
Worked by hand with M = 2 bins and n = 10 predictions: bin A holds 4 samples with confidence 0.4 and accuracy 0.25, so its gap is 0.15 with weight 0.4, contributing 0.06. Bin B holds 6 samples with average confidence 0.9 and accuracy 0.5, so its gap is 0.40 with weight 0.6, contributing 0.24. The ECE is , or 30 percent. The MCE is the largest single gap, 0.40. Most of the error sits in bin B, where the network is confident but right only half the time.
Step 4 in symbols: the negative log-likelihood
Given a probabilistic model and n validation samples, the negative log-likelihood is
The paper cites a standard result: in expectation this quantity is smallest when equals the true conditional distribution. That is why it is a sensible target for fitting a calibration parameter. Minimising it rewards a probability of the true class that is high, but not higher than the data support.
Step 4 in symbols: temperature scaling
Temperature scaling replaces the softmax input by with a single scalar :
Two limits explain the behaviour. As T grows without bound, every probability approaches , which is maximum uncertainty. As T approaches 0, the largest probability approaches 1. Because the division by T does not change the order of the logits, gives the same class for every T, so accuracy is unchanged. The paper notes that fitting T is a one-dimensional convex optimisation problem, and with a conjugate gradient solver the optimal temperature is found in about 10 iterations.
For the binary case with one logit z, the confidence for the positive class is , where is the logistic sigmoid from Logistic Regression. Equivalently, the scaled logit has log-odds , so dividing by T shrinks the log-odds of every prediction toward zero.
Results
The paper applies the methods to six image datasets and four document datasets. Its Table 1 reports ECE with M = 15 bins. Training uses 45,000 / 5,000 / 10,000 CIFAR-100 images for train / validation / test, and the validation split is where each method is fitted.
- The 110-layer ResNet on CIFAR-100 has uncalibrated ECE of 16.53 percent. After temperature scaling it is 1.26 percent. The 152-layer ResNet on ImageNet goes from 5.48 percent to 1.86 percent.
- The ratio for the CIFAR-100 ResNet is . Temperature scaling cut the calibration error roughly thirteenfold, using one number fitted on 5,000 validation images.
- Histogram binning on the same network reaches 2.66 percent. Temperature scaling is better by about 1.4 points, which is roughly half the binning error.
- Matrix scaling, with one weight per entry of a 100 by 100 matrix, reaches 25.49 percent on the same network. More parameters overfit the small validation set.
- Interpretation: the miscalibration does not need many parameters to correct. It behaves like a single global overconfidence, and one temperature removes most of it. The paper's own summary is that network miscalibration is intrinsically low dimensional.
Try it: a binary network outputs logit for its positive class. Under temperature , what is the calibrated confidence , to three decimal places? Answer: , and .
The paper's other results point the same way. Vector scaling recovers essentially the same solution as temperature scaling, with nearly constant entries. Matrix scaling performs poorly on datasets with hundreds of classes and fails to converge on ImageNet. Binning methods improve calibration on most datasets but do not beat temperature scaling, and they can change class predictions. Temperature scaling does not calibrate Reuters, but Reuters starts with ECE below 1 percent, so there is little room to improve.
The limits matter. The paper's conclusions come from the models and datasets it tested, all trained with the authors' settings. ECE depends on the bin count and bin placement, so it is a summary rather than a complete description of calibration. The paper also says it cannot explain causally why depth and weight decay affect calibration; it reports association. Accuracy and calibration are separate properties: a more accurate network can be less calibrated, so each needs its own measurement.
Reading guide
The paper is short. Its sections map onto the lessons as follows.
- Section 1, Introduction: the motivation and the 2005 comparison. Needs Model Calibration and the "Why it mattered" section above.
- Section 2, Definitions: the calibration definition, reliability diagrams, ECE, MCE and NLL. Needs Model Calibration, Cross-Entropy Loss and Maximum Likelihood Estimation.
- Section 3, Observing miscalibration: model capacity, Batch Normalization, weight decay and NLL overfitting. Needs Batch Normalization, L2 Regularization and Overfitting.
- Section 4, Calibration methods: histogram binning, isotonic regression, BBQ, Platt scaling and the multiclass extensions. Needs Logistic Regression, Softmax and Softmax Temperature.
- Section 5, Results: Table 1 and the timing comparison. Needs only the definitions from Section 2.
- Section 6, Conclusion: the summary of the trends.
After this paper, read Simple and Scalable Predictive Uncertainty Estimation using Deep Ensembles for a different route to calibrated uncertainty, and Bayesian Neural Network for the probabilistic view of the weights that the paper contrasts with its method.
Check yourself
QuestionWhich quantity does the paper's ECE estimate, in words?Show answer
It estimates the average gap between confidence and accuracy, weighted across bins. Each bin's gap is the absolute difference between the fraction of correct predictions and the average confidence in that bin. The weights are the shares of the samples in each bin. It is a finite-sample approximation of the ideal that a prediction with confidence p is correct with probability p.
QuestionA network has logits (4, 0) for two classes. What is the top softmax probability with T = 1, and with T = 4? Give both to three decimal places.Show answer
With T = 1 the probability is . With T = 4 the scaled logits are , so the probability is . The temperature lowers the confidence and leaves the top class unchanged.
QuestionWhy does temperature scaling leave accuracy unchanged, while histogram binning can change it?Show answer
Temperature scaling divides every logit by the same positive number, so the logit with the largest value stays the largest, and the arg max prediction is preserved. Histogram binning replaces each confidence by a bin value, and bins are not guaranteed to preserve the ranking across classes, so the predicted class can change.
QuestionA team fits matrix scaling on a validation set of 2,000 images for a 1000-class problem. Why would you expect it to overfit, and what does the paper say about this case?Show answer
Matrix scaling has one weight per pair of classes, so for 1000 classes it has about a million parameters, far more than 2,000 images can constrain. The paper reports that matrix scaling fails to converge on the 1000-class ImageNet data, and that models with tens of thousands or more parameters overfit the small validation set. A single temperature has one parameter and avoids this problem.
QuestionA deployed system needs to decide when to hand a case to a human. The network is trained, and its calibration on new data is unknown. What would you do before trusting its confidence, and why?Show answer
Hold out a validation set drawn from the same distribution as the expected inputs, measure ECE and the reliability diagram on it, and if the calibration error is high, fit one temperature on that set by minimising the negative log-likelihood. Check ECE again on a separate test set. The reason is that the confidence threshold is only meaningful if the reported numbers match observed accuracy, and temperature scaling keeps accuracy while fixing the numbers.
Sources
- Guo, C., Pleiss, G., Sun, Y., & Weinberger, K. Q. (2017). On Calibration of Modern Neural Networks. arXiv:1706.04599. https://arxiv.org/abs/1706.04599
- DOI record for arXiv:1706.04599: https://doi.org/10.48550/arXiv.1706.04599