Reliable Uncertainty Estimates in Deep Neural Networks using Noise Contrastive Priors

1 INTRODUCTION . Many successful applications of neural networks ( Krizhevsky et al. , 2012 ; Sutskever et al. , 2014 ; van den Oord et al. , 2016 ) are in restricted settings where predictions are only made for inputs similar to the training distribution . In real-world scenarios , neural networks can face truly novel data points during inference , and in these settings it can be valuable to have good estimates of the model ’ s uncertainty . For example , in healthcare , reliable uncertainty estimates can prevent overconfident decisions for rare or novel patient conditions ( Schulam and Saria , 2015 ) . Similarly , autonomous agents that actively explore their environment can use uncertainty estimates to decide what data points will be most informative . Epistemic uncertainty describes the amount of missing knowledge about the data generating function . Uncertainty can in principle be completely reduced by observing more data points at the right locations and training on them . In contrast , the data generating function may also have inherent randomness , which we call aleatoric noise . This noise can be captured by models outputting a distribution rather than a point prediction . Obtaining more data points allows the noise estimate to move closer to the true value , which is usually different from zero . For active learning , it is crucial to separate the two types of randomness : we want to acquire labels in regions of high uncertainty but low noise ( MacKay , 1992a ) . Bayesian analysis provides a principled approach to modeling uncertainty in neural networks ( Denker et al. , 1987 ; MacKay , 1992b ) . Namely , one places a prior over the network ’ s weights and biases . This effectively places a distribution over the functions that the network represents , capturing uncertainty about which function best fits the data . Specifying this prior remains an open challenge . Common practice is to use a standard normal prior in weight space , which imposes weak shrinkage regularities analogous to weight decay . It is neither informative about the induced function class nor the data ( e.g. , it is sensitive to parameterization ) . This can cause the induced function posterior to generalize in unforeseen ways on out-of-distribution ( OOD ) inputs , which are inputs outside of the distribution that generated the training data . Motivated by these challenges , we introduce noise contrastive priors ( NCPs ) , which encourage uncertainty outside of the training distribution through a loss in data space . NCPs are compatible with any model that represents functional uncertainty as a random variable , are easy to scale , and yield reliable uncertainty estimates that show significantly improved active learning performance . 2 NOISE CONTRASTIVE PRIORS . Specifying priors is intuitive for small probabilistic models , where each variable typically has a clear interpretation ( Blei , 2014 ) . It is less intuitive for neural networks , where the parameters serve more as adaptive basis coefficients in a nonparametric function . For example , neural network models are nonidentifiable due to weight symmetries that yield the same function ( Müller and Insua , 1998 ) . This makes it difficult to express informative priors on the weights , such as expressing high uncertainty on unfamiliar examples . Data priors Unlike a prior in weight space , a data prior lets one easily express informative assumptions about input-output relationships . Here , we use the example of a prior over a labeled data set { x , y } , although the prior can also be on x and another variable in the model that represents uncertainty and has a clear interpretation . The prior takes the form pprior ( x , y ) = pprior ( x ) pprior ( y | x ) , where pprior ( x ) denotes the input prior and pprior ( y | x ) denotes the output prior . To prevent overconfident predictions , a good input prior pprior ( x ) should include OOD examples so that it acts beyond the training distribution . A good output prior pprior ( y | x ) should be a high-entropy distribution , representing high uncertainty about the model output given OOD inputs . Generating OOD inputs Exactly generating OOD data is difficult . A priori , we must uniformly represent the input domain . A posteriori , we must represent the complement of the training distribution . Both distributions are typically uniform over infinite support , making them ill-defined . To estimate OOD inputs , we develop an algorithm inspired by noise contrastive estimation ( Gutmann and Hyvärinen , 2010a ; Mnih and Kavukcuoglu , 2013 ) , where a complement distribution is approximated using random noise . A hypothesis of our work is that in practice it is enough to encourage high uncertainty output near the boundary of the training distribution , and that this effect will propagate to the entire OOD space . This hypothesis is backed up by previous work ( Lee et al. , 2017 ) as well as our experiments ( see Figure 1 ) . This means we no longer need to sample arbitrary OOD inputs . It is enough to sample OOD points that lie close to the boundary of the training distribution , and to apply our desired prior at those points . Loss function Noise contrastive priors are data priors that are enforced on both training inputs x and inputs x̃ perturbed by noise . For example , in binary and categorical input domains , we approximate OOD inputs by randomly flipping the features to different classes with a certain probability . For continuous valued inputs x , we can use additive Gaussian noise to obtain noised up inputs x̃ = x+ . This expresses the noise contrastive prior where inputs are distributed according to the convolved distribution , pprior ( x̃ ) = ∫ x ptrain ( x ) Normal ( x̃− x | µx , σ2x ) dx pprior ( ỹ | x̃ ) = Normal ( µy , σ2y ) . ( 1 ) The variances σ2x and σ 2 y are hyperparameters that tune how far from the boundary we sample , and how large we want the output uncertainty to be . We choose µx = 0 to apply the prior equally in all directions from the data manifold . The output mean µy determines the default prediction of the model outside of the training distribution , for example µy = 0 . We set µy = y which corresponds to data augmentation ( Matsuoka , 1992 ; An , 1996 ) , where a model is trained to recover the true labels from perturbed inputs . This way , NCP makes the model uncertain while still trying to generalize to OOD inputs . For training , we minimize the loss function L ( θ ) = Eptrain ( x ) [ DKL [ ptrain ( y | x ) ‖ pmodel ( y | x , θ ) ] ] +γEpprior ( x̃ ) [ DKL [ pprior ( ỹ | x̃ ) ‖ pmodel ( ỹ | x̃ , θ ) ] ] . ( 2 ) The first term represents typical maximum likelihood , in which one minimizes the KL divergence to the empirical training distribution ptrain ( y | x ) over training inputs . The second term is added by our method : it represents the analogous term on a data prior . The hyperparameter γ sets the relative trade-off between them . Interpretation as function prior The noise contrastive prior can be interpreted as inducing a function prior . This is formalized through the prior predictive distribution , p ( y | x ) = ∫ pmodel ( y | x , θ ) pmodel ( θ | x̃ , ỹ ) pprior ( x̃ , ỹ ) dθ dx̃ dỹ . ( 3 ) The distribution marginalizes over network parameters θ as well as data fantasized from the data prior . The distribution p ( θ | x̃ , ỹ ) represents the distribution of model parameters after fitting the prior data . That is , the belief over weights is shaped to make p ( y | x ) highly variable . This parameter belief causes uncertain predictions outside of the training distribution , which we could not specify in weight space directly . Because network weights are constrained to fit the data prior , the prior acts as “ pseudo-data. ” This is similar to classical work on conjugate priors : a Beta ( α , β ) prior on the probability of a Bernoulli likelihood implies a Beta posterior , and if the posterior mode is chosen as an optimal parameter setting , then the prior translates to α− 1 successes and β − 1 failures . It is also similar to pseudo-data in sparse Gaussian processes ( Quiñonero-Candela and Rasmussen , 2005 ) . Data priors encourage learning parameters that not only capture the training data well but also the prior data . In practice , we can combine NCP with other priors , for example the typical standard normal prior in weight space for Bayesian neural networks , although we did not find this necessary in our experiments . 3 BAYESIAN NEURAL NETWORKS WITH NCP . Noise contrastive priors are applicable to any model that represents uncertainty in a random variable . The NCP can then be added to that random variable to make the model uncertain on OOD inputs . In this section , we apply NCP to a Bayesian neural network ( BNN ) trained via variational inference . Blundell et al . ( 2015 ) introduce such a model under the name Bayes by Backprop ( BBB ) that uses a standard normal prior in weight space . We extend this model with a NCP on the mean predicted by the neural network . Consider a regression task with data { x , y } that we model as p ( y | x , θ ) = Normal ( µ ( x ) , σ2 ( x ) ) with mean and variance predicted by a neural network from the inputs . This model is heteroskedastic , meaning that it can predict a different aleatoric noise amount for every point in the input space . We use a weight prior for only the output layer ( Lázaro-Gredilla and Figueiras-Vidal , 2010 ; Calandra et al. , 2014 ) that predicts the mean , resulting in the model θ ∼ Normal ( 0 , 0.1 ) y ∼ Normal ( µ ( x , θ ) , σ2 ( x ) ) . ( 4 ) We do not model uncertainty about the noise estimate , as this is not required for the approximation for the Gaussian expected information gain ( MacKay , 1992a ) that we use to acquire labels . Therefore , the distribution of the mean induced by the weight prior , q ( µ ( x ) ) = ∫ µ ( x , θ ) qφ ( θ ) dθ , represents the model ’ s epistemic uncertainty . Note that this is different from the predictive distribution , which combines both uncertainty and noise . We place an NCP on the distribution of the mean , resulting in the loss function L ( φ ) = −Eqφ ( θ ) [ ln p ( y | x , θ ) ] + βDKL [ qφ ( θ ) ‖ p ( θ ) ] + γDKL [ Normal ( µµ , σ 2 µ ) ‖ q ( µ ( x̃ ) ) ] NCP loss . ( 5 ) Here , x̃ are the perturbed inputs and qφ ( θ ) forms an approximate posterior over weights.1 Because we only use the weight belief for the linear output layer , we can compute the KL-divergence of the NCP loss analytically . In other models , it could be estimated using samples . The loss function applies weight regularization in order for network weights to regress to a standard normal prior ; like other regularization techniques , this assists in improving the network ’ s generalization in-distribution . 1To derive the loss , set p ( y | x , θ ) = Eqφ ( θ ) [ p ( y | x , θ ) ] in Equation 2 and apply Jensen ’ s inequality ( Blundell et al. , 2015 ; Higgins et al. , 2016 ) . The NCP loss encourages the network ’ s generalization OOD by matching the mean distribution to the output prior . Minimizing the KL divergence to a wide output prior results in high uncertainty on OOD inputs , so the model will explore these data points during active learning . In practice , we find that NCP is sufficient as a prior for the BNN and set β = 0 . The appendix ( Appendix B includes an alternative interpretation explaining why NCP might be sufficient , which represents the weight space KL-divergence in data space after a change of variables .

Summary: The paper considers the problem of obtaining reliable predictive uncertainty estimates. The authors propose noise contrastive priors — the idea being to explicitly encourage high uncertainties for out of distribution (OOD) data through a loss in the data space.  OOD data is simulated by adding noise to existing data and the model is trained to maximize the likelihood wr.t. training data while being close in the KL sense to a (wide) conditional prior p(y | x) on the OOD responses (y).  The authors demonstrate that the procedure leads to improved uncertainty estimates on toy data and can better drive active learning on a large flight delay dataset.