Offline Deep models calibration with bayesian neural networks

1 INTRODUCTION . Deep Neural Networks ( DNNs ) have achieved state of art performance in many task such as Image Recognition ( Huang et al. , 2017 ; Szegedy et al. , 2017 ; Zagoruyko & Komodakis , 2016 ) , language modeling ( Mikolov et al. , 2013a ; b ) , machine translation ( Vaswani et al. , 2017 ) or speech ( Hinton et al. , 2012 ) . For that reason , neural networks are now used in many applications . However , this state-of-theart performance is measured in terms of accuracy , but there are many tasks in which the probabilistic information must be also reliable . For example , a probabilistic classifier can be incorporated into a more complex model considering multiple sources of information , by the use of e.g. , probabilistic graphical models ( Koller & Friedman , 2009 ) , or by combining neural networks with language models in natural language processing tasks ( Gulcehre et al. , 2017 ) . In addition , probabilistic outputs of classifiers have proven to be useful in many areas apart from classical machine learning tasks , such as language recognition ( Brümmer & van Leeuwen , 2006 ) , language models for speech recognition ( Tüske et al. , 2018 ) or medical diagnosis ( Caruana et al. , 2015 ) . In Bayesian statistics , the reliability of probabilities is measured by their calibration . As a consequence , the machine learning community has been exploring methods to calibrate the output of classifiers to achieve the many beneficial properties of well-calibrated probabilities ( Zadrozny & Elkan , 2002a ; Cohen & Goldszmidt , 2004 ; Niculescu-Mizil & Caruana , 2005 ) . Nowadays , there is an increasing interest in obtaining reliable probabilities in the deep learning community . In the past , neural networks trained with a cross-entropy criterion tended to present relatively good calibration . However , a relevant recent work in Guo et al . ( 2017 ) has evidenced that modern state-of-the-art neural networks are badly calibrated in general . Moreover , the same work shows that calibration can be dramatically improved by very simple maximum-likelihood parametric techniques , among which Temperature Scaling ( TS ) is highlighted as the preferred choice , due to its extreme simplicity , ResNet-101 : 93.46 % accuracy ( CIFAR10 ) very good behavior in general and computational efficiency . In fact , TS outperforms more complex techniques in most cases , leading to the conclusion that good calibration can be better achieved with simpler techniques . This conclusion follows the hypothesis that the space configured by the outputs of a deep model is relatively simple , and therefore good performance , measured as Expected Calibration Error ( ECE ) , can be achieved with very simple models . In fact , TS is a technique that performs nicely in complex multiclass tasks ( Guo et al. , 2017 ) . In general , there are two main approaches to reduce overconfidence : implicit or online and explicit or offline . An implicit method aims at obtaining calibrated distributions directly at the output of the model , while explicit methods post-process the output of the model to be calibrated . In this paper we propose an offline method based on a Bayesian Neural Networks ( BNNs ) to obtain calibrated probabilities , see figure 2 . We use BNNs as we aim at being benefited from two key properties of Bayesian statistics and neural networks : the high expressiveness of neural network models and the capabilities of the Bayesian statistics to model the uncertainty . We assume the hypothesis that as long as the uncertainty is correctly modelled , we can use high expressive function approximators for the task of calibration . These high expressive models are required since we assume that the calibration space is not simple . However , the generalization capability of these models are achieved through proper uncertainty consideration . Figure 1 shows reliability diagrams comparing our BNN method to TS . This work is organized as follows . We first provide an insight on why Bayesian Statistics and neural networks are suitable to adjust confidence in output probabilities . We then describe our offline calibration approach based on BNNs . We end up comparing our method to TS and reporting clear performance improvements . Finally , we discuss our approach against recent published techniques , enumerate some beneficial properties and propose possible improvements over this contribution . 2 BAYESIAN MODELLING AND CALIBRATION . In a classification scenario , calibration can be interpreted as the agreement between the probabilities of a class assigned by a model to a set of samples , and the proportion of those samples where that class is actually the true one . One way of achieving calibration is to reliably modelling the probabilistic distributions of the data from the classes involved . This is the main strength of Bayesian models , which manage uncertainty properly , in contrast to point-estimate approaches ( i.e . Maximum Likelihood or Maximum Posterior ) . In the former , the uncertainty is incorporated by taking an average of all the likelihood models under the posterior distribution on the parameters , given an observed set of data : p ( t|x ) = Ep ( θ|O ) { p ( t|x , θ ) } , ( 1 ) where θ are model parameters , x represent a sample for which we want to predict a label t and O = { ( xi , ti ) } Ni=1 is the set of observed samples1 . In Bayesian approaches , it is indeed the observed data what model how representative a likelihood model is for a particular task , and thus how it influences the predictions . On the other hand , in point-estimate models all the decision is based on a choice of the parameter once the model is trained . For instance , consider the case of a MAP network ( e.g. , a typical deep convolutional model trained with cross-entropy loss and L2 regularization ) . This model explains the data based on a point-estimate training , i.e. , by representing what is more likely to appear . Nowadays , this gives outstanding accuracy in classification tasks , but it is easy to train an over/under-confident model , i.e. , the one that outputs too extreme probabilities , even for unfavourable cases like e.g . when data that has conditions not unseen in the training set , or not explained by the expressiveness of the model itself . This could happen if the true distribution does not lie in the family of parametric models p ( t|x , θ ) . We will refer to both conditions as mismatch . This is very harmful for the calibration , because in those mismatch cases , the model should yield more moderate probabilities , otherwise the classification errors will be more catastrophic . In other words , in tasks where calibration matters , a classification error has unequal consequences if the probabilities are moderate or extreme . Thus , for example , if there exists such mismatching conditions , what is likely to happen , a point estimate will not represent the data ( i.e . the probability assigned ) in the way it should , possibly leading to over-or under-estimation of probabilities . On the other hand , in the Bayesian framework , a posterior distribution on the parameters could consider networks explaining these mismatching conditions . By averaging different contributions , the model ideally moderates probabilities on unfavourable data . For the sake of illustration , we provide a simple example in appendix A . We encourage unfamiliar readers with Bayesian statistics and calibration to read this appendix . Regarding the accuracy of Bayesian models , in Bayesian decision theory , if the model used to generate the data is known , the optimal error can be achieved , which also means optimal accuracy if all decision costs are equal . This suggests that a proper way of assigning probabilities is also paramount for the accuracy . Thus , by choosing appropriate densities for the class-conditional probabilities p ( t|x ) , such as factorized multivariate Bernoulli distributions like in point estimate models , the accuracy will also be correctly modelled . Moreover , it is well known that Bayesian models asymptotically tend to point estimate models as the data increases in size , see Duda et al . ( 2000 ) section 3.4 . Therefore , it is expected that good accuracy performance achieved by point-estimate models should be also achievable by Bayesian models , at least for sufficient amounts of data . 3 OFFLINE CALIBRATION WITH BAYESIAN NEURAL NETWORKS . The architecture proposed in this work is shown in Figure 2 . We apply a BNN to the potentially uncalibrated outputs of a DNN model . The goal is to improve the calibration minimizing the accuracy degradation of the original DNN model . Our approach works offline , meaning that given a DNN model , we project the available data to the space defined by the outputs of the model in the form of logit , i.e . pre-softmax values . This new representation is then the input to our BNN . The BNN aims at taking this uncalibrated so-called logit space and project it to a new calibrated one . The same procedure is applied for the TS method . 1This is a particularization of Bayesian learning for class-conditional modelling . This off-line set-up presents clear advantages . First , the approach is efficient , since the DNN model does not need to be re-trained for re-calibration . Furthermore , we can incorporate future improvements to the BNN calibration stage without affecting the previous DNN model . Second , our proposal is extremely flexible , as the proposed BNN calibration stage will work with any probabilistic model , even implicitly-calibrated models , with potential benefits on calibration performance . And finally , our proposal preserves privacy , because there is no need to access the original data used to train the DNN model , or even the DNN topology : to be trained , the BNN only needs the data projected to the outputs of the DNN on the logit space , and the original targets t. For these Bayesian approaches one has to compute the posterior distribution p ( θ|O ) and the expectation in equation 1 . Using configurations that yield to analytic solutions to both problems result in low-expression models for this task . We solve this problem by choosing Neural Networks to parameterize the likelihood p ( t|x , θ ) of our BNN , and therefore taking advantage of the high expressiveness of these models . In this case , several intractabilities arise that must be addressed . In this work we approximate expectations on equation 1 with Monte Carlo integration , and the posterior is approximated by a variational distribution in terms of the Kulback-Lieber Divergence . This is done by the maximization the Evidence Lower Bound ( ELBO ) . We use stochastic optimization based on the reparameterization trick ( Kingma & Welling , 2014 ; Rezende et al. , 2014 ) to approximate the expectation under the variational distribution , and also mini-batch stochastic optimization for expectations under data distribution . Thus , our training criteria is given by : ELBO = 1 N ∑ ( x , t ) ∼pd ( x , t ) [ 1 K ∑ θ∼qφ ( θ ) [ log p ( t|x , θ ) ] − β ·DKL { qφ ( θ ) //p ( θ ) } ] , ( 2 ) where we introduce β following Blundell et al . ( 2015 ) . Our variational distribution is a factorized Gaussian distribution and for that reason we refer to our BNN approach as a basic approach , as we do not incorporate any improvement recently proposed for BNN models , such as normalizing flows , local reparameterization , and so on . Also , we use a standard normal density for the prior . We choose this simple approximation to demonstrate our starting hypothesis : that BNNs can be applied to improve the calibration of state-of-the-art DNN in a very efficient way . Our basic BNN model can be improved by using normalizing flows ( Rezende & Mohamed , 2015 ; Kingma et al. , 2016 ; Huang et al. , 2018 ; van den Berg et al. , 2018 ) , auxiliary variables ( Agakov & Barber , 2004 ; Ranganath et al. , 2016 ; Maaløe et al. , 2016 ) , local reparameterization ( Kingma et al. , 2015 ) , combinations of all of them ( Louizos & Welling , 2017 ) or deterministic models ( Wu et al. , 2018 ) . Also , Cremer et al . ( 2018 ) has recently pointed out that amortized inference leads to an additional gap in the bound , in addition to the DKL gap between the true and variational posteriors ; and we can also use other proposals to mitigate this effect ( Shu et al. , 2018 ; Kim et al. , 2018 ) . Finally , class predictions are assigned by first computing the logits of a test sample using the first DNN stage B , and then using them as inputs of our BNN to yield calibrated probabilities , which can be formalized as follows : l = B ( x ) p ( t|x , O ) ≈ 1 M M∑ i=1 p ( t|l , θi ) ; θi ∼ qφ ( θ ) , ( 3 ) where M is a value chosen on validation . Note that our proposed BNN is not as efficient as TS for calibration . However , the contributions to the weighted average can be fully parallelized computationally , as predictions do not depend on each other . Thus , we can use modern GPU libraries such as CUBLAS and batch-based operations to dramatically speed-up the process .

Summary: This paper presents an approach for calibrating the predictions of deep neural networks. The idea is quite simple and straightforward - simply use a more expressive model (Bayesian neural network with amortized inference). Surprisingly, the results show that this simple approach outperforms many of the recent approaches, such as those based on temperature scaling. A trick that they use is to control the KL term in the approximation of the ELBO using a hyperparameter (but this has been used in prior work on Bayesian neural nets).