Variational Dropout and the Local Reparameterization Trick

Diederik P. Kingma, Tim Salimans, Max Welling

Introduction

Deep neural networks are a flexible family of models that easily scale to millions of parameters and datapoints, but are still tractable to optimize using minibatch-based stochastic gradient ascent. Due to their high flexibility, neural networks have the capacity to fit a wide diversity of nonlinear patterns in the data. This flexbility often leads to overfitting when left unchecked: spurious patterns are found that happen to fit well to the training data, but are not predictive for new data. Various regularization techniques for controlling this overfitting are used in practice; a currently popular and empirically effective technique being dropout . In it was shown that regular (binary) dropout has a Gaussian approximation called Gaussian dropout with virtually identical regularization performance but much faster convergence. In section 5 of it is shown that Gaussian dropout optimizes a lower bound on the marginal likelihood of the data. In this paper we show that a relationship between dropout and Bayesian inference can be extended and exploited to greatly improve the efficiency of variational Bayesian inference on the model parameters. This work has a direct interpretation as a generalization of Gaussian dropout, with the same fast convergence but now with the freedom to specify more flexibly parameterized posterior distributions.

Bayesian posterior inference over the neural network parameters is a theoretically attractive method for controlling overfitting; exact inference is computationally intractable, but efficient approximate schemes can be designed. Markov Chain Monte Carlo (MCMC) is a class of approximate inference methods with asymptotic guarantees, pioneered by for the application of regularizing neural networks. Later useful refinements include and .

An alternative to MCMC is variational inference or the equivalent minimum description length (MDL) framework. Modern variants of stochastic variational inference have been applied to neural networks with some succes , but have been limited by high variance in the gradients. Despite their theoretical attractiveness, Bayesian methods for inferring a posterior distribution over neural network weights have not yet been shown to outperform simpler methods such as dropout. Even a new crop of efficient variational inference algorithms based on stochastic gradients with minibatches of data have not yet been shown to significantly improve upon simpler dropout-based regularization.

In section 2 we explore an as yet unexploited trick for improving the efficiency of stochastic gradient-based variational inference with minibatches of data, by translating uncertainty about global parameters into local noise that is independent across datapoints in the minibatch. The resulting method has an optimization speed on the same level as fast dropout , and indeed has the original Gaussian dropout method as a special case. An advantage of our method is that it allows for full Bayesian analysis of the model, and that it’s significantly more flexible than standard dropout. The approach presented here is closely related to several popular methods in the literature that regularize by adding random noise; these relationships are discussed in section 4.

Efficient and Practical Bayesian Inference

We consider Bayesian analysis of a dataset D\mathcal{D}, containing a set of NN i.i.d. observations of tuples (x,y)(\mathbf{x},\mathbf{y}), where the goal is to learn a model with parameters or weights w\mathbf{w} of the conditional probability p(yx,w)p(\mathbf{y}|\mathbf{x},\mathbf{w}) (standard classification or regression)Note that the described method is not limited to classification or regression and is straightforward to apply to other modeling settings like unsupervised models and temporal models.. Bayesian inference in such a model consists of updating some initial belief over parameters w\mathbf{w} in the form of a prior distribution p(w)p(\mathbf{w}), after observing data D\mathcal{D}, into an updated belief over these parameters in the form of (an approximation to) the posterior distribution p(wD)p(\mathbf{w}|\mathcal{D}). Computing the true posterior distribution through Bayes’ rule p(wD)=p(w)p(Dw)/p(D)p(\mathbf{w}|\mathcal{D})=p(\mathbf{w})p(\mathcal{D}|\mathbf{w})/p(\mathcal{D}) involves computationally intractable integrals, so good approximations are necessary. In variational inference, inference is cast as an optimization problem where we optimize the parameters ϕ\mathbf{\phi} of some parameterized model qϕ(w)q_{\mathbf{\phi}}(\mathbf{w}) such that qϕ(w)q_{\mathbf{\phi}}(\mathbf{w}) is a close approximation to p(wD)p(\mathbf{w}|\mathcal{D}) as measured by the Kullback-Leibler divergence DKL(qϕ(w)p(wD))D_{KL}(q_{\mathbf{\phi}}(\mathbf{w})||p(\mathbf{w}|\mathcal{D})). This divergence of our posterior qϕ(w)q_{\mathbf{\phi}}(\mathbf{w}) to the true posterior is minimized in practice by maximizing the so-called variational lower bound L(ϕ)\mathcal{L}(\mathbf{\phi}) of the marginal likelihood of the data:

We’ll call LD(ϕ)L_{\mathcal{D}}(\mathbf{\phi}) the expected log-likelihood. The bound L(ϕ)\mathcal{L}(\mathbf{\phi}) plus DKL(qϕ(w)p(wD))D_{KL}(q_{\mathbf{\phi}}(\mathbf{w})||p(\mathbf{w}|\mathcal{D})) equals the (conditional) marginal log-likelihood (x,y)Dlogp(yx)\sum_{(\mathbf{x},\mathbf{y})\in\mathcal{D}}\log p(\mathbf{y}|\mathbf{x}). Since this marginal log-likelihood is constant w.r.t. ϕ\mathbf{\phi}, maximizing the bound w.r.t. ϕ\mathbf{\phi} will minimize DKL(qϕ(w)p(wD))D_{KL}(q_{\mathbf{\phi}}(\mathbf{w})||p(\mathbf{w}|\mathcal{D})).

Various algorithms for gradient-based optimization of the variational bound (eq. (1)) with differentiable qq and pp exist. See section 4 for an overview. A recently proposed efficient method for minibatch-based optimization with differentiable models is the stochastic gradient variational Bayes (SGVB) method introduced in (especially appendix F) and . The basic trick in SGVB is to parameterize the random parameters wqϕ(w)\mathbf{w}\sim q_{\mathbf{\phi}}(\mathbf{w}) as: w=f(ϵ,ϕ)\mathbf{w}=f(\mathbf{\epsilon},\mathbf{\phi}) where f(.)f(.) is a differentiable function and ϵp(ϵ)\mathbf{\epsilon}\sim p(\mathbf{\epsilon}) is a random noise variable. In this new parameterisation, an unbiased differentiable minibatch-based Monte Carlo estimator of the expected log-likelihood can be formed:

where (xi,yi)i=1M(\mathbf{x}^{i},\mathbf{y}^{i})_{i=1}^{M} is a minibatch of data with MM random datapoints (xi,yi)D(\mathbf{x}^{i},\mathbf{y}^{i})\sim\mathcal{D}, and ϵ\mathbf{\epsilon} is a noise vector drawn from the noise distribution p(ϵ)p(\mathbf{\epsilon}). We’ll assume that the remaining term in the variational lower bound, DKL(qϕ(w)p(w))D_{KL}(q_{\mathbf{\phi}}(\mathbf{w})||p(\mathbf{w})), can be computed deterministically, but otherwise it may be approximated similarly. The estimator (3) is differentiable w.r.t. ϕ\mathbf{\phi} and unbiased, so its gradient is also unbiased: ϕLD(ϕ)ϕLDSGVB(ϕ)\nabla_{\phi}L_{\mathcal{D}}(\mathbf{\phi})\simeq\nabla_{\mathbf{\phi}}L_{\mathcal{D}}^{\text{SGVB}}(\mathbf{\phi}). We can proceed with variational Bayesian inference by randomly initializing ϕ\mathbf{\phi} and performing stochastic gradient ascent on L(ϕ)\mathcal{L}(\mathbf{\phi}) (1).

2 Variance of the SGVB estimator

The theory of stochastic approximation tells us that stochastic gradient ascent using (3) will asymptotically converge to a local optimum for an appropriately declining step size and sufficient weight updates , but in practice the performance of stochastic gradient ascent crucially depends on the variance of the gradients. If this variance is too large, stochastic gradient descent will fail to make much progress in any reasonable amount of time. Our objective function consists of an expected log likelihood term that we approximate using Monte Carlo, and a KL divergence term DKL(qϕ(w)p(w))D_{KL}(q_{\mathbf{\phi}}(\mathbf{w})||p(\mathbf{w})) that we assume can be calculated analytically and otherwise be approximated with Monte Carlo with similar reparameterization.

Assume that we draw minibatches of datapoints with replacement; see appendix F for a similar analysis for minibatches without replacement. Using LiL_{i} as shorthand for logp(yixi,w=f(ϵi,ϕ))\log p(\mathbf{y}^{i}|\mathbf{x}^{i},\mathbf{w}=f(\mathbf{\epsilon}^{i},\mathbf{\phi})), the contribution to the likelihood for the ii-th datapoint in the minibatch, the Monte Carlo estimator (3) may be rewritten as LDSGVB(ϕ)=NMi=1MLiL_{\mathcal{D}}^{\text{SGVB}}(\mathbf{\phi})=\frac{N}{M}\sum_{i=1}^{M}L_{i}, whose variance is given by

