Simple Algorithm
Deep Learning · Emergence · 26 min

Dropout in Depth

Subnetwork ensembles, adaptive L2 penalties and the noise-injection family.

Dropout looks like a hack: silence random units and hope for the best. Underneath are exact statements. For a softmax layer the weight-scaling rule computes an ensemble of exponentially many subnetworks exactly; for generalized linear models dropout is a ridge penalty that adapts to the Fisher information and spares rare but useful features; and in deep networks the randomness of the masks regularizes on its own, beyond the penalty it adds to the expected loss.

What you’ll learn

  • Prove that the weight-scaling rule computes the normalized geometric mean of all dropout subnetworks of a softmax layer, show that this ensemble never has worse log loss than the average subnetwork, and explain why exactness ends at the first hidden nonlinearity.
  • Derive the dropout penalty for linear regression and its quadratic approximation for generalized linear models, and read it as an L2L_2 penalty after rescaling each feature by its Fisher information.
  • Separate dropout's explicit regularizer from the implicit effect of its noise, and describe the experiment that shows the noise matters.
  • Evaluate the Bayesian reading of dropout and its critiques, and place DropConnect, Gaussian, spatial and block dropout, stochastic depth, LayerDrop, R-Drop and early dropout in one family.

An exact ensemble, and where exactness ends

DerivationProof
  1. ∑mP(m)log⁡Pm(y∣x)=∑mP(m) zm,y  −  ∑mP(m)log⁡∑kezm,k⏟the same for every y\sum_{\mathbf m}P(\mathbf m)\log P_{\mathbf m}(y\mid\mathbf x)=\sum_{\mathbf m}P(\mathbf m)\,z_{\mathbf m,y}\;-\;\underbrace{\sum_{\mathbf m}P(\mathbf m)\log\sum_ke^{z_{\mathbf m,k}}}_{\text{the same for every }y}

    Write zm=W⊤(m⊙x)/p+b\mathbf z_{\mathbf m}=W^\top(\mathbf m\odot\mathbf x)/p+\mathbf b, so log⁡Pm(y∣x)=zm,y−log⁡∑kezm,k\log P_{\mathbf m}(y\mid\mathbf x)=z_{\mathbf m,y}-\log\sum_ke^{z_{\mathbf m,k}}. The log of the unnormalized geometric mean splits into a part that depends on yy and a part that does not:

  2. ∑mP(m) zm,y=wy⊤E[m]⊙xp+by=wy⊤x+by⟹G(⋅∣x)=softmax⁡(W⊤x+b)\sum_{\mathbf m}P(\mathbf m)\,z_{\mathbf m,y}=\mathbf w_y^\top\frac{\E[\mathbf m]\odot\mathbf x}{p}+b_y=\mathbf w_y^\top\mathbf x+b_y\quad\Longrightarrow\quad G(\cdot\mid\mathbf x)=\softmax(W^\top\mathbf x+\mathbf b)

    The second part cancels when we normalize over yy. The first part is linear in m\mathbf m, so the average passes straight through, and E[m]=p1\E[\mathbf m]=p\mathbf 1 cancels the 1/p1/p:

  3. Z=∑y′∏mPm(y′∣x)P(m)≤∑y′∑mP(m)Pm(y′∣x)=1⟹−log⁡G(y∣x)≤−∑mP(m)log⁡Pm(y∣x)Z=\sum_{y'}\prod_{\mathbf m}P_{\mathbf m}(y'\mid\mathbf x)^{P(\mathbf m)}\le\sum_{y'}\sum_{\mathbf m}P(\mathbf m)P_{\mathbf m}(y'\mid\mathbf x)=1\quad\Longrightarrow\quad-\log G(y\mid\mathbf x)\le-\sum_{\mathbf m}P(\mathbf m)\log P_{\mathbf m}(y\mid\mathbf x)

    For the loss bound, write G(y∣x)=∏mPm(y∣x)P(m)/ZG(y\mid\mathbf x)=\prod_{\mathbf m}P_{\mathbf m}(y\mid\mathbf x)^{P(\mathbf m)}/Z. By the weighted inequality of arithmetic and geometric means each product is at most the matching arithmetic average, so the normalizer is at most one:

  4. The same computation for a single logistic unit gives NWGM(σ(S))=σ(E[S])\mathrm{NWGM}(\sigma(S))=\sigma(\E[S]) (Baldi & Sadowski, 2013). Once a nonlinearity sits between the masks and the output, zm\mathbf z_{\mathbf m} is no longer linear in m\mathbf m, the expectation no longer passes through, and the deterministic pass only approximates the ensemble. Baldi and Sadowski describe deep networks by three recursive equations: NWGM(O)=σ(E[S])\mathrm{NWGM}(O)=\sigma(\E[S]) holds exactly for every logistic unit, E[S]\E[S] follows from the expected outputs of the layer below by linearity, and the only approximation is E[O]≈NWGM(O)\E[O]\approx\mathrm{NWGM}(O), made at every layer.

