Confidence Calibration of Classifiers with Many Classes

Adrien LeCoz, Stéphane Herbin, Faouzi Adjed

TL;DR

Deep neural networks often output unreliable confidence scores, and standard post-processing calibration methods break down when a model has hundreds or thousands of classes. This paper introduces Top-versus-All (TvA), a remarkably simple yet effective reformulation that collapses multiclass confidence calibration into a single binary problem: "Is the top prediction correct?" By avoiding the data imbalance and overfitting issues of traditional approaches, TvA drastically reduces calibration error across massive vision and language models while preserving classification accuracy.

What Problem Does This Paper Address?

Modern deep neural networks (DNNs) are frequently deployed in safety-critical applications like autonomous driving or medical diagnostics, where knowing when a model is uncertain is just as important as its raw accuracy. Typically, the maximum softmax probability is treated as a confidence score. However, DNNs are notoriously miscalibrated—often exhibiting extreme overconfidence.

To fix this, researchers use post-hoc calibration methods (like Temperature Scaling or Histogram Binning) on a separate validation set. Unfortunately, these methods fail when scaling to problems with many classes (e.g., ImageNet's 1,000 classes or ImageNet-21K's 10,000+ classes) due to two main issues:

  1. Overfitting in Scaling Methods: Expressive methods like Vector Scaling or Dirichlet Calibration introduce parameters that grow with the number of classes, causing them to overfit small calibration datasets.
  2. Data Imbalance in Binary Methods: Adapting binary calibration methods to multiclass settings usually relies on a One-versus-All (OvA) approach. For a 1,000-class problem, this splits the data into subsets with a grueling 1:999 positive-to-negative ratio, leaving far too few positive examples to reliably learn a calibrator. Furthermore, calibrating each class independently can alter the final probability rankings, inadvertently degrading the model's original accuracy.

Methods

The core innovation of this paper is the Top-versus-All (TvA) framework. Instead of trying to calibrate the entire probability vector or splitting the task into $L$ separate class-wise problems, TvA reframes calibration around a single question: Is the predicted class correct?

Multiclass Output Vector  -->  [Max Operator]  -->  Confidence Score (s)
                                                            |
                                                            v
                                                Surrogate Binary Classifier 
                                              "Is this top prediction correct?"
                                                    (1 = Yes, 0 = No)

For any standard calibration dataset $D_{cal} = \{(xi, yi)\}$, TvA applies a quick preprocessing step:

  1. It computes the model's top prediction $\hat{y}_i$ and its confidence score $s_i = \max_k f_k(x_i)$.
  2. It creates a binary label $y^b_i$, which is $1$ if the prediction is correct ($\hat{y}_i = y_i$) and $0$ otherwise.

This transforms the calibration set into a binary dataset $D^{TvA}_{cal} = \{(x_i, y^b_i)\}$. Standard calibration algorithms can then be trained directly on this binary surrogate problem using Binary Cross-Entropy (BCE) loss:

$$\ell_{BCE} = - [y^b \cdot \log s + (1 - y^b) \cdot \log(1 - s)]$$

Additionally, the authors introduce a simple $L_2$ regularization term for Vector Scaling and Dirichlet Calibration to penalize coefficients that drift too far from 1, effectively neutralizing the overfitting problem in high-class dimensions.

Datasets

The authors extensively evaluated TvA across both computer vision and natural language processing domains using:

  • Image Classification: CIFAR-10, CIFAR-100, ImageNet (1,000 classes), and ImageNet-21K (10,450 classes).
  • Text Classification: Amazon Fine Foods, DynaSent, MNLI, and Yahoo Answers.
  • Models Evaluated: ResNet, Wide-ResNet, DenseNet, MobileNetV3, ViT, ConvNeXt, EfficientNet, Swin, CLIP, RoBERTa, T5, GPT-J, and Llama-2.