where the variances and covariances are w.r.t. both the data distribution and ϵ\mathbf{\epsilon} distribution, i.e. Var[Li]=Varϵ,xi,yi[logp(yixi,w=f(ϵ,ϕ))]\text{Var}\left[L_{i}\right]=\text{Var}_{\mathbf{\epsilon},\mathbf{x}^{i},\mathbf{y}^{i}}\left[\log p(\mathbf{y}^{i}|\mathbf{x}^{i},\mathbf{w}=f(\mathbf{\epsilon},\mathbf{\phi}))\right], with xi,yi\mathbf{x}^{i},\mathbf{y}^{i} drawn from the empirical distribution defined by the training set. As can be seen from (5), the total contribution to the variance by Var[Li]\text{Var}\left[L_{i}\right] is inversely proportional to the minibatch size MM. However, the total contribution by the covariances does not decrease with MM. In practice, this means that the variance of LDSGVB(ϕ)L_{\mathcal{D}}^{\text{SGVB}}(\mathbf{\phi}) can be dominated by the covariances for even moderately large MM.

3 Local Reparameterization Trick

We therefore propose an alternative estimator for which we have Cov[Li,Lj]=0\text{Cov}\left[L_{i},L_{j}\right]=0, so that the variance of our stochastic gradients scales as 1/M1/M. We then make this new estimator computationally efficient by not sampling ϵ\mathbf{\epsilon} directly, but only sampling the intermediate variables f(ϵ)f(\mathbf{\epsilon}) through which ϵ\mathbf{\epsilon} influences LDSGVB(ϕ)L_{\mathcal{D}}^{\text{SGVB}}(\mathbf{\phi}). By doing so, the global uncertainty in the weights is translated into a form of local uncertainty that is independent across examples and easier to sample. We refer to such a reparameterization from global noise to local noise as the local reparameterization trick. Whenever a source of global noise can be translated to local noise in the intermediate states of computation (ϵf(ϵ)\mathbf{\epsilon}\rightarrow f(\mathbf{\epsilon})), a local reparameterization can be applied to yield a computationally and statistically efficient gradient estimator.

Such local reparameterization applies to a fairly large family of models, but is best explained through a simple example: Consider a standard fully connected neural network containing a hidden layer consisting of 1000 neurons. This layer receives an M×1000M\times 1000 input feature matrix A\mathbf{A} from the layer below, which is multiplied by a 1000×10001000\times 1000 weight matrix W\mathbf{W}, before a nonlinearity is applied, i.e. B=AW\mathbf{B}=\mathbf{A}\mathbf{W}. We then specify the posterior approximation on the weights to be a fully factorized Gaussian, i.e. qϕ(wi,j)=N(μi,j,σi,j2)wi,jWq_{\mathbf{\phi}}(w_{i,j})=N(\mu_{i,j},\sigma^{2}_{i,j})\hskip 2.84544pt\forall w_{i,j}\in\mathbf{W}, which means the weights are sampled as wi,j=μi,j+σi,jϵi,jw_{i,j}=\mu_{i,j}+\sigma_{i,j}\epsilon_{i,j}, with ϵi,jN(0,1)\epsilon_{i,j}\sim N(0,1). In this case we could make sure that Cov[Li,Lj]=0\text{Cov}\left[L_{i},L_{j}\right]=0 by sampling a separate weight matrix W\mathbf{W} for each example in the minibatch, but this is not computationally efficient: we would need to sample MM million random numbers for just a single layer of the neural network. Even if this could be done efficiently, the computation following this step would become much harder: Where we originally performed a simple matrix-matrix product of the form B=AW\mathbf{B}=\mathbf{A}\mathbf{W}, this now turns into MM separate local vector-matrix products. The theoretical complexity of this computation is higher, but, more importantly, such a computation can usually not be performed in parallel using fast device-optimized BLAS (Basic Linear Algebra Subprograms). This also happens with other neural network architectures such as convolutional neural networks, where optimized libraries for convolution cannot deal with separate filter matrices per example.

Fortunately, the weights (and therefore ϵ\mathbf{\epsilon}) only influence the expected log likelihood through the neuron activations B\mathbf{B}, which are of much lower dimension. If we can therefore sample the random activations B\mathbf{B} directly, without sampling W\mathbf{W} or ϵ\mathbf{\epsilon}, we may obtain an efficient Monte Carlo estimator at a much lower cost. For a factorized Gaussian posterior on the weights, the posterior for the activations (conditional on the input A\mathbf{A}) is also factorized Gaussian:

