A V ARIATIONAL D IRICHLET F RAMEWORK FOR O UTOF -D ISTRIBUTION D ETECTION
Anonymous authors
Paper under double-blind review
A BSTRACT
With the recently rapid development in deep learning, deep neural networks have been widely adopted in many real-life applications.
However, deep neural networks are also known to have very little control over its uncertainty for test examples, which potentially causes very harmful and annoying consequences in practical scenarios.
In this paper, we are particularly interested in designing a higherorder uncertainty metric for deep neural networks and investigate its performance on the out-of-distribution detection task proposed by Hendrycks & Gimpel (2016).
Our method ﬁrst assumes there exists a underlying higher-order distribution P ( z ) , which generated label-wise distribution P ( y ) over classes on the K-dimension simplex, and then approximate such higher-order distribution via parameterized posterior function p θ ( z | x ) under variational inference framework, ﬁnally we use the entropy of learned posterior distribution p θ ( z | x ) as uncertainty measure to detect out-of-distribution examples.
However, we identify the overwhelming overconcentration issue in such a framework, which greatly hinders the detection performance.
Therefore, we further design a log-smoothing function to alleviate such issue to greatly increase the robustness of the proposed entropy-based uncertainty measure.
Through comprehensive experiments on various datasets and architectures, our proposed variational Dirichlet framework with entropy-based uncertainty measure is consistently observed to yield signiﬁcant improvements over many baseline systems.
I NTRODUCTION
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 classiﬁcation (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-conﬁdent predictions.
Such overconﬁdence 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 conﬁdence 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 conﬁdence 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 conﬁdence measure.
These methods though achieve signiﬁcant results on out-of-distribution detection tasks, they conﬂate 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 speciﬁcally, 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,
[Figure]
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 ﬁrst view the label-wise distribution p ( x ) as a K-dimensional variable z generated from a higher-order distribution P ( z ) over the simplex S k , 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-conﬁdence 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 signiﬁcant 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 classiﬁcation problem and deﬁne a higher-order uncertainty measure.
• We identify the over-concentration issue in our Dirichlet framework and propose a smoothing method to alleviate such problem.
M ODEL
In this paper, we particularly consider the image classiﬁcation 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 ∈ R k : (cid:80) ki
=
z i = 1 } lying on a K-dimensional simplex S k , 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 S k is itself a categorical distribution over different classes.
The high-order distribution is described by the probability over such simplex S k , which describes the underlying factory to generate such categorical distributions.
By studying the statistical properties of distribution P ( z ) , we are able to quantitatively measure the higher-order uncertainty conveyed by the prediction.
Here we consider a Bayesian inference with a given dataset D containing data pairs ( x, y ) and show the plate model in Figure 2, where x carries the seen information from input data (images), y is unknown at test time, and z is latent variable.
Thus, the ”true” posterior distribution can be viewed as P ( z ) =
p ( z | y ) given the ground truth y , which we are interested in.
During test time, we can only get access to the input data x and use p ( z | x ) to infer the latent variable z .
Therefore, we hope to align an approximate posterior model p θ ( z | x ) with ”true” posterior p ( z | y ) given a pairwise input ( x, y ) by minimizing their KL-divergence D KL ( p θ ( z | x ) || p ( z | y )) .
With the amortized posterior p θ ( z | x ) , we can predict the distribution over the latent variable z on an unseen image x ∗ without label y and quantitatively study its statistical properties to compute higher-order uncertainty.
[Figure]
In order to minimize such objective, we leverage the variational inference framework by decomposing D KL ( p θ ( z | x ) || p ( z | y )) into two components as follows (details in appendix):
[Equation]
where L ( θ ) is better known as the variational evidence lower bound, and log p ( y ) is the marginal likelihood over the label y .
[Equation]
Since the marginal distribution p ( y ) is constant w.r.t θ , minimizing the
KL-divergence D KL ( 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:
[Equation]
where α is the concentration parameter of the Dirichlet distribution and B ( α )
= (cid:81)
Ki Γ( α i ) Γ( (cid:80)
ki α 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:
[Equation]
However, it is in general difﬁcult 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 also a Dirichlet distribution Dir (ˆ α ) with concentration parameters
ˆ α and speciﬁcally talk about three intuitive prior functions in Figure 3.
The ﬁrst uniform prior aggressively pushes all dimensions
[Figure]
[Equation]
[Figure]
[Equation]
[Figure]
[Equation]
[Figure]
Class 1 Class 2 Class 3 Class 4 Class    4.
Category
GroundtruthPreserving
Class 1 Class 2 Class 3 Class 4 Class  5.
Category
Prediction Preserving
Class 1 Class 2 Class 3 Class 4 Class
[Figure]
towards 1, while the prediction-preserving and groundtruth-preserving is less strict by copying value from certain dimension of α to unbind certain dimension from the KL-divergence computation.
The *-preserving prior gives model one dimension of freedom in concentration parameter α .
Given the prior concentration parameter ˆ α , we can obtain a closed-form solution for the evidence lower bound as follows:
[Equation]
[Equation]
where α 0 is the sum of concentration parameter α over K dimensions, Γ 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 ∂α (cid:12) α · ∂f θ ( x ) ∂θ , where (cid:12) is the Hardamard product and ∂f θ ( x ) ∂θ is the Jacobian matrix.
In practice, we parameterize Dir ( z | α ) via a neural network 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:
[Equation]
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 classiﬁcation evidence:
[Equation]
Therefore, we can use the maximum α ’s index as the model prediction class during inference ˆ y = arg max i p ( y = i | x ) = arg max i α i .
U NCERTAINTY M EASURE
After optimization, we obtain a parametric Dirichlet function p θ ( z | α ) and compute its entropy E as the higher-order uncertainty measure.
Formally, we write the such metric as follows:
[Equation]
where α is computed via the deep neural network f θ ( x ) , and α 0 is the sum of α over K dimensions.
Here we use negative of entropy as the conﬁdence score C ( α ) .
By investigating the magnitude distribution of concentration parameter α for in-distribution test cases, we can see that α is either adopting the prior α = 1 . 0 or adopting a very large value α (cid:29) 1 . 0 .
In order words, the Dirichlet distribution is heavily concentrated at a corner of the simplex regardless of whehter the inputs are from out-domain region.
Concretely, the model holds very strong belief about what the form of output distribution p ( y | x ) on unseen test cases, which makes the model very sensitive to outof-distribution examples and leads to compromised detection accuracy.
Therefore, we propose to smooth the concentration parameters α to decrease model’s conﬁdence for better separating in- and out-of-distribution data.
Concentration smoothing In order to construct a more robust measure for better separating inand out-of-distribution samples, we adopt the log-scaling function ˆ α = log( α + 1) to calibrate the concentration α and obtain the smoothed conﬁdence score C (ˆ α ) .
By plotting the histogram of concentration magnitude before and after log-scaling in Figure 4, we can observe a very strong smoothing effect where the Dirichlet concentration parameters α are more evenly distributed.
We also demonstrate the histogram of conﬁdence score for in- and out-of-distribution samples before and after log-scaling in Figure 4, we can see the two distributions are better separated with the more robust uncertainty measure.
In the experimental section, we also compare different smoothing functions to discuss its impact on ﬁnal detection accuracy.
Smoothing
[Table]
Input Perturbation Inspired by fast gradient sign method (Goodfellow et al., 2014), we propose to add perturbation in the data before feeding into neural networks:
[Equation]
where the parameter (cid:15) denotes the magnitude of the perturbation, and ( x, y ) denotes the input-label data pair.
Here, similar to Liang et al.
our goal is also to improve the entropy score of any given input by adding belief to its own prediction.
Here we make a more practical assumption that we have no access to any form of out-of-distribution data.
Therefore, we stick to a rule-of-thumb value (cid:15) = 0 .
01 throughout our experiments.
Detection For each input x , we ﬁrst use input perturbation to obtain ˆ x , then we feed it into neural network f θ (ˆ x ) to compute the concentration α , ﬁnally we use log-scaling to calibrate α and compute
C (ˆ α ) .
Speciﬁcally, we compare the conﬁdence C (ˆ α ) to the threshold δ and say that the data x follows in-distribution if the conﬁdence score C (ˆ α ) is above the threshold and that the data x follows out-of-distribution, otherwise.
E XPERIMENTS
In order to evaluate our variational Dirichlet method on out-of-distribution detection, we follow the previous paper (Hendrycks & Gimpel, 2016; Liang et al., 2017) to replicate their experimental setup.
Throughout our experiments, a neural network is trained on some in-distribution datasets to distinguish against the out-of-distribution examples represented by images from a variety of unrelated datasets.
For each sample fed into the neural network, we will calculate the Dirichlet entropy based on the output concentration α , which will be used to predict which distribution the samples come from.
Finally, several different evaluation metrics are used to measure and compare how well different detection methods can separate the two distributions.
4. I N - DISTRIBUTION AND O UT - OF - DISTRIBUTION DATASET
These datasets
are
all available
in
Github 1 .
• In-distribution: CIFAR10/100 (Krizhevsky & Hinton, 2009) and SVHN (Netzer et al., 2011), which are both comprised of RGB images of 32 × 32 pixels.
• Out-of-distribution: TinyImageNet (Deng et al., 2009), LSUN (Yu et al., 2015) and iSUN (Xiao et al., 2010), these images are resized to 32 × 32 pixels to match the in-distribution images.
Before reporting the out-of-distribution detection results, we ﬁrst measure the classiﬁcation accuracy of our proposed method on the two in-distribution datasets in Table 1, from which we can observe that our proposed algorithm has minimum impact on the classiﬁcation accuracy.
4. T RAINING D ETAILS
In order to make fair comparisons with other out-of-distribution detectors, we follow the same setting of Liang et al.
(2017); Zagoruyko & Komodakis (2016); DeVries & Taylor (2018)
; Shalev et al.
(2018) to separately train WideResNet (Zagoruyko & Komodakis, 2016) (depth=16 and widening factor=8 for SVHN, depth=28 and widening factor=10 for CIFAR100), VGG13 (Simonyan & Zisserman, 2014), and ResNet18 (He et al., 2016) models on the in-distribution datasets.
All models are trained using stochastic gradient descent with Nesterov momentum of 0.9, and weight decay with 5e-4.
We train all models for 200 epochs with 128 batch size.
We initialize the learning with 0. and reduced by a factor of 5 at 60th, 120th and 180th epochs.
we cut off the gradient norm by 1 to prevent from potential gradient exploding error.
We save the model after the classiﬁcation accuracy on validation set converges and use the saved model for out-of-distribution detection.
4. E XPERIMENTAL R ESULTS
We measure the quality of out-of-distribution detection using the established metrics for this task (Hendrycks & Gimpel, 2016; Liang et al., 2017; Shalev et al., 2018).
(1) FPR at 95% TPR (lower is better): Measures the false positive rate (FPR) when the true positive rate (TPR) is equal to 95%.
(2) Detection Error (lower is better): Measures the minimum possible misclassiﬁcation probability deﬁned by min δ { 0 .
5 P in ( f ( x ) ≤ δ ) + 0 .
5 P out ( f ( x ) > δ ) } .
(3) AUROC (larger is better): Measures the Area Under the Receiver Operating Characteristic curve.
The Receiver Operating Characteristic (ROC) curve plots the relationship between TPR and FPR.
(4) AUPR (larger is better): Measures the Area Under the Precision-Recall (PR) curve, where AUPR-In refers to using in-distribution as positive class and AUPR-Out refers to using out-of-distribution as positive class.
[Table]
We report our VGG13’s performance in Table 2 and ResNet/WideResNet’s performance in Table 3 under groundtruth-preserving prior, where we list the performance of Baseline Hendrycks & Gimpel (2016), ODIN Liang et al.
Bayesian Neural Network (Gal, 2016) 2 , SemanticRepresentation (Shalev et al., 2018) and Learning-Conﬁdence (DeVries & Taylor, 2018).
The results in both tables have shown remarkable improvements brought by our proposed variational Dirichlet framework.
For CIFAR datasets, the achieved improvements are very remarkable, however, the FPR score on CIFAR100 is still unsatisfactory with nearly half of the out-of-distribution samples being
[Table]
[Figure] [Table] [Figure] [Table]
[Figure]
[Table] wrongly detected. For the simple SVHN dataset, the current algorithms already achieve close-toperfect results, therefore, the improvements brought by our algorithm is comparatively minor.
4. A BLATION S TUDY
In order to individually study the effectiveness of our proposed methods (entropy-based uncertainty measure, concentration smoothing, and input perturbation)
[Figure]
we design a series of ablation experiments in Figure 5.
From which, we could observe that concentration smoothing has a similar inﬂuence as input perturbation, the best performance is achieved when combining these two methods.
[Figure]
Here we mainly experiment with four different priors and depict our observations in Figure 6.
From which, we can observe that the non-informative uniform prior is too strong assumption in terms of regularization, thus leads to inferior detection performances.
In comparison, giving model one dimension of freedom is a looser assumption, which leads to generally better detection accuracy.
Among these two priors, we found that preserving the groundtruth information can generally achieve slightly better performance, which is used through our experiments.
We also investigate the impact of different smoothing functions on the out-of-distribution detection accuracy.
For smoothing functions, we mainly consider the following function forms: √ x , 3 √ x , log (1 + x ) , x , x 2 , Sigmoid ( x ) and SoftSign ( x ) .
Here we use Sigmoid ( x ) , SoftSign ( x ) (range= [0 , 1] ) as baseline to investigate the impact of the range of smoothing function on the de- [Figure]
tection accuracy, and use x, x 2 as baseline to investigate the impact of compression capability of smoothing function on the detection accuracy.
From Figure [Figure] we can observe that the ﬁrst three smoothing functions greatly outperforms the baseline functions. Therefore
[Figure]
we can conclude that the smoothing function should adopt two important characteristics: 1) the smoothing function should not be bounded, i
[Figure] e. the range should be [0 , ∞ ] . 2) the large values should be compressed [Figure]
[Figure]
R ELATED W ORK
The novelty detection problem (Pimentel et al., 2014) has already a long-standing research topic in traditional machine learning community, the previous works (Vincent & Bengio, 2003; Ghoting et al., 2008; Schlegl et al., 2017) have been mainly focused on low-dimensional and speciﬁc tasks.
Their methods are known to be unreliable in high-dimensional space.
Recently, more research works about detecting an anomaly in deep learning have been proposed like Akcay et al.
(2018), which combines the ability of deep networks to extract a progressively rich representation of data with the one-class objective of creating a tight envelope around normal data.
Another line of research is Bayesian Networks (Gal & Ghahramani, 2016; 2015; Gal, 2016; Kingma et al., 2015), which are powerful in providing stochasticity in deep neural networks by assuming the weights are stochastic.
However, Bayesian Neural Networks’ uncertainty measure like variational ratio and mutual information rely on Monte-Carlo estimation, where the networks have to perform forward passes many times, which greatly reduces the detection speed.
Instead of modeling the weight uncertainty in deep neural networks, our method directly models randomness of output neuron with
Dirichlet distribution, which arrives in closed-form uncertainty measure and bypasses the cost of
Monte-Carlo sampling.
C ONCLUSION
In this paper, we aim at ﬁnding an effective way for deep neural networks to express their uncertainty over their output distribution.
Our variational Dirichlet framework is empirically demonstrated to yield better results, but its detection accuracy on a more challenging setup like CIFAR100 is still very compromised.
We conjecture that better prior Dirichlet distribution or smoothing function could help further improve the performance.
In the future work, we plan to apply our method to broader applications like natural language processing tasks or speech recognition tasks.
Appendices A D ERIVATION
Here we want to approximate the parameterized function towards to true distribution over latent variable z , which we write as:
[Equation]
B D ETAILED D ATASET
• CIFAR10/100 (in-distribution): The CIFAR-10 and CIFAR100 dataset (Krizhevsky & Hinton, 2009) consists of RGB images of 32 × 32 pixels.
Each image is classiﬁed into 10/100 classes, such as dog, cat, automobile, or ship.
The training split for both datasets is comprised of 50, images, while the test split is comprised of 10,000 images.
• SVHN (in-distribution):
The Street View Housing Numbers (SVHN) dataset (Netzer et al., 2011) consists of colored housing number pictures ranging from 0 to 9.
Images are also with a resolution of 32 × 32 .
The ofﬁcial training split is comprised of 73,257 images, and the test split is comprised of 26,032 images.
• TinyImageNet (out-of-distribution): The TinyImageNet dataset2 is a subset of the ImageNet dataset (Deng et al., 2009).
The test set for TinyImageNet contains 10,000 images from 200 different classes for creating the out-of-distribution dataset, it contains the original images, downsampled to 32 × 32 pixels.
• LSUN (out-of-distribution):
The Large-scale Scene UNderstanding dataset (LSUN) (Yu et al., 2015) has a test set consisting of 10,000 images from 10 different scene classes, such as bedroom, church, kitchen, and tower.
We downsample LSUN’s original image and create 32 ×images as an out-of-distribution dataset.
• iSUN
(out-of-distribution): The iSUN dataset (Xiao et al., 2010) is a subset of the SUN dataset, containing 8,925 images.
All images are downsampled to 32 × 32 pixels.
C E FFECTS ON KL- DIVERGENCE
Here we investigate the impact of KL-divergence in terms of both classiﬁcation accuracy and detection errors.
By gradually increasing the weight of KL loss (increasing the balancing factor η fromto 10), we plot their training loss curve in Figure 8.
With a too strong KL regularization, the model’s classiﬁcation accuracy will decrease signiﬁcantly.
As long as η is within a rational range, the classiﬁcation accuracy will become stable.
For detection error, we can see from Figure 8 that adopting either too large value or too small value can lead to compromised performance.
For the very small value η → 0 , the variational Dirichlet framework degrades into a marginal log-likelihood, where the concentration parameters are becoming very erratic and untrustworthy uncertainty measure without any regularization.
For larger η > 1 , the too strong regularization will force both in- and outof-distribution samples too close to prior distribution, thus erasing the difference between in- and out-of-distribution becomes and leading to worse detection performance.
We ﬁnd that adopting a hyper-parameter of η = 0 .
01 can balance the stability and detection accuracy.
[Figure]
[Figure]
D R ESULTS ON CIFAR
Here we particularly investigate the out-of-distribution detection results of our model on CIFAR under different scenarios.
Our experimental results are listed in Table 4.
Model
OODMethod
FPR
Detection
AUROC
AUPR
AUPR Dataset (TPR=0.95)
Error
In
Out
WideResNet iSUN
Baseline 82.
[Table]