Check your understanding

In which case does running the network with dropout switched off compute an ensemble of all dropout subnetworks exactly?

  1. Dropout on the inputs of a single softmax layer: the pass equals the normalized geometric mean
  2. Dropout anywhere in a ReLU network: the pass equals the arithmetic mean
  3. Dropout in a deep network, provided pp is close to 1
  4. Never; it is always an approximation
Show the answer

A. Dropout on the inputs of a single softmax layer: the pass equals the normalized geometric mean

The softmax's log is linear in the logits up to a term that does not depend on the class, and the logits are linear in the mask, so the expectation passes through exactly. A hidden nonlinearity breaks the linearity, leaving an approximation, good or bad depending on how nonlinear the units are over the range the masks explore.

Dropout as an adaptive penalty

Wager, Wang and Liang (2013) asked what dropout does to a model's objective. Apply inverted dropout to the features of a generalized linear model: x~ij=mijxij/p\tilde x_{ij}=m_{ij}x_{ij}/p with independent masks, so E[x~i]=xi\E[\tilde{\mathbf x}_i]=\mathbf x_i and Var⁡[x~ij]=1−ppxij2\Var[\tilde x_{ij}]=\frac{1-p}px_{ij}^2.

DerivationThe dropout penalty
  1. Em[(y−w⊤x~)2]=(y−w⊤x)2+Var⁡(w⊤x~)=(y−w⊤x)2+1−pp∑jwj2xj2\E_{\mathbf m}\big[(y-\mathbf w^\top\tilde{\mathbf x})^2\big]=(y-\mathbf w^\top\mathbf x)^2+\Var\big(\mathbf w^\top\tilde{\mathbf x}\big)=(y-\mathbf w^\top\mathbf x)^2+\frac{1-p}{p}\sum_jw_j^2x_j^2

    Linear regression. The squared error of a noisy input is the clean error plus the variance of the noisy prediction, exactly:

  2. ∑iEm[ℓ(x~i,yi)]=∑iℓ(xi,yi)+R(β),R(β)=∑i(Em[A(x~i⊤β)]−A(xi⊤β)) ≥ 0\sum_i\E_{\mathbf m}\big[\ell(\tilde{\mathbf x}_i,y_i)\big]=\sum_i\ell(\mathbf x_i,y_i)+R(\boldsymbol\beta),\qquad R(\boldsymbol\beta)=\sum_i\Big(\E_{\mathbf m}\big[A(\tilde{\mathbf x}_i^\top\boldsymbol\beta)\big]-A(\mathbf x_i^\top\boldsymbol\beta)\Big)\ \ge\ 0

    Averaged over the data this is ridge regression with a separate weight per feature, 1−pp⋅1n∑ixij2\frac{1-p}p\cdot\frac1n\sum_ix_{ij}^2: ridge on standardized features. GLMs. Now take pβ(y∣x)∝ey x⊤β−A(x⊤β)p_{\boldsymbol\beta}(y\mid\mathbf x)\propto e^{y\,\mathbf x^\top\boldsymbol\beta-A(\mathbf x^\top\boldsymbol\beta)}, with convex log-partition function AA and loss ℓ=A(x⊤β)−y x⊤β\ell=A(\mathbf x^\top\boldsymbol\beta)-y\,\mathbf x^\top\boldsymbol\beta. The term linear in x~\tilde{\mathbf x} averages to its clean value, so the noise adds a penalty:

  3. Rq(β)=12 1−pp∑i=1nA′′(xi⊤β)∑jxij2βj2=12 1−pp  β⊤diag⁡(X⊤VX) β,V=diag⁡(A′′(xi⊤β))R^{q}(\boldsymbol\beta)=\frac12\,\frac{1-p}{p}\sum_{i=1}^nA''(\mathbf x_i^\top\boldsymbol\beta)\sum_jx_{ij}^2\beta_j^2=\frac12\,\frac{1-p}{p}\;\boldsymbol\beta^\top\diag\big(X^\top V X\big)\,\boldsymbol\beta,\qquad V=\diag\big(A''(\mathbf x_i^\top\boldsymbol\beta)\big)

    R≥0R\ge0 by Jensen's inequality, and it does not involve the labels at all. A second-order Taylor expansion of AA around xi⊤β\mathbf x_i^\top\boldsymbol\beta (the first-order term averages to zero) gives the quadratic penalty:

  4. Rq(β)=12 1−pp∑i,jμi(1−μi) xij2 βj2R^{q}(\boldsymbol\beta)=\frac12\,\frac{1-p}{p}\sum_{i,j}\mu_i(1-\mu_i)\,x_{ij}^2\,\beta_j^2

    At the true parameter, 1nX⊤VX\frac1nX^\top VX estimates the Fisher information I\mathcal I. So dropout is, to second order, an L2L_2 penalty applied after rescaling each feature by Ijj−1/2\mathcal I_{jj}^{-1/2}: it applies the penalty in a basis where the features have been balanced, although the loss's level sets need not be round. For logistic regression A′′=μi(1−μi)A''=\mu_i(1-\mu_i) with μi=σ(xi⊤β)\mu_i=\sigma(\mathbf x_i^\top\boldsymbol\beta):

