Abstract
The reliable measurement of confidence in classifiers' predictions is very important for many applications and is, therefore, an important part of classifier design. Yet, although deep learning has received tremendous attention in recent years, not much progress has been made in quantifying the prediction confidence of neural network classifiers. Bayesian models offer a mathematically grounded framework to reason about model uncertainty, but usually come with prohibitive computational costs. In this paper we propose a simple, scalable method to achieve a reliable confidence score, based on the data embedding derived from the penultimate layer of the network. We investigate two ways to achieve desirable embeddings, by using either a distance-based loss or Adversarial Training. We then test the benefits of our method when used for classification error prediction, weighting an ensemble of classifiers, and novelty detection. In all tasks we show significant improvement over traditional, commonly used confidence scores.
Introduction
Deep neural networks are state-of-the-art classifiers, yet they are notoriously "overconfident." A standard network often assigns high probability to a prediction even when the input is significantly different from the training data. The industry standard for measuring confidence is the Softmax score (the maximum value of the output layer), which measures relative class strength rather than absolute certainty. While Bayesian neural networks provide a principled approach to uncertainty, their computational cost makes them difficult to scale. This research introduces a "Distance Score"—a scalable alternative that bridges the gap between standard networks and complex probabilistic models.
Methodology: The Distance-Based Approach
The proposed Distance Score shifts the focus from the output layer to the penultimate layer, or the embedding space.
The Distance Score
For a new test point, the network calculates its embedding and identifies its $k$-nearest neighbors ($k$-NN) in the training set using Euclidean distance. The confidence score is defined as the ratio of the density of neighbors sharing the predicted label to the total density of all $k$ neighbors.
Optimizing the Embedding Space
To maximize the effectiveness of this score, the embedding space must be well-structured, with same-class points tightly clustered. The authors explore two techniques to enforce this structure:
- Distance-based Loss: A penalty term minimizes distances between same-class pairs while enforcing a minimum margin between different-class pairs.
- Adversarial Training: By training on small, intentional perturbations, the network naturally improves the density and separation of the embedding space, acting as an effective regularizer.
Experimental Evaluation
The method was evaluated on CIFAR-100, STL-10, and SVHN benchmarks. Performance was primarily measured using the Area Under the ROC Curve (AUC) for predicting classification correctness.
Error Prediction
The Distance Score consistently outperformed traditional metrics. On CIFAR-100, it achieved an AUC of 0.853, significantly higher than standard Entropy (0.833) and MC-Dropout (0.726).
Ensembling and Novelty Detection
When combining multiple models into an ensemble, weighting votes by the Distance Score yielded higher accuracy than simple averaging. Furthermore, the score proved highly effective at novelty detection—flagging samples from unseen classes—especially when combined with Adversarial Training.
Discussion and Key Insights
A primary takeaway is that the penultimate layer contains rich semantic information that the final Softmax layer often discards. By analyzing a point's position relative to the training data, we can distinguish between "guessing" and "recognizing."
While $k$-NN approaches are often criticized for speed, the authors demonstrate that modern GPU acceleration and data reduction techniques (like Condensed Nearest Neighbors) make the overhead manageable, often less than the forward pass of a large ResNet.
Limitations
Despite its advantages, the method requires maintaining a representation of the training data at test time, which may pose challenges for memory-constrained edge devices. Additionally, the choice of $k$ and the margin $m$ in the loss function introduce additional hyperparameters that require tuning.
Conclusion
The Distance Score provides a simple yet powerful tool for quantifying neural network confidence. By leveraging the structure of the embedding space, it offers significant improvements in error prediction, ensemble performance, and novelty detection over standard softmax-based metrics.
Summary updated