{'fraction_non_alphanumeric': 0.034511784511784514, 'fraction_numerical': 0.017770295548073325, 'mean_word_length': 4.79880694143167, 'pattern_counts': {'":': 0, '<': 0, '<?xml version=': 0, '>': 0, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
Efficient variational Bayesian neural network ensembles for outlier detection

In this work we perform outlier detection using ensembles of neural networks obtained by variational approximation of the posterior in a Bayesian neural network setting. The variational parameters are obtained by sampling from the true posterior by gradient descent. We show our outlier detection results are comparable to those obtained using other efficient ensembling methods.


INTRODUCTION AND RELATED WORK
In this work we use posterior sampling by gradient descent in order to estimate the parameters of a variational approximation of the true posterior. This allows us to create an ensemble of networks that we use to perform outlier detection. We show that our method achieves better results than other efficient ensembling methods, though worse than standard ensembles. Our work is inspired by a mix of scalable ways to perform Bayesian deep learning (Graves (2011); Blundell et al. (2015); Hernández-Lobato & Adams (2015); Gal & Ghahramani (2015); McClure & Kriegeskorte (2016)), the use of ensembles to improve accuracy and obtain uncertainty estimates of the network's predictions (Zhou et al. (2002); Lakshminarayanan et al. (2016)), and the ability to sample from the true posterior using stochastic gradient descent-like techniques (Welling & Teh (2011); Teh et al. (2016)). We use these samples to obtain a variational approximation of the true posterior, which can then be used to generate an ensemble of networks. We take inspiration from Huang et al. (2016), where weight samples are taken along the optimization trajectory, and used as an ensemble at test time. Instead, we take weight samples and use them to incrementally estimate the parameters of a variational approximation to the posterior during training, which allows us to sample from a distribution over weights while keeping constant memory requirements.
In Lakshminarayanan et al. (2016), the authors train N independent networks from scratch (with respective uncertainty estimates for regression) and use the ensemble to obtain good uncertainty estimates and classification performance. We view this model as an upper bound on how good our model can be, since the goal is to achieve similarly good results training only a single network.
This work is most comparable to Dropout-MC (Gal & Ghahramani (2015)) and other Dropoutrelated methods (McClure & Kriegeskorte (2016)). This is because only a single network is trained and the ensembles are only created for testing.

VARIATIONAL BAYES
In Bayesian inference we are interested in evaluating the predictive distribution where p(w|D) = p(D|w)p(w)/p(D) is the posterior over the weights, is the training data, p(D|w) is the model likelihood, parametrized by a neural network with e.g. a softmax or Gaussian output, and p(w) is the prior. In order to evaluate the integral above we first find an approximate posterior q θ (w), where θ are the parameters of q (for example, if q is Gaussian, θ = (µ, σ)) and then use use Monte-Carlo samples from this posterior to obtain an ensemble that can be used to estimate (1). In variational approximations the optimal parameters θ * are usually found by minimizing the KL-divergence between the approximate and the true posterior. However, this form underestimates the variance of the posterior, hence its uncertainty. Since we are interested in a robust estimate of the uncertainty, we instead minimize the forward KL-divergence: Using a diagonal Gaussian as approximate posterior, where D is a constant, the minimization with respect to µ and σ 2 yields This shows the optimal approximate weight means and variances are simply the first and second moments of the weights over the posterior distribution. In order to sample from the intractable posterior distribution of the weights without additional computation or memory requirements besides the standard stochastic gradient descent calculations, we can use Stochastic Gradient Lagevin Dynamics (SGLD) (Welling & Teh (2011);Teh et al. (2016)). We use the trajectory of the weights through parameter space during training as samples from the unnormalized posterior p(D|w)p(w), and compute µ and σ 2 using the standard unbiased Monte-Carlo estimatesμ = S s w (s) /S and Due to the large number of parameters in a neural network, storing all the samples (one per mini-batch step) would be too memory expensive. Instead we use the incremental formulas for computingμ andσ 2 from Welford (1962). This incremental estimation reduces the memory requirements to a minimum since we only have to store a single set of parameters during training. We can use this method as long as our training trajectory works as a valid sampling procedure, i.e, w (s) ∼ p(D|w)p(w)/Z, which is guaranteed by SGLD.

ENSEMBLES AND OUTLIER DETECTION
At test time, we sample weights from q θ (w) in order to obtain a neural network ensemble and calculate the predictive probability using a Monte-Carlo estimate of (1). The ensemble is used to calculate an uncertainty score of the prediction. We use disagreement as defined by Lakshminarayanan et al. (2016) as uncertainty measure. The disagreement is defined as the sum of the KL-divergence between the average ensemble prediction and each ensemble component. We use the calculated disagreement to perform outlier detection. Therefore, we calculate the mean µ(d train ) and standard deviation σ(d train ) of the disagreement d train for a random training batch. A given sample is labelled as an outlier by thresholding: Here, the addition of 3σ(d train ) to the threshold is used to minimize the false positive rate.

EXPERIMENTS AND RESULTS
In the experiments we used a 3-layer fully-connected neural network with 200 hidden units per layer and 10-unit softmax output, and a standard Gaussian prior. We trained on the MNIST dataset and run outlier detection on the MNIST (LeCun et al. (1998)) and notMNIST (Bulatov (2011)) test sets. The networks were trained with a batch size of 100 for 1000 steps. We compare our method against Dropout-MC (Gal & Ghahramani (2015)) and standard ensembles (Lakshminarayanan et al. (2016)) where each network is trained from scratch. Experiments with Snapshot Ensembles (Huang et al. (2016)) and fully factorized variational inference were run but did not yield good performances.
SGLD imposes some conditions on the step sizes and gradient noise (such as annealing) in order to guarantee that our procedure is a valid sampler from the true posterior. Because of this we compare our method to Dropout-MC and standard ensembles trained with the same learning rate schedule. Additionally, we introduce an intuitive approximation to SGLD using an Adam optimizer (Kingma & Ba (2014)) with added noise to the updates. The noise was scaled according to the adaptive learning rate calculated by Adam. We compare this method to Dropout-MC and standard ensembles trained with Adam. The results can be found in the appendix. All experiments 1 use a base learning rate of 0.005. We do not use any burn in or thinning when calculating the Gaussian approximation. 87.0 ± 0.6 72.9 ± 2.7 76.1 ± 0.7 Table 1 shows the classification accuracies for the different models using the SGLD learning rate schedule given the number of ensemble components. The classification performance of our method is situated between Dropout-MC and standard ensembles. However, the performance of our method does not increase with the number of components in the ensemble. Analysing the disagreement results across the ensembles shows very small disagreement. Our method shows disagreements of order 10 −3 to 10 −2 , whereas the other methods have a disagreement of 10 −1 to 10 0 . This means that the variational approximation fits a Gaussian with small variance. However, outlier detection depends on relative rather than absolute disagreement values between in-dataset samples and outof-dataset samples.
We perform outlier detection on the test set of both MNIST and notMNIST. The results for various ensemble sizes using the SGLD learning rate schedule can be seen in Fig. 1. Standard ensembles achieve the best overall performance. This can be explained by the use of different initialisations which lead to a higher variety in trained models. Our method method and Dropout-MC achieve high recall but low precision. Our method performs slightly worse than Dropout but outperforms it on the the normal MNIST classification task. Additional results using Adam are shown in the appendix.

CONCLUSION
We present an efficient method for building variational approximations of neural networks. It enables the creation of ensembles. Our method is easily adaptable to a wide range of neural network architectures, provides comparable prediction performance and only minimally increases computation and memory requirements during training. Furthermore, this method can be combined with other sampling methods and a combination with recent advances in gradient-based approximate Bayesian inference Mandt et al. (2017) is left for future work. Additionally, we propose a simple ensemble based outlier detection method which is inspired by Lakshminarayanan et al. (2016).

A RESULTS USING noisy Adam AS APPROXIMATION FOR SGLD
Here we present the results obtained by using noisy Adam as approximation for SGLD. We define the noisy Adam update as ∆θ = Adam(θ, x, y) + with ∼ N (0, α 2 t ) where ∆θ is the update of θ, Adam(θ, x, y) is the update of θ given the data points x and y according to regular Adam and is the noise added to this update. This noise is Gaussian distributed with a standard deviation of α t which is the current adaptive learning rate calculated by Adam. Table  2 shows the MNIST classification accuracy of different methods with various ensemble sizes using Adam for optimization. Standard ensembles achieve the best performance. Our method outperforms Dropout and is able to achieve a better performance for the single network 'ensemble' case. 94.6 ± 0.2 91.5 ± 0.7 93.9 ± 0.2 10 94.9 ± 0.2 91.7 ± 0.6 94.1 ± 0.1 We then performed the same outlier detection task with those methods. The results are shown in Figure 2. Again, standard ensembles perform best. However, noisy Adam outperforms Dropout-MC on both recall and precision. Additionally, the general outlier detection performance using Adam is worse than the results using the SGLD learning rate schedule.
Figure 2: Recall and precision for outlier detection using different ensembling methods and various ensemble sizes. The methods are tested on the test sets of MNIST and notMNIST (outlier). All methods show low precision and high recall. Our method is only outperformed by standard ensembles.