Read the logistic penalty term by term. An example contributes only through features that are active on it (xij≠0x_{ij}\ne0), and only if its prediction is uncertain (μi(1−μi)\mu_i(1-\mu_i) large). A rare feature that, whenever it fires, helps make a confident prediction pays almost nothing, however large its weight; a plain L2L_2 penalty would charge it in full. Wager et al. confirmed in simulation that dropout beats L2L_2 when the signal lives in rare features, which fits dropout's success in document classification. And because RR ignores the labels, unlabeled data can be used to estimate it, which their semi-supervised variant exploits.

Predict before you look

Inverted dropout with keep probability p=0.8p=0.8 acts on the inputs of a linear regression trained with mean squared error. A feature has mean square 1n∑ixij2=4\frac1n\sum_ix_{ij}^2=4. What coefficient cc multiplies wj2w_j^2 in the penalty dropout adds to the mean squared error?

Show the answer

1

c=1−pp⋅1n∑ixij2=0.25×4=1c=\frac{1-p}{p}\cdot\frac1n\sum_ix_{ij}^2=0.25\times4=1. The same dropout rate penalizes a feature with twice the scale four times as hard, which is why dropout on raw inputs behaves like ridge on standardized inputs.

Explicit and implicit effects

In a deep network, apply inverted dropout to a hidden layer h\mathbf h and let FF map it to the outputs, with J=∂F/∂hJ=\partial F/\partial\mathbf h and HoutH_{\text{out}} the Hessian of the loss with respect to the outputs. The perturbation δ=h⊙(m/p−1)\boldsymbol\delta=\mathbf h\odot(\mathbf m/p-\mathbf 1) has mean zero and covariance 1−ppdiag⁡(h⊙2)\frac{1-p}p\diag(\mathbf h^{\odot2}), so a second-order expansion (keeping the Gauss–Newton part of the curvature) gives the explicit regularizer:

