Abstract
Controlling the output probabilities of softmax-based models is a common problem in modern machine learning. Although the Softmax function provides soft control via its temperature parameter, it lacks the ability to enforce hard constraints, such as box constraints, on output probabilities, which can be critical in certain applications requiring reliable and trustworthy models. In this work, we propose the box-constrained softmax (BCSoftmax) function, a novel generalization of the Softmax function that explicitly enforces lower and upper bounds on output probabilities. While BCSoftmax is formulated as the solution to a box-constrained optimization problem, we develop an exact and efficient computation algorithm for BCSoftmax. As a key application, we introduce two post-hoc calibration methods based on BCSoftmax. The proposed methods mitigate underconfidence and overconfidence in predictive models by learning the lower and upper bounds of the output probabilities or logits after model training, thereby enhancing reliability in downstream decision-making tasks. We demonstrate the effectiveness of our methods experimentally using the TinyImageNet, CIFAR-100, and 20NewsGroups datasets, achieving improvements in calibration metrics.
Introduction: The Challenge of Overconfidence
In high-stakes fields like medical diagnosis or financial portfolio allocation, knowing how much to trust a model is as important as the prediction itself. A well-calibrated model's predicted probability should reflect the actual likelihood of being correct. However, modern deep neural networks are frequently "miscalibrated"—they tend to be overconfident (predicting 99% certainty for a 70% likely event) or occasionally underconfident.
Existing solutions like "Temperature Scaling" provide "soft" adjustments to probabilities but cannot guarantee that a model stays within specific safety bounds. If a system requires that no single class ever receives more than 75% probability (to prevent catastrophic over-allocation) or less than 4% (to ensure all options are considered), standard methods have no way to enforce these "hard" constraints.
Methods: Probability Bounding via BCSoftmax
The authors propose Probability Bounding (PB), which mitigates miscalibration by learning explicit lower ($a$) and upper ($b$) bounds for output probabilities on a validation set. The technical heart of the paper is the Box-Constrained Softmax (BCSoftmax). While standard Softmax is the solution to an unconstrained entropy-regularized optimization problem, BCSoftmax solves the same problem but adds "box constraints" ($a_i \le p_i \le b_i$).
Key methodological contributions include:
- An Exact Algorithm: Solving constrained optimization during every model inference is usually slow. The authors developed an exact, efficient algorithm that runs in $O(K \log K)$ time (where $K$ is the number of classes), making it practical for real-time use.
- Theoretical Guarantees: They prove that PB preserves the "top-k" rankings of the original model under certain conditions and provide an upper bound on the "smooth calibration error."
- Variants: They introduce Logit Bounding (LB), a simpler surrogate that clips the inputs to the Softmax, and Dual PB (DPB), which learns the constraints in the dual optimization space.
Key Results and Insights
The researchers evaluated their methods on four diverse real-world datasets: TinyImageNet, CIFAR-100, 20NewsGroups, and ImageNet-1K, using architectures like ResNet-50, DenseNet-121, and Vision Transformers (ViT).
- Consistent Error Reduction: Across almost all datasets and models, PB and its variants consistently reduced the Expected Calibration Error (ECE) and Smooth ECE compared to uncalibrated models and standard Temperature Scaling.
- Handling Underconfidence: On ImageNet-1K with a Vision Transformer (which is often underconfident), PB successfully "pushed" probabilities up, improving calibration where other methods struggled.
- Efficiency: Their custom algorithm makes BCSoftmax nearly as fast as standard Softmax, being 150–400x faster than general-purpose optimization solvers.
- Preserving Accuracy: PB generally preserves the original model's top-1 and top-k predictions while significantly improving the reliability of the probability scores.
Limitations and Future Work
While highly effective, enforcing hard bounds can theoretically lead to "ties" in the top-1 prediction, though this was rare in practice. Additionally, while Instance-Dependent PB (using a small neural network to predict bounds based on input) yields the best results, it adds complexity to the deployment pipeline.
Future work suggests BCSoftmax could be highly useful in Reinforcement Learning, where hard constraints could prevent a policy from becoming too "greedy" too quickly by balancing exploration and exploitation more robustly.
Summary updated