Density-Softmax: Scalable and Distance-Aware Uncertainty Estimation under Distribution Shifts

Ha Manh Bui, Anqi Liu

Abstract

Sampling-based methods, e.g., Deep Ensembles and Bayesian Neural Nets have become promising approaches to improve the quality of uncertainty estimation and robust generalization. However, they suffer from a large model size and high latency at test-time, which limits the scalability needed for low-resource devices and real-time applications. To resolve these computational issues, we propose Density-Softmax, a sampling-free deterministic framework via combining a density function built on a Lipschitz-constrained feature extractor with the softmax layer. Theoretically, we show that our model is the solution of minimax uncertainty risk and is distance-aware on feature space, thus reducing the over-confidence of the standard softmax under distribution shifts. Empirically, our method enjoys competitive results with state-of-the-art techniques in terms of uncertainty and robustness, while having a lower number of model parameters and a lower latency at test-time.

Introduction

Deep Neural Networks (DNNs) are notoriously "overconfident"—they often provide high-certainty predictions even when the input data is far from what they saw during training (Out-of-Distribution or OOD data). In high-stakes fields like healthcare or autonomous driving, a model needs to "fail gracefully" by signaling high uncertainty when it's unsure.

Current solutions generally fall into two camps: sampling-based methods (e.g., Deep Ensembles), which are reliable but computationally heavy, and deterministic methods, which are fast but often struggle with calibration under distribution shifts. Density-Softmax bridges this gap by creating a model that is as fast as a standard deterministic network but as reliable as a complex ensemble.

The Density-Softmax Framework

The proposed framework consists of three integrated components designed to provide distance-aware uncertainty in a single forward pass.

Architecture of the Density-Softmax framework showing the flow from input X to output Y via feature extractor F, density model p(Z; alpha), and a density-scaled softmax.
  1. Lipschitz-Constrained Feature Extractor ($f$): Using gradient-penalty regularization, the model ensures the feature extractor is "1-Lipschitz." This ensures that distance in the feature space is semantically meaningful and prevents the model from being overly sensitive to noise.
  2. Normalizing-Flows Density Model ($p(Z; \alpha)$): A lightweight model estimates the probability density of the features ($Z$) learned by the extractor. If a test point lands in a "sparse" area of the feature space (far from training data), the density value will be low.
  3. Density-Scaled Softmax: Unlike a standard softmax, Density-Softmax scales the logit vectors by the feature density before the final exponentiation. When the model encounters OOD data, the density $p(Z; \alpha)$ drops toward zero, effectively "flattening" the softmax output and forcing the model to output a uniform distribution (maximum uncertainty).

Distance Awareness and Visualizing Uncertainty

A major insight of this work is that density estimation alone isn't enough; the Lipschitz constraint is required to preserve the geometry needed for the density model to work. The paper proves theoretically that Density-Softmax is "distance-aware," meaning its uncertainty metrics are monotonic functions of the distance between a test point and the training set in the feature space.

Comparison of class probability and predictive uncertainty on a toy dataset. Density-Softmax (right) shows superior distance awareness by increasing uncertainty in regions far from training data.

As visualized in Figure 1, standard methods like ERM or even MC Dropout remain confident in regions far from the data clusters. In contrast, Density-Softmax correctly identifies these regions as highly uncertain (indicated by the yellow regions in the bottom-right plot).

Empirical Results

The researchers evaluated the model across a wide range of benchmarks including CIFAR-10/100 and ImageNet, as well as their corrupted versions (CIFAR-10-C, etc.) to test robustness under distribution shifts.

  • Speed & Efficiency: On ImageNet (ResNet-50), Density-Softmax has a latency of ~300ms/sample, nearly identical to a standard deterministic model, while Deep Ensembles take ~700ms. It uses ~26M parameters compared to the ~102M required by ensembles.
  • Calibration: On corrupted data (CIFAR-10-C), it achieved an Expected Calibration Error (ECE) of 0.060, significantly outperforming standard ERM (0.153) and even beating SNGP (0.078).
  • Robustness: It achieved the highest accuracy on several shifted datasets, such as 79.2% on CIFAR-10-C, rivaling Deep Ensembles while maintaining deterministic efficiency.

Conclusion

Density-Softmax provides a scalable and theoretically grounded approach to uncertainty estimation. By combining geometric constraints with density modeling, it achieves state-of-the-art reliability in a single forward pass. Future work includes exploring ways to avoid explicit Jacobian computations to speed up training and applying this framework to large-scale pre-trained models like Vision Transformers.

Summary updated

Abstract

Sampling-based methods, e.g., Deep Ensembles and Bayesian Neural Nets have become promising approaches to improve the quality of uncertainty estimation and robust generalization. However, they suffer from a large model size and high latency at test-time, which limits the scalability needed for low-resource devices and real-time applications. To resolve these computational issues, we propose Density-Softmax, a sampling-free deterministic framework via combining a density function built on a Lipschitz-constrained feature extractor with the softmax layer. Theoretically, we show that our model is the solution of minimax uncertainty risk and is distance-aware on feature space, thus reducing the over-confidence of the standard softmax under distribution shifts. Empirically, our method enjoys competitive results with state-of-the-art techniques in terms of uncertainty and robustness, while having a lower number of model parameters and a lower latency at test-time.
BibTeX
@inproceedings{bui2024density,
  author = {Ha Manh Bui and Anqi Liu},
  title = {{Density-Softmax: Scalable and Distance-Aware Uncertainty Estimation under Distribution Shifts}},
  booktitle = {International Conference on Machine Learning},
  year = {2024},
  url = {https://openreview.net/forum?id=lon750Kf7n},
}
Figure