Rather than sampling the Gaussian weights and then computing the resulting activations, we may thus sample the activations from their implied Gaussian distribution directly, using bm,j=γm,j+δm,jζm,jb_{m,j}=\gamma_{m,j}+\sqrt{\delta_{m,j}}\zeta_{m,j}, with ζm,jN(0,1)\zeta_{m,j}\sim N(0,1). Here, ζ\zeta is an M×1000M\times 1000 matrix, so we only need to sample MM thousand random variables instead of MM million: a thousand fold savings.

In addition to yielding a gradient estimator that is more computationally efficient than drawing separate weight matrices for each training example, the local reparameterization trick also leads to an estimator that has lower variance. To see why, consider the stochastic gradient estimate with respect to the posterior parameter σi,j2\sigma^{2}_{i,j} for a minibatch of size M=1M=1. Drawing random weights W\mathbf{W}, we get

If, on the other hand, we form the same gradient using the local reparameterization trick, we get

Here, there are two stochastic terms: The first is the backpropagated gradient LDSGVB/bm,j\partial L_{\mathcal{D}}^{\text{SGVB}}/\partial b_{m,j}, and the second is the sampled random noise (ϵi,j\epsilon_{i,j} or ζm,j\zeta_{m,j}). Estimating the gradient with respect to σi,j2\sigma^{2}_{i,j} then basically comes down to estimating the covariance between these two terms. This is much easier to do for ζm,j\zeta_{m,j} as there are much fewer of these: individually they have higher correlation with the backpropagated gradient LDSGVB/bm,j\partial L_{\mathcal{D}}^{\text{SGVB}}/\partial b_{m,j}, so the covariance is easier to estimate. In other words, measuring the effect of ζm,j\zeta_{m,j} on LDSGVB/bm,j\partial L_{\mathcal{D}}^{\text{SGVB}}/\partial b_{m,j} is easy as ζm,j\zeta_{m,j} is the only random variable directly influencing this gradient via bm,jb_{m,j}. On the other hand, when sampling random weights, there are a thousand ϵi,j\epsilon_{i,j} influencing each gradient term, so their individual effects get lost in the noise. In appendix D we make this argument more rigorous, and in section 5 we show that it holds experimentally.

Variational Dropout

Dropout is a technique for regularization of neural network parameters, which works by adding multiplicative noise to the input of each layer of the neural network during optimization. Using the notation of section 2.3, for a fully connected neural network dropout corresponds to:

where A\mathbf{A} is the M×KM\times K matrix of input features for the current minibatch, θ\theta is a K×LK\times L weight matrix, and B\mathbf{B} is the M×LM\times L output matrix for the current layer (before a nonlinearity is applied). The \circ symbol denotes the elementwise (Hadamard) product of the input matrix with a M×KM\times K matrix of independent noise variables ξ\xi. By adding noise to the input during training, the weight parameters θ\theta are less likely to overfit to the training data, as shown empirically by previous publications. Originally, proposed drawing the elements of ξ\xi from a Bernoulli distribution with probability 1p1-p, with pp the dropout rate. Later it was shown that using a continuous distribution with the same relative mean and variance, such as a Gaussian N(1,α)N(1,\alpha) with α=p/(1p)\alpha=p/(1-p), works as well or better .

Here, we re-interpret dropout with continuous noise as a variational method, and propose a generalization that we call variational dropout. In developing variational dropout we provide a firm Bayesian justification for dropout training by deriving its implicit prior distribution and variational objective. This new interpretation allows us to propose several useful extensions to dropout, such as a principled way of making the normally fixed dropout rates pp adaptive to the data.

If the elements of the noise matrix ξ\xi are drawn independently from a Gaussian N(1,α)N(1,\alpha), the marginal distributions of the activations bm,jBb_{m,j}\in\mathbf{B} are Gaussian as well:

Making use of this fact, proposed Gaussian dropout, a regularization method where, instead of applying (9), the activations are directly drawn from their (approximate or exact) marginal distributions as given by (10). argued that these marginal distributions are exact for Gaussian noise ξ\xi, and for Bernoulli noise still approximately Gaussian because of the central limit theorem. This ignores the dependencies between the different elements of B\mathbf{B}, as present using (9), but report good results nonetheless.

As noted by , and explained in appendix B, this Gaussian dropout noise can also be interpreted as arising from a Bayesian treatment of a neural network with weights W\mathbf{W} that multiply the input to give B=AW\mathbf{B}=\mathbf{A}\mathbf{W}, where the posterior distribution of the weights is given by a factorized Gaussian with qϕ(wi,j)=N(θi,j,αθi,j2)q_{\mathbf{\phi}}(w_{i,j})=\mathcal{N}(\theta_{i,j},\alpha\theta_{i,j}^{2}). From this perspective, the marginal distributions (10) then arise through the application of the local reparameterization trick, as introduced in section 2.3. The variational objective corresponding to this interpretation is discussed in section 3.3.

