A Geometric Perspective towards Neural Calibration via Sensitivity Decomposition

It is well known that vision classification models suffer from poor calibration in the face of data distribution shifts . In this paper , we take a geometric approach to this problem . We propose Geometric Sensitivity Decomposition ( GSD ) which decomposes the norm of a sample feature embedding and the angular similarity to a target classifier into an instance-dependent and an instance-independent component . The instance-dependent component captures the sensitive information about changes in the input while the instance-independent component represents the insensitive information serving solely to minimize the loss on the training dataset . Inspired by the decomposition , we analytically derive a simple extension to current softmax-linear models , which learns to disentangle the two components during training . On several common vision models , the disentangled model outperforms other calibration methods on standard calibration metrics in the face of out-of-distribution ( OOD ) data and corruption with significantly less complexity . Specifically , we surpass the current state of the art by 30.8 % relative improvement on corrupted CIFAR100 in Expected Calibration Error . Code available at https : //github.com/GT-RIPL/Geometric-Sensitivity-Decomposition.git . 1 Introduction . During development , deep learning models are trained and validated on data from the same distribution . However , in the real world sensors degrade and weather conditions change . Similarly , subtle changes in image acquisition and processing can also lead to distribution shift of the input data . This is often known as covariate shift , and will typically decrease the performance ( e.g . classification accuracy ) . However , it has been empirically found that the model ’ s confidence remains high even when accuracy has degraded [ 1 ] . The process of aligning confidence to empirical accuracy is called model calibration . Calibrated probability provides valuable uncertainty information for decision making . For example , knowing when a decision can not be trusted and more data is needed is important for safety and efficiency in real world applications such as self-driving [ 2 ] and active learning [ 3 ] . A comprehensive comparison of calibration methods has been studied for in-distribution ( IND ) data [ 4 ] , However , these methods lead to unsatisfactory performance under distribution shift [ 5 ] . To resolve the problem , high-quality uncertainty estimation [ 6 , 5 ] is required . Principled Bayesian methods [ 7 ] model uncertainty directly but are computationally heavy . Recent deterministic methods [ 8 , 9 ] propose to improve a model ’ s sensitivity to input changes by regularizing the model ’ s intermediate layers . In this context , sensitivity is defined as preserving distance between two different input samples through layers of the model . We would like to utlize the improved sensitivity to better detect 35th Conference on Neural Information Processing Systems ( NeurIPS 2021 ) . Out-of-Distribution ( OOD ) data . However , these methods introduce added architecture changes and large combinatorics of hyperparameters . Unlike existing works , we propose to study sensitivity from a geometric perspective . The last linear layer in a softmax-linear model can be decomposed into the multiplication of a norm and a cosine similarity term [ 10 , 11 , 12 , 13 ] . Geometrically , the angular similarity dictates the membership of an input and the norm only affects the confidence in a softmax-linear model . Counter-intuitively , the norm of a sample ’ s feature embedding exhibits little correlation to the hardness of the input [ 11 ] . Based on this observation , we explore two questions : 1 ) why is a model ’ s confidence insensitive to distribution shift ? 2 ) how do we improve model sensitivity and calibration ? We hypothesize that in part an insensitive norm is responsible for bad calibration especially on shifted data . We observe that the sensitivity of the angular similarity increases with training whereas the sensitivity of the norm remains low . More importantly , calibration worsens during the period when the norm increases while the angular similarity changes slowly . This shows a concrete example of the inability of the norm to adapt when accuracy has dropped . Intuitively , training on clean datasets encourages neural networks to always output increasingly large feature norm to continuously minimize the training loss . Because the probability of the prevalent class of an input is proportional to its norm , larger norms lead to smaller training loss when most training data have been classified correctly ( See Sec . 3.1 ) . This renders the norm insensitive to input differences because the model is trained to always output features with large norm on clean data . While we have put forth that the norm is poorly calibrated , we must emphasize that it can still play an important role in model calibration ( See Sec . 4.1 ) . To encourage sensitivity , we propose to decompose the norm of a sample ’ s feature embedding and the angular similarity into two components : instance-dependent and instance-independent . The instance-dependent component captures the sensitive information about the input while the instanceindependent component represents the insensitive information serving solely to minimize the loss on the training dataset . Inspired by the decomposition , we analytically derive a simple extension to the current softmax-linear model , which learns to disentangle the two components during training . We show that our model outperforms other deterministic methods ( despite their significant complexity ) and is comparable to multi-pass methods with fewer training hyperparameters in Sec . 4.1 . In summary , our contributions are four fold : • We study the problem of calibration geometrically and identify that the insensitive norm is responsible for bad calibration under distribution shift . • We derive a principled but simple geometric decomposition that decomposes the norm into an instance-dependent and instance-independent component . • Based on the decomposition , we propose a simple training and inference scheme to encourage the norm to reflect distribution changes . • We achieve state of the art results in calibration metrics in the face of corruptions while having arguably the simplest calibration method to implement . 2 Related Work . Methods dedicated to strengthening calibration can be divided into two camps : multi-pass models and single-pass deterministic models . The current state-of-the-art multi-pass models are : Bayesian Monte Carlo Drop Out ( MCDO ) [ 7 ] and Deep Ensembles [ 14 ] . Bayesian methods are the most principled way to model uncertainty . Instead of optimizing max likelihood for a single set of parameters , Bayesian methods obtain a posterior distribution over possible parameters given a prior distribution over parameters and calculated data likelihood assuming some process noise . The posterior distribution over parameters captures epistemic uncertainty or uncertainty due to the limits of what the model knows . The final predictive distribution is obtained by marginalizing out model parameters . While Bayesian methods are theoretically sound , they are intractable in practice . Deep Ensembles averages multiple models trained using different random initialization so they learn different classification functions . A recent trend is to use a single-pass deterministic non-Bayesian model to improve uncertainty estimation . Two recent works DUQ [ 8 ] and SNGP [ 9 ] propose to improve uncertainty-awarenesss of deterministic networks by improving the networks ’ sensitivity to input changes . Intuitively , a sensitive model should map samples further from the training data as they become more out-of-distribution . This can be achieved at two levels : feature level and output level . At the feature level , both methods require the feature extractors ( CNNs ) to be regularized to prevent feature collapse , which is the mapping of two different data points to the same embedded vector . This is ensured by having input distance awareness , which is equivalent to ensuring bi-Lipschitz continuity [ 15 ] . In order to achieve this , DUQ [ 8 ] uses a two-sided gradient penalty [ 16 ] and SNGP [ 9 ] uses bounded spectral normalization [ 15 ] . The output level needs to reflect the changes in feature space . This can be done by adopting distance-aware classifiers . DUQ [ 8 ] uses a RBF networks with learned centroids for each class and SNGP [ 9 ] uses an approximate Gaussian Process layer . We were inspired by temperature scaling [ 4 ] , which is another method for bettering calibration , but fails under distribution shift [ 5 ] . Our method does not require input distance awareness and instead leverages the geometric intuitions about the output layer , specifically properties of the norm of the input embedding . 3 Method . Following our hypothesise that the insensitivity of the norm is responsible for bad calibration on distribution shifted data , we propose geometric sensitivity decomposition ( GSD ) for the norm . We first introduce the geometric perspective of the last linear layer in Sec . 3.1 and then derive GSD in Sec . 3.2 . To improve sensitivity of the norm and model calibration on shifted data , we propose a GSD-inspired training and inference procedure in Sec . 3.3 and Sec . 3.4 . 3.1 Norm and Similarity . The output layer of a neural network can be written as a dot-product < x , wy > , where x is the embedded input and wy is the weight vector associated with class y . Though seemingly simple there are strong geometric and calibration related intuitions drawn from this . Several prior works [ 10 , 12 , 11 ] have studied the effects decomposition of the last linear layer in a softmax model can have on classification . The output layer can be decomposed into angular similarity cosφy and norm ‖x‖2 . P ( y|x ) = exp ly∑c j=1 exp lj = exp ( ‖wy‖2‖x‖2 cosφy ) ∑c j=1 exp ( ‖wj‖2‖x‖2 cosφj ) ( 1 ) where ‖wy‖2 is the norm of a specific classifier in the linear layer . We ’ ll use this geometric view of the linear layer instead of the dot-product representation . Based on this perspective , we base the foundation of our work on the following observations from prior works [ 10 , 12 , 11 ] : 1 ) The probability/confidence of the prevalent class of an input is proportional to its norm [ 12 ] . 2 ) While the norm of a feature strongly scales the predictive probability , due to it ’ s unregularized nature the norm is not sensitive to the hardness of the input [ 11 ] . In other words , the norm could be the reason for bad sensitivity of the confidence to input distribution shift . Consequently , the insensitive norm can be causally related to bad calibration . We will examine a strong correlation between the quality of calibration and the magnitude of norm in Sec . 4.2 . 3.2 Geometric Sensitivity Decomposition of Norm and Angular Similarity . To motivate the subsequent geometric decomposition , we can revisit the softmax model , P ( y|x ) ∝ exp ( ‖wy‖2‖x‖2 cosφy ) . There are three terms contributing to the magnitude of the exponential function , ‖wy‖2 , ‖x‖2 and cosφy . Due to weight regularizations , ‖wy‖2 is most likely very small , while cosφy ∈ [ −1 , 1 ] . Therefore , the only way to obtain a high probability/confidence on training data and minimize cross-entropy loss is to 1 ) push the norm ‖x‖2 to a large value and 2 ) keep cos |φy| of the ground truth class close to one , i.e. , |φy| close to zero . This is further supported by [ 17 ] , where it was shown that logits of the ground truth class must diverge to infinity in order to minimize cross-entropy loss under gradient descent . In this process , models tend towards large norms and small angles for all training samples . Therefore , we propose to decompose the norms of features into two components : an instanceindependent scalar offset and an instance-dependent variance factor , which we define in Eq . 2 . The role of the instance-independent offset Cx is to minimize the loss on the entire training set and the instance-dependent component ∆x accounts for differences in samples . Therefore , if we can disentangle the instance-independent component from the instance-dependent component , we can obtain a norm that is sensitive to the hardness of data . Following this logic , we decompose the norm into two components . ‖x‖2 = ‖∆x‖2 + Cx ( 2 ) Similarly , we relax the angles such that the predicted angular similarity does not need to be close to one on the training data , i.e. , making the angles larger . To achieve this , we introduce an instanceindependent relaxation angle Cφ and an instance-dependent angle ∆φy . Analogous to the norm decomposition , the scalar Cφ serves solely to minimize the training loss while the instance-dependent ∆φy accounts for differences in samples . Because we need to account for the sign of the angle , we put an absolute value on it . |φy| = |∆φy| − |Cφ| ( 3 ) The ‖∆x‖2 , |∆φy| are the instance-dependent components and Cx , |Cφ| are the instance-independent components . We can rewrite the pre-softmax logits in Eq . 1 with the decomposed norm and angular similarity . ( Detailed derivation in Sec . A.1 in the Appendix . ) ‖x‖2 cosφy = ‖x‖2 cos |φy| = ( ‖∆x‖2 + Cx ) cos ( |∆φy| − |Cφ| ) ( 4 ) = ( ‖∆x‖2 + Cx ) 1 cos |Cφ| cos |∆φy| ( 1− sin |Cφ|2 ( 1− cos |Cφ| sin |∆φy| sin |Cφ| cos |∆φy| ) ) We can simplify the equation by assuming cos |φy| is close to one , which means |φy| is small . This is due to the fact that |φy| is the angle between the correct class weight and x , which means as training ensues , the angle converges to 0 and thus the cosine similarity converges to 1 . ( Please see Sec . A.2 for empirical support . ) cos |Cφ| sin |∆φy| sin |Cφ| cos |∆φy| = sin ( |∆φy|+ |Cφ| ) + sin |φy| sin ( |∆φy|+ |Cφ| ) − sin |φy| ≈ 1 ( 5 ) Therefore , Eq . 4 , omitting the absolute value on angles because cos is an even function , simplifies : ‖x‖2 cosφy ≈ ( ‖∆x‖2 + Cx ) 1 cos Cφ cos ∆φy ( 6 ) = ( 1 cos Cφ ‖∆x‖2 + 1 cos Cφ Cx ) cos ∆φy = ( 1 α ‖∆x‖2 + β α ) cos ∆φy Because cos Cφ and Cx are instance-independent , we denote them as α and β respectively . This geometric decomposition of norm and cosine similarity inspires us to include α and β as free trainable parameters in a new network and the network can learn to predict the more inputsensitive ‖∆x‖2 and ∆φy instead of the original ‖x‖2 and φy . While both the angle and norm can be decomposed we direct the focus to the norm as the angle is already calibrated to accuracy [ 11 ] . In other words , angles have been shown to be sensitive to input changes in [ 11 ] .

Summary: This paper studies the problem of neural calibration from a novel geometric perspective and finds that the insensitive norm is responsible for bad calibration under distribution shift. Based on this insight, this paper proposes Geometric Sensitivity Decomposition (GSD), which decomposes the norm and angular similarity into an instance-dependent and instance-independent component. Subsequently, this paper proposes a training and inference scheme, to encourage the norm to reflect distribution changes. The proposed method is easy to implement and achieves SOTA results in calibration metrics in the face of corruptions.