A Variational Dirichlet Framework for Out-of-Distribution Detection

1 INTRODUCTION . Recently , deep neural networks ( LeCun et al. , 2015 ) have surged and replaced the traditional machine learning algorithms to demonstrate its potentials in many real-life applications like speech recognition ( Hannun et al. , 2014 ) , image classification ( Deng et al. , 2009 ; He et al. , 2016 ) , and machine translation ( Wu et al. , 2016 ; Vaswani et al. , 2017 ) , reading comprehension ( Rajpurkar et al. , 2016 ) , etc . However , unlike the traditional machine learning algorithms like Gaussian Process , Logistic Regression , etc , deep neural networks are very limited in their capability to measure their uncertainty over the unseen test cases and tend to produce over-confident predictions . Such overconfidence issue ( Amodei et al. , 2016 ; Zhang et al. , 2016 ) is known to be harmful or offensive in real-life applications . Even worse , such models are prone to adversarial attacks and raise concerns in AI safety ( Goodfellow et al. , 2014 ; Moosavi-Dezfooli et al. , 2016 ) . Therefore , it is very essential to design a robust and accurate uncertainty metric in deep neural networks in order to better deploy them into real-world applications . Recently , An out-of-distribution detection task has been proposed in Hendrycks & Gimpel ( 2016 ) as a benchmark to promote the uncertainty research in the deep learning community . In the baseline approach , a simple method using the highest softmax score is adopted as the indicator for the model ’ s confidence to distinguish in- from out-ofdistribution data . Later on , many follow-up algorithms ( Liang et al. , 2017 ; Lee et al. , 2017 ; Shalev et al. , 2018 ; DeVries & Taylor , 2018 ) have been proposed to achieve better performance on this benchmark . In ODIN ( Liang et al. , 2017 ) , the authors follow the idea of temperature scaling and input perturbation ( Pereyra et al. , 2017 ; Hinton et al. , 2015 ) to widen the distance between in- and out-of-distribution examples . Later on , adversarial training ( Lee et al. , 2017 ) is introduced to explicitly introduce boundary examples as negative training data to help increase the model ’ s robustness . In DeVries & Taylor ( 2018 ) , the authors proposed to directly output a real value between [ 0 , 1 ] as the confidence measure . The most recent paper ( Shalev et al. , 2018 ) leverages the semantic dense representation into the target labels to better separate the label space and uses the cosine similarity score as the confidence measure . These methods though achieve significant results on out-of-distribution detection tasks , they conflate different levels of uncertainty as pointed in Malinin & Gales ( 2018 ) . For example , when presented with two pictures , one is faked by mixing dog , cat and horse pictures , the other is a real but unseen dog , the model might output same belief as { cat:34 % , dog:33 % , horse:33 % } . Under such scenario , the existing measures like maximum probability or label-level entropy ( Liang et al. , 2017 ; Shalev et al. , 2018 ; Hendrycks & Gimpel , 2016 ) will misclassify both images as from out-of-distribution because they are unable to separate the two uncertainty sources : whether the uncertainty is due to the data noise ( class overlap ) or whether the data is far from the manifold of training data . More specifically , they fail to distinguish between the lower-order ( aleatoric ) uncertainty ( Gal , 2016 ) , and higherorder ( episdemic ) uncertainty ( Gal , 2016 ) , which leads to their inferior performances in detecting out-domain examples . In order to resolve the issues presented by lower-order uncertainty measures , we are motivated to design an effective higher-order uncertainty measure for out-of-distribution detection . Inspired by Subjective Logic ( Jøsang , 2016 ; Yager & Liu , 2008 ; Sensoy et al. , 2018 ) , we first view the label-wise distribution P ( y ) as a K-dimensional variable z generated from a higher-order distribution P ( z ) over the simplex Sk , and then study the higher-order uncertainty by investigating the statistical properties of such underlying higher-order distribution . Under a Bayesian framework with data pair D = ( x , y ) , we propose to use variational inference to approximate such “ true ” latent distribution P ( z ) = p ( z|y ) by a parameterized Dirichlet posterior pθ ( z|x ) , which is approximated by a deep neural network . Finally , we compute the entropy of the approximated posterior for outof-distribution detection . However , we have observed an overwhelming over-concentration problem in our experiments , which is caused by over-confidence problem of the deep neural network to greatly hinder the detection accuracy . Therefore , we further propose to smooth the Dirichlet distribution by a calibration algorithm . Combined with the input perturbation method ( Liang et al. , 2017 ; Krizhevsky & Hinton , 2009 ) , our proposed variational Dirichlet framework can greatly widen the distance between in- and out-of-distribution data to achieve significant results on various datasets and architectures . The contributions of this paper are described as follows : • We propose a variational Dirichlet algorithm for deep neural network classification problem and define a higher-order uncertainty measure . • We identify the over-concentration issue in our Dirichlet framework and propose a smoothing method to alleviate such problem . 2 MODEL . In this paper , we particularly consider the image classification problem with image input as x and output label as y . By viewing the label-level distribution P ( y ) = [ p ( y = ω1 ) , · · · , p ( y = ωk ) ] as a random variable z = { z ∈ Rk : ∑k i=1 zi = 1 } lying on a K-dimensional simplex Sk , we assume there exists an underlying higher-order distribution P ( z ) over such variable z . As depicted in Figure 1 , each point from the simplex Sk is itself a categorical distribution P ( y ) over different classes . The high-order distribution P ( z ) is described by the probability over such simplex Sk to depict the underlying generation function . By studying the statistical properties of such higher-order distribution P ( z ) , we can quantitatively analyze its higher-order uncertainty by using entropy , mutual information , etc . Here we consider a Bayesian inference framework with a given dataset D containing data pairs ( x , y ) and show the plate notation in Figure 2 , where x denotes the observed input data ( images ) , y is the groundtruth label ( known at training but unknown as testing ) , and z is latent variable higher-order variable . We assume that the “ true ” posterior distribution is encapsulated in the partially observable groundtruth label y , thus it can be viewed as P ( z ) = p ( z|y ) . During test time , due to the inaccessibility of y , we need to approximate such “ true ” distribution with the given input image x . Therefore , we propose to parameterize a posterior model pθ ( z|x ) and optimize its parameters to approach such “ true ” posterior p ( z|y ) given a pairwise input ( x , y ) by minimizing their KL-divergence DKL ( pθ ( z|x ) ||p ( z|y ) ) . With the parameterized posterior pθ ( z|x ) , we are able to infer the higher-order distribution over z given an unseen image x∗ and quantitatively study its statistical properties to estimate the higher-order uncertainty . 𝑧 p ( z|y ) 𝑝 ( 𝑧|𝑥 ) Image x p ( y|z ) p ( z ) 𝜃 Label y Figure 2 : Plate Notation In order to minimize the KL-divergence DKL ( pθ ( z|x ) ||p ( z|y ) ) , we leverage the variational inference framework to decompose it into two components as follows ( details in appendix ) : DKL ( pθ ( z|x ) ||p ( z|y ) ) = −L ( θ ) + log p ( y ) ( 1 ) where L ( θ ) is better known as the variational evidence lower bound , and log p ( y ) is the marginal likelihood over the label y. L ( θ ) = E z∼pθ ( z|x ) [ log p ( y|z ) ] −DKL ( pθ ( z|x ) ||p ( z ) ) ( 2 ) Since the marginal distribution p ( y ) is constant w.r.t θ , minimizing the KL-divergence DKL ( pθ ( z|x ) ||p ( z|y ) ) is equivalent to maximizing the evidence lower bound L ( θ ) . Here we propose to use Dirichlet family to realize the higher-order distribution pθ ( z|x ) = Dir ( z|α ) due to its tractable analytical properties . The probability density function of Dirichlet distribution over all possible values of the K-dimensional stochastic variable z can be written as : Dir ( z|α ) = { 1 B ( α ) ∏K i=1 z αi−1 i for z ∈ Sk 0 otherwise , ( 3 ) where α is the concentration parameter of the Dirichlet distribution and B ( α ) = ∏K i Γ ( αi ) Γ ( ∑k i αi ) is the normalization factor . Since the LHS ( expectation of log probability ) has a closed-formed solution , we rewrite the empirical lower bound on given dataset D as follows : L ( θ ) = ∑ ( x , y ) ∈D [ ψ ( αy ) − ψ ( α0 ) −DKL ( Dir ( z|α ) ||p ( z ) ) ] ( 4 ) where α0 is the sum of concentration parameter α over K dimensions . However , it is in general difficult to select a perfect model prior to craft a model posterior which induces an the distribution with the desired properties . Here , we assume the prior distribution is as Dirichlet distributionDir ( α̂ ) with concentration parameters α̂ and specifically talk about three intuitive prior functions in Figure 3 . The first uniform prior aggressively pushes all dimensions towards 1 , while the * -preserving priors are less strict by allowing one dimension of freedom in the posterior concentration parameter α . This is realized by copying the value from kth dimension of posterior concentration parameter α to the uniform concentration to unbindαk from KL-divergence computation . Given the prior concentration parameter α̂ , we can obtain a closed-form solution for the evidence lower bound as follows : L ( θ ) = ∑ ( x , y ) ∈D [ ψ ( αy ) − ψ ( α0 ) − log B ( α̂ ) B ( α ) − k∑ i=1 ( αi − α̂i ) ( ψ ( αi ) − ψ ( α0 ) ) ( 5 ) Γ denotes the gamma function , ψ denotes the digamma function . We write the derivative of L ( θ ) w.r.t to parameters θ based on the chain-rule : ∂L∂θ = ∂L ∂α α · ∂fθ ( x ) ∂θ , where is the Hardamard product and ∂fθ ( x ) ∂θ is the Jacobian matrix . In practice , we parameterize Dir ( z|α ) via a neural network with α = fθ ( x ) and re-weigh the two terms in L ( θ ) with a balancing factor η . Finally , we propose to use mini-batch gradient descent to optimize the network parameters θ as follows : ∂L ∂α = ∑ ( x , y ) ∈B ( x , y ) [ ∂ [ ψ ( αy ) − ψ ( α0 ) ] ∂α + η ∂DKL ( Dir ( z|α ) ||Dir ( z|α̂ ) ) ∂α ] ( 6 ) where B ( x , y ) denotes the mini-batch in dataset D. During inference time , we use the marginal probability of assigning given input x to certain class label i as the classification evidence : p ( y = i|x ) = ∫ z p ( y = i|z ) pθ ( z|x ) dz = αi∑k j=1 αj ( 7 ) Therefore , we can use the maximum α ’ s index as the model prediction class during inference ŷ = arg maxi p ( y = i|x ) = arg maxi αi .

Summary: This paper proposes a new framework for out-of-distribution detection, based on variational inference and a prior Dirichlet distribution. The Dirichlet distribution is presented, and the way it is used withing the method is discussed (i.e. clipping, scaling, etc). Experiments on several datasets and comparison with the state of the art is reported and extensively discussed.