Key Insights and Ideas

  • Direct vs. Indirect Penalization: In standard multiclass cross-entropy, minimizing the loss on an incorrect prediction attempts to raise the probability of the true class. It only indirectly lowers the confidence of the wrong top prediction via softmax normalization. TvA’s binary cross-entropy directly targets the top prediction, generating significantly stronger gradients to suppress false confidence.
  • Fixing the Imbalance: By grouping all correct predictions together and all incorrect predictions together, TvA yields a vastly better-balanced calibration set. For an ImageNet model with 80% accuracy, the positive-to-negative ratio becomes 4:1 instead of the catastrophic 1:999 ratio seen in One-versus-All setups.
  • Accuracy Preservation: Because TvA only scales the confidence score after the top prediction has already been decided, it is mathematically impossible for binary methods like Histogram Binning to alter the class rankings. This completely decouples calibration from accuracy optimization.

Key Results

TvA consistently and significantly outperforms standard calibration baselines across almost all model families and datasets.

As shown in the comprehensive results table below, applying the TvA framework (denoted by the $\text{TvA}$ subscript) dramatically lowers the Expected Calibration Error (ECE):

Table 1: ECE in % (lower is better). The subscript TvA denotes that our reformulation was applied to the calibration method. IRM and I-Max are competing methods. The best method for a given model is in bold. Methods in purple impact the model prediction, potentially degrading accuracy; methods in teal do not. Values are averaged over five random seeds. Results are averaged over models of the same family. Detailed results for all models can be seen in Tables 5 and 6 of the Appendix.

Key Quantitative Takeaways:

  • Histogram Binning Excellence: Histogram Binning combined with TvA ($HB_{TvA}$) emerged as the absolute best calibration method overall, frequently driving the ECE below 1% (e.g., dropping ImageNet ResNet ECE from an uncalibrated 15.26% down to 0.55%).
  • Mitigating Overfitting: On ImageNet-21K (10,450 classes), standard implementations of competing methods like I-Max and IRM suffered from out-of-memory errors or severe degradation. TvA handled this massive scale effortlessly.
  • Reliability Diagrams: Qualitative improvements are highly visible in reliability diagrams, where TvA shifts the average confidence line to perfectly align with global accuracy.
Figure 1: Reliability diagrams for ResNet-50 and ViT-B/16 when using Temperature Scaling (TS), Vector Scaling (VS), and Histogram Binning (HB) on ImageNet. The subscript TvA signifies that the TvA reformulation was used, and reg means our regularization (6) was applied. Red bars show the differences between bin accuracy (blue bar) and accuracy for perfect calibration (dashed red line). As the methods improve the calibration, these differences are reduced and the average confidence (vertical dotted line) will get closer to the global accuracy (vertical dashed line).

Limitations and Future Work

While TvA is highly effective for optimizing confidence calibration (the accuracy of the top predicted class), it does not calibrate the entire probability vector (i.e., it doesn't guarantee that the 2nd or 3rd most likely classes have accurate probabilities). Therefore, it is less suited for tasks requiring strict class-wise calibration.

Additionally, the authors note that the magnitude of improvement is less pronounced for simple problems with very few classes ($\le 10$), where standard calibration methods don't suffer as severely from data sparsity or parameter explosion. Future work could explore extending this binary surrogate mapping to multi-label classification or out-of-distribution detection settings.

Summary updated

Abstract

For classification models based on neural networks, the maximum predicted class probability is often used as a confidence score. This score rarely predicts well the probability of making a correct prediction and requires a post-processing calibration step. However, many confidence calibration methods fail for problems with many classes. To address this issue, we transform the problem of calibrating a multiclass classifier into calibrating a single surrogate binary classifier. This approach allows for more efficient use of standard calibration methods. We evaluate our approach on numerous neural networks used for image or text classification and show that it significantly enhances existing calibration methods.
BibTeX
@inproceedings{lecoz2024confidence,
  author = {Adrien LeCoz and Stéphane Herbin and Faouzi Adjed},
  title = {{Confidence Calibration of Classifiers with Many Classes}},
  booktitle = {Advances in Neural Information Processing Systems},
  year = {2024},
  url = {https://openreview.net/forum?id=ebBnKVxMcZ},
}
Figure