2 Variational dropout with correlated weight noise

Instead of ignoring the dependencies of the activation noise, as in section 3.1, we may retain the dependencies by interpreting dropout (9) as a form of correlated weight noise:

where am\mathbf{a}^{m} is a row of the input matrix and bm\mathbf{b}^{m} a row of the output. The wi\mathbf{w}_{i} are the rows of the weight matrix, each of which is constructed by multiplying a non-stochastic parameter vector θi\theta_{i} by a stochastic scale variable sis_{i}. The distribution on these scale variables we interpret as a Bayesian posterior distribution. The weight parameters θi\theta_{i} (and the biases) are estimated using maximum likelihood. The original Gaussian dropout sampling procedure (9) can then be interpreted as arising from a local reparameterization of our posterior on the weights W\mathbf{W}.

3 Dropout’s scale-invariant prior and variational objective

The posterior distributions qϕ(W)q_{\mathbf{\phi}}(\mathbf{W}) proposed in sections 3.1 and 3.2 have in common that they can be decomposed into a parameter vector θ\theta that captures the mean, and a multiplicative noise term determined by parameters α\alpha. Any posterior distribution on W\mathbf{W} for which the noise enters this multiplicative way, we will call a dropout posterior. Note that many common distributions, such as univariate Gaussians (with nonzero mean), can be reparameterized to meet this requirement.

i.e. a prior that is uniform on the log-scale of the weights (or the weight-scales sis_{i} for section 3.2). As explained in appendix A, this prior has an interesting connection with the floating point format for storing numbers: From an MDL perspective, the floating point format is optimal for communicating numbers drawn from this prior. Conversely, the KL divergence DKL(qϕ(w)p(w))D_{KL}(q_{\mathbf{\phi}}(\mathbf{w})||p(\mathbf{w})) with this prior has a natural interpretation as regularizing the number of significant digits our posterior qϕq_{\mathbf{\phi}} stores for the weights wi,jw_{i,j} in the floating-point format.

Putting the expected log likelihood and KL-divergence penalty together, we see that dropout training maximizes the following variatonal lower bound w.r.t. θ\theta:

where we have made the dependence on the θ\theta and α\alpha parameters explicit. The noise parameters α\alpha (e.g. the dropout rates) are commonly treated as hyperparameters that are kept fixed during training. For the log-uniform prior this then corresponds to a fixed limit on the number of significant digits we can learn for each of the weights wi,jw_{i,j}. In section 3.4 we discuss the possibility of making this limit adaptive by also maximizing the lower bound with respect to α\alpha.

For the choice of a factorized Gaussian approximate posterior with qϕ(wi,j)=N(θi,j,αθi,j2)q_{\mathbf{\phi}}(w_{i,j})=\mathcal{N}(\theta_{i,j},\alpha\theta_{i,j}^{2}), as discussed in section 3.1, the lower bound (12) is analyzed in detail in appendix C. There, it is shown that for this particular choice of posterior the negative KL-divergence DKL(qα(w)p(w))-D_{KL}(q_{\alpha}(\mathbf{w})||p(\mathbf{w})) is not analytically tractable, but can be approximated extremely accurately using

The same expression may be used to calculate the corresponding term DKL(qα(s)p(s))-D_{KL}(q_{\alpha}(\mathbf{s})||p(\mathbf{s})) for the posterior approximation of section 3.2.

4 Adaptive regularization through optimizing the dropout rate

The noise parameters α\alpha used in dropout training (e.g. the dropout rates) are usually treated as fixed hyperparameters, but now that we have derived dropout’s variational objective (12), making these parameters adaptive is trivial: simply maximize the variational lower bound with respect to α\alpha. We can use this to learn a separate dropout rate per layer, per neuron, of even per separate weight. In section 5 we look at the predictive performance obtained by making α\alpha adaptive.

We found that very large values of α\alpha correspond to local optima from which it is hard to escape due to large-variance gradients. To avoid such local optima, we found it beneficial to set a constraint α1\alpha\leq 1 during training, i.e. we maximize the posterior variance at the square of the posterior mean, which corresponds to a dropout rate of 0.50.5.

Related Work

Pioneering work in practical variational inference for neural networks was done in , where a (biased) variational lower bound estimator was introduced with good results on recurrent neural network models. In later work it was shown that even more practical estimators can be formed for most types of continuous latent variables or parameters using a (non-local) reparameterization trick, leading to efficient and unbiased stochastic gradient-based variational inference. These works focused on an application to latent-variable inference; extensive empirical results on inference of global model parameters were reported in , including succesful application to reinforcement learning. These earlier works used the relatively high-variance estimator (3), upon which we improve. Variable reparameterizations have a long history in the statistics literature, but have only recently found use for efficient gradient-based machine learning and inference . Related is also probabilistic backpropagation , an algorithm for inferring marginal posterior probabilities; however, it requires certain tractabilities in the network making it insuitable for the type of models under consideration in this paper.

As we show here, regularization by dropout can be interpreted as variational inference. DropConnect is similar to dropout, but with binary noise on the weights rather than hidden units. DropConnect thus has a similar interpretation as variational inference, with a uniform prior over the weights, and a mixture of two Dirac peaks as posterior. In , standout was introduced, a variation of dropout where a binary belief network is learned for producing dropout rates. Recently, proposed another Bayesian perspective on dropout. In recent work , a similar reparameterization is described and used for variational inference; their focus is on closed-form approximations of the variational bound, rather than unbiased Monte Carlo estimators. and also investigate a Bayesian perspective on dropout, but focus on the binary variant. reports various encouraging results on the utility of dropout’s implied prediction uncertainty.

Experiments

We compare our method to standard binary dropout and two popular versions of Gaussian dropout, which we’ll denote with type A and type B. With Gaussian dropout type A we denote the pre-linear Gaussian dropout from ; type B denotes the post-linear Gaussian dropout from . This way, the method names correspond to the matrix names in section 2 (A\mathbf{A} or B\mathbf{B}) where noise is injected. Models were implemented in Theano , and optimization was performed using Adam with default hyper-parameters and temporal averaging.

Two types of variational dropout were included. Type A is correlated weight noise as introduced in section 3.2: an adaptive version of Gaussian dropout type A. Variational dropout type B has independent weight uncertainty as introduced in section 3.1, and corresponds to Gaussian dropout type B.

A de facto standard benchmark for regularization methods is the task of MNIST hand-written digit classification. We choose the same architecture as : a fully connected neural network with 3 hidden layers and rectified linear units (ReLUs). We follow the dropout hyper-parameter recommendations from these earlier publications, which is a dropout rate of p=0.5p=0.5 for the hidden layers and p=0.2p=0.2 for the input layer. We used early stopping with all methods, where the amount of epochs to run was determined based on performance on a validation set.

We start out by empirically comparing the variance of the different available stochastic estimators of the gradient of our variational objective. To do this we train the neural network described above for either 10 epochs (test error 3%) or 100 epochs (test error 1.3%), using variational dropout with independent weight noise. After training, we calculate the gradients for the weights of the top and bottom level of our network on the full training set, and compare against the gradient estimates per batch of M=1000M=1000 training examples. Appendix E contains the same analysis for the case of variational dropout with correlated weight noise.

Table 1 shows that the local reparameterization trick yields the lowest variance among all variational dropout estimators for all conditions, although it is still substantially higher compared to not having any dropout regularization. The 1/M1/M variance scaling achieved by our estimator is especially important early on in the optimization when it makes the largest difference (compare weight sample per minibatch and weight sample per data point). The additional variance reduction obtained by our estimator through drawing fewer random numbers (section 2.3) is about a factor of 2, and this remains relatively stable as training progresses (compare local reparameterization and weight sample per data point).

We compared the regular SGVB estimator, with separate weight samples per datapoint with the efficient estimator based on local reparameterization, in terms of wall-clock time efficiency. With our implementation on a modern GPU, optimization with the naïve estimator took 1635 seconds per epoch, while the efficient estimator took 7.4 seconds: an over 200 fold speedup.

Figure 1 shows test-set classification error for the tested regularization methods, for various choices of number of hidden units. Our adaptive variational versions of Gaussian dropout perform equal or better than their non-adaptive counterparts and standard dropout under all tested conditions. The difference is especially noticable for the smaller networks. In these smaller networks, we observe that variational dropout infers dropout rates that are on average far lower than the dropout rates for larger networks. This adaptivity comes at negligable computational cost.

We found that slightly downscaling the KL divergence part of the variational objective can be beneficial. Variational (A2) in figure 1 denotes performance of type A variational dropout but with a KL-divergence downscaled with a factor of 3; this small modification seems to prevent underfitting, and beats all other dropout methods in the tested models.

Conclusion

Efficiency of posterior inference using stochastic gradient-based variational Bayes (SGVB) can often be significantly improved through a local reparameterization where global parameter uncertainty is translated into local uncertainty per datapoint. By injecting noise locally, instead of globally at the model parameters, we obtain an efficient estimator that has low computational complexity, can be trivially parallelized and has low variance. We show how dropout is a special case of SGVB with local reparameterization, and suggest variational dropout, a straightforward extension of regular dropout where optimal dropout rates are inferred from the data, rather than fixed in advance. We report encouraging empirical results.

We thank the reviewers and Yarin Gal for valuable feedback. Diederik Kingma is supported by the Google European Fellowship in Deep Learning, Max Welling is supported by research grants from Google and Facebook, and the NWO project in Natural AI (NAI.14.108).

References

Appendix A Floating-point numbers and compression

The floating-point format is by far the most common number format used for model parameters in neural network type models. The absolute value of floating-point numbers in base 2 equals sign(s/2p1)2e\text{\emph{sign}}\cdot(s/2^{p-1})\cdot 2^{e} where ss is the mantissa with pp bits and ee is the exponent, both non-negative integer-valued. For random bit patterns for ss and ee, floating point numbers closely follow a log-uniform distribution with finite range. The floating-point format is thus close to optimal, from a compression point of view, for communicating parameters for which the receiver has a log-uniform prior distribution, with finite range, over the magnitude of parameters. Specifically, this prior for each individual floating-point parameter wjw_{j} is p(logwj)=U(interval)p(\log|w_{j}|)=\mathcal{U}(\text{interval}), where the interval is approximately (log(28),log(28))(\log(2^{-8}),\log(2^{8})) for single-point precision and (log(211),log(211))(\log(2^{-11}),\log(2^{11})) for double-precision floating-point numbers in the most common IEEE specification.

The KL-divergence between a variational posterior qϕq_{\mathbf{\phi}} (eq. (1)) and this log-uniform prior is relatively simple: it equals the entropy under qϕq_{\mathbf{\phi}} of the log-transformed magnitude of w\mathbf{w} plus a constant:

This divergence has a natural interpretation as controlling the number of significant digits under qϕq_{\mathbf{\phi}} of the corresponding floating-point number.

Appendix B Derivation of dropout’s implicit variational posterior

In the common version of dropout , linear operations bi=aiW\mathbf{b}^{i}=\mathbf{a}^{i}\mathbf{W} in a model, where ai\mathbf{a}^{i} is a column vector that is the result of previous operations on the input for datapoint ii, are replaced by a stochastic operation:

where column vector ai\mathbf{a}^{i} is the result of previous operations on the input for datapoint ii. Expected values and variance w.r.t. the dropout rate are:

The expected value and variance for the elements of the resulting vector bi\mathbf{b}^{i} are:

Thus, ignoring dependencies between elements of bi\mathbf{b}^{i}, dropout can be approximated by a Gaussian :

where (.)2(.)^{2}, (.)\sqrt{(}.) and \odot are again component-wise operations.

B.2 Weight uncertainty

Equivalently, the Gaussian dropout relationship p(biai,W)p(\mathbf{b}^{i}|\mathbf{a}^{i},W) can be parameterized as weight uncertainty:

In the main text, we show how we can treat the distribution over weights p(VjkWjk,αjk)p(V_{jk}|W_{jk},\alpha_{jk}) as a variational posterior qϕq_{\mathbf{\phi}}, which we can optimize w.r.t. each αjk\alpha_{jk} (the dropout rate for individual parameters) to optimize a bound on the marginal likelihood of the data.

Appendix C Negative KL-divergence for the log-uniform prior

The variational lower bound (1) that we wish to optimize is given by

where LD(ϕ)L_{\mathcal{D}}(\mathbf{\phi}) is the expected log likelihood term which we approximate using Monte Carlo, as discussed in section 2.3. Here we discuss how to deterministically compute the negative KL divergence term DKL(qϕ(w)p(w))-D_{KL}(q_{\mathbf{\phi}}(\mathbf{w})||p(\mathbf{w})) for the log-uniform prior proposed in section B. For simplicity we only discuss the case of factorizing approximate posterior qϕ(w)=i=1kqϕ(wi)q_{\mathbf{\phi}}(\mathbf{w})=\prod_{i=1}^{k}q_{\mathbf{\phi}}(w_{i}), although the extension to more involved posterior approximations is straight forward.

Our log-uniform prior p(wi)p(w_{i}) (appendix A) consists of a Bernoulli distribution on the sign bit si{1,+1}s_{i}\in\{-1,+1\} which captures the sign of wiw_{i}, combined with a uniform prior on the log-scale of wiw_{i}:

For an approximate posterior qϕ(wi)q_{\mathbf{\phi}}(w_{i}) with support on the real line, the KL divergence will thus consist of two parts: the KL-divergence between the posterior and prior on the sign bit sis_{i} and the KL-divergence between the conditional posterior and prior on the log scale log(wi)\log(|w_{i}|).

The negative KL divergence between the posterior and prior on the sign bit is given by:

with Qϕ(0)Q_{\phi}(0) the posterior CDF of wiw_{i} evaluated at 0, i.e. the probability of drawing a negative weight from our approximate posterior.

The negative KL divergence of the second part (the log-scale) is then

where qϕ(wi)/Qϕ(0)q_{\mathbf{\phi}}(w_{i})/Q_{\phi}(0) is the truncation of our approximate posterior to the negative part of the real-line, and the log(wi)\log(|w_{i}|) term enters through transforming the uniform prior from the log-space to the normal space.

Putting both parts together the terms involving the CDF Qϕ(0)Q_{\phi}(0) cancel, and we get:

where H(qϕ(wi))\mathcal{H}(q_{\mathbf{\phi}}(w_{i})) is the entropy of our approximate posterior.

We now consider the special case of a dropout posterior, as proposed in section 3, which we defined as any approximate posterior distribution qϕ(wi)q_{\mathbf{\phi}}(w_{i}) for which the weight noise is multiplicative:

Assuming qα(ϵi)q_{\alpha}(\epsilon_{i}) is a continuous distribution, this choice of posterior gives us

where the last term can be understood as the log jacobian determinant of a linear transformation of the random variable ϵi\epsilon_{i}.

Taking (40) and (41) together, the terms depending on θ\theta thus cancel exactly, proving that the KL divergence between posterior and prior is indeed independent of these parameters:

In fact, the log-uniform prior is the only prior consistent with dropout. If the prior had any additional terms involving wiw_{i}, their expectation w.r.t. qϕq_{\mathbf{\phi}} would not cancel with the entropy term in DKL[qϕ(wi)p(wi)]-D_{KL}[q_{\mathbf{\phi}}(w_{i})|p(w_{i})].

For the specific case of Gaussian dropout, as proposed in section 3, we have qα(ϵi)=N(1,α)q_{\alpha}(\epsilon_{i})=N(1,\alpha). This then gives us

Appendix D Variance reduction of local parameterization compared to separate weight samples

In section 2.3 we claim that our local reparameterization not only is more computationally efficient than drawing separate weight matrices for each training example, but that it also leads to an estimator that has lower variance. To see why, consider the stochastic gradient estimate with respect to the posterior parameter σi,j2\sigma^{2}_{i,j} for a minibatch of size M=1M=1. Drawing random weights W\mathbf{W} to form the estimate, we get

If, on the other hand, we form the same gradient using the local reparameterization trick, we get

We can decompose the variance of these estimators as

Here, the first term is identical for both gradient estimators, but the second term is not. When drawing separate weight matrices per training example, it is

with q=(bm,jγm,j)2am,i4/4q=(b_{m,j}-\gamma_{m,j})^{2}a_{m,i}^{4}/4.

When using the local reparameterization trick, we simply have

In this case, the second term vanishes because the random variable ζm,j\zeta_{m,j} is uniquely determined given bm,jb_{m,j}, as there is only a single ζm,j\zeta_{m,j} for each bm,jb_{m,j}. Because there are many ϵi,j\epsilon_{i,j} for each bm,jb_{m,j}, this variable is not uniquely determined by conditioning on bm,jb_{m,j}, so there is an additional (positive) contribution to the variance.

Appendix E Variance of stochastic gradients for variational dropout with correlated weight noise

In section 5 we empirically compare the variance of the different available stochastic estimators of the gradient of our variational objective for a model regularized using variational dropout with independent weight noise (section3.1). Here we present the same analysis for variational dropout with correlated weight noise (section3.2). As table 2 shows, the relative performance of the different estimators is similar to that reported in section 5, although the noise level is generally much higher using this regularization method.

Appendix F Variance of SGVB estimator with minibatches of datapoints without replacement

Using the indicator variables siSs_{i}\in S, to denote whether the ii-th training example is included in our minibatch, and Li(ϵ,ϕ)L_{i}(\mathbf{\epsilon},\phi) as shorthand for logp(yixi,w=f(ϵ,ϕ))\log p(\mathbf{y}^{i}|\mathbf{x}^{i},\mathbf{w}=f(\mathbf{\epsilon},\mathbf{\phi})), the Monte Carlo estimator (3) may be rewritten as