Rexplicit≈1−p2p ⟨J⊤HoutJ, diag⁡(h⊙2)⟩=1−p2p∑jhj2 [J⊤HoutJ]jjR_{\text{explicit}}\approx\frac{1-p}{2p}\,\Big\langle J^\top H_{\text{out}}J,\ \diag\big(\mathbf h^{\odot2}\big)\Big\rangle=\frac{1-p}{2p}\sum_jh_j^2\,\big[J^\top H_{\text{out}}J\big]_{jj}
Each unit pays its squared activation times the curvature of the loss along that unit. For a linear model, JJ is the weight vector and Hout=A′′H_{\text{out}}=A'', recovering the GLM penalty. For cross-entropy Hout=diag⁡(q)−qq⊤H_{\text{out}}=\diag(\mathbf q)-\mathbf q\mathbf q^\top with q\mathbf q the predicted probabilities, so confident predictions cost little.

But dropout does more than add RexplicitR_{\text{explicit}} to the expected loss. Each step uses one random mask, so the update is the gradient of the expected objective plus mean-zero noise, much like the noise of small mini-batches. Wei, Kakade and Ma (2020) separated the two effects. Their "Dropoutk_k" averaged the loss over kk masks per update, which leaves the expected objective unchanged and only removes noise: for LSTM language models on Penn Treebank and WikiText-2, validation perplexity got steadily worse as kk grew. Adding back mean-zero noise with the covariance of dropout's gradient noise restored performance, and the analytic explicit regularizer plus this noise matched dropout. Two details matter: replacing the loss Hessian in the penalty by the identity worked poorly, and on the much larger WikiText-103 with a Transformer-XL the implicit effect largely disappeared.

The noise can also help optimization. Liu et al. (2023) found that for models that underfit (in their experiments, small vision models trained on ImageNet), dropout applied only in the first part of training ("early dropout") reached a lower final training loss than no dropout; they observed that it reduces the variance of mini-batch gradient directions early on, aligning them with the full-data gradient. For models that overfit they proposed the mirror image, "late dropout", switched on only after an initial phase.

Check your understanding

Averaging the loss over kk dropout masks per update keeps dropout's expected objective fixed. Validation perplexity of LSTM language models got worse as kk grew. What does that show?

  1. The explicit penalty was implemented incorrectly
  2. More masks per step overfit because they see more subnetworks
  3. The randomness of single-mask updates is itself a regularizer, beyond the penalty in the expected objective
  4. Dropout works only through its effect on the learning rate
Show the answer

C. The randomness of single-mask updates is itself a regularizer, beyond the penalty in the expected objective

With the expected objective held fixed, the only thing kk changes is the variance of the update. Worse results with less noise mean the noise was helping, an implicit regularization effect, and adding matched noise back recovered the performance.

The Bayesian reading and its critiques

Gal and Ghahramani (2016) gave dropout a probabilistic interpretation: training a network with dropout and an L2L_2 penalty can be cast as approximate variational inference for a Bayesian neural network, with a variational distribution in which all the weights leaving a unit are switched on or off together by one Bernoulli variable. Keeping dropout on at test time and averaging many stochastic passes ("MC dropout") then approximates the posterior predictive distribution, and the spread of the passes serves as an uncertainty estimate at no extra training cost. The Machine Learning course's lesson Uncertainty in Neural Networks compares it with deep ensembles in practice.

The reading has drawn sharp critiques. Osband (2016) pointed out that with a fixed dropout rate the spread of MC dropout predictions does not shrink as the training set grows, unlike a posterior, so it reflects the noise of the procedure more than uncertainty about the parameters. Hron, Matthews and Ghahramani (2018) showed that the log-uniform prior used by variational Gaussian dropout (Kingma, Salimans & Welling, 2015) is improper and generally yields an improper posterior, so that Bayesian objective is ill-posed; the sparsity the method produces cannot be explained by the Bayesian or minimum-description-length arguments offered for it. They also showed that, for Bernoulli and Gaussian dropout alike, the approximating distribution is singular with respect to the true posterior, which leaves the standard variational objective undefined, and they proposed a quasi-KL divergence that makes the remedies used for MC dropout rigorous.

Think first Why can't the spread of MC dropout predictions concentrate as the dataset grows, the way a true posterior does?

The variational family fixes the shape of the uncertainty in advance: each weight is either present or absent with the fixed probability pp, so the spread of the sampled networks is set by pp and by the size of the learned weights, not by the amount of data. A Bayesian posterior over a well-specified model narrows roughly like 1/n1/\sqrt n. Unless pp itself is learned and pushed toward 1 as data grow, the "posterior" keeps its width.

A family of structured noise

VariantWhat is dropped or perturbedWhy
Gaussian dropoutEach unit is multiplied by noise from N(1,1−pp)\mathcal N\big(1,\frac{1-p}p\big), the same mean and variance as inverted Bernoulli dropoutNo test-time rescaling; Srivastava et al. (2014) found it worked as well or slightly better
DropConnectIndividual weights, so each unit sees a random subset of its inputs (Wan et al., 2013)A finer-grained family of subnetworks
SpatialDropoutWhole channels of a convolutional feature map (Tompson et al., 2015)Neighboring activations are correlated, so dropping single pixels hides little
DropBlockContiguous square regions of a feature map (Ghiasi, Lin & Le, 2018)Removes whole local evidence, forcing the network to use other regions
Stochastic depth, LayerDropWhole residual blocks (Huang et al., 2016) or transformer layers (Fan, Grave & Joulin, 2020)LayerDrop also lets a trained model be cut to a smaller depth at inference without fine-tuning
R-DropTwo dropout masks per example, plus the symmetric KL divergence between the two predictions (Liang et al., 2021)Makes the sampled subnetworks agree, shrinking the gap with the full test-time network
Early and late dropoutDropout only before, or only after, a chosen point in training (Liu et al., 2023)Early dropout eases underfitting; late dropout targets overfitting

Dropout also interacts badly with batch normalization. A dropped-out layer has a different activation variance during training than at test time, but a following batch-norm layer keeps using the running variance it accumulated with dropout on. Li, Chen, Hu and Yang (2019) called this mismatch variance shift and traced the poor results of combining the two to it; placing dropout after the last batch-norm layer avoids it. In convolutional networks with batch normalization, dropout largely gave way to augmentation, weight decay and stochastic depth.

Key takeaways

  • For inverted dropout on the inputs of one softmax layer, the deterministic pass is exactly the normalized geometric mean of all 2n2^n subnetworks, whose log loss never exceeds the average subnetwork's; hidden nonlinearities make it an approximation.
  • For GLMs, dropout adds the label-free penalty ∑i(E[A(x~i⊤β)]−A(xi⊤β))≥0\sum_i(\E[A(\tilde{\mathbf x}_i^\top\boldsymbol\beta)]-A(\mathbf x_i^\top\boldsymbol\beta))\ge0, to second order 121−ppβ⊤diag⁡(X⊤VX)β\frac12\frac{1-p}p\boldsymbol\beta^\top\diag(X^\top VX)\boldsymbol\beta: ridge after rescaling by the diagonal Fisher information, gentle on rare but useful features.
  • In deep networks the explicit penalty weights each unit's squared activation by the loss curvature along it, and the mask noise adds an implicit regularization of its own (Wei, Kakade & Ma, 2020).
  • MC dropout reads dropout as variational inference (Gal & Ghahramani, 2016), but its spread does not concentrate with data at a fixed rate, and variational Gaussian dropout's log-uniform prior is improper (Hron et al., 2018): treat its uncertainty as an empirical claim.
  • The family (Gaussian, DropConnect, spatial, block, stochastic depth, LayerDrop, R-Drop, early dropout) varies what is dropped to match the structure of the network; before batch normalization, dropout causes a train–test variance shift.

Check yourself

In the interactive lesson these are scored with your confidence, and what you miss comes back for review.

Question 1

For inverted dropout on the inputs of a softmax layer, the deterministic test-time pass equals which ensemble of the 2n2^n subnetworks?

  1. The arithmetic mean of their predicted probabilities
  2. The normalized geometric mean of their predicted probabilities, weighted by the mask probabilities
  3. The single most probable subnetwork, with all units kept
  4. The median of their predictions
Show the answer

B. The normalized geometric mean of their predicted probabilities, weighted by the mask probabilities

The log of a softmax is the logit minus a class-independent term, and the logits are linear in the mask, so the weighted geometric mean renormalizes to softmax⁡(W⊤x+b)\softmax(W^\top\mathbf x+\mathbf b). Its log loss is never worse than the average subnetwork's, by the inequality of arithmetic and geometric means.

Question 2

Dropout on the features of a logistic regression adds, to second order, 121−pp∑i,jμi(1−μi)xij2βj2\frac12\frac{1-p}p\sum_{i,j}\mu_i(1-\mu_i)x_{ij}^2\beta_j^2. Which feature can keep a large weight cheaply?

  1. A feature that is active on every example, where predictions are uncertain
  2. Any feature with a large average value
  3. None: the penalty is the same as L2L_2 for every feature
  4. A rare feature that, whenever it is active, contributes to a confident prediction
Show the answer

D. A rare feature that, whenever it is active, contributes to a confident prediction

A feature pays only on examples where it is active (xij≠0x_{ij}\ne0), weighted by μi(1−μi)\mu_i(1-\mu_i), which is small for confident predictions. Rare, discriminative features escape most of the penalty, unlike under L2L_2.

Question 3

For a generalized linear model, why can the dropout penalty R(β)R(\boldsymbol\beta) be estimated from unlabeled data?

  1. Because the labels enter the loss linearly through y x⊤βy\,\mathbf x^\top\boldsymbol\beta, whose expectation over the masks is unchanged; only the log-partition term is perturbed
  2. Because dropout ignores the loss function entirely
  3. Because the Fisher information never depends on β\boldsymbol\beta
  4. It cannot; the penalty depends on every label
Show the answer

A. Because the labels enter the loss linearly through y x⊤βy\,\mathbf x^\top\boldsymbol\beta, whose expectation over the masks is unchanged; only the log-partition term is perturbed

E[x~]=x\E[\tilde{\mathbf x}]=\mathbf x leaves the term linear in yy untouched, so R=∑i(E[A(x~i⊤β)]−A(xi⊤β))R=\sum_i(\E[A(\tilde{\mathbf x}_i^\top\boldsymbol\beta)]-A(\mathbf x_i^\top\boldsymbol\beta)) involves inputs only. Wager et al. used this to build a semi-supervised regularizer.

Question 4

What did Hron, Matthews and Ghahramani (2018) show about variational Gaussian dropout with a log-uniform prior?

  1. It is too expensive to train on large networks
  2. Its prior is too informative, so the data are ignored
  3. The prior is improper and generally gives an improper posterior, so the Bayesian objective is ill-posed
  4. It is exactly equivalent to Bernoulli dropout with p=0.5p=0.5
Show the answer

C. The prior is improper and generally gives an improper posterior, so the Bayesian objective is ill-posed

An improper prior can be harmless when the posterior is still normalizable; here it generally is not, so the variational objective has no well-defined Bayesian target, and the sparsity it produces needs another explanation.

Further reading

  • P. Baldi & P. J. Sadowski, "Understanding dropout," NeurIPS (2013).
  • S. Wager, S. Wang & P. Liang, "Dropout training as adaptive regularization," NeurIPS (2013).
  • C. Wei, S. Kakade & T. Ma, "The implicit and explicit regularization effects of dropout," ICML (2020).
  • Y. Gal & Z. Ghahramani, "Dropout as a Bayesian approximation: representing model uncertainty in deep learning," ICML (2016).
  • J. Hron, A. G. de G. Matthews & Z. Ghahramani, "Variational Bayesian dropout: pitfalls and fixes," ICML (2018).