Foundations to Frontier
Tests
E. Deep Learning › E4 Regularization Techniques (one page each)

Dropout

Dropout randomly switches off each hidden unit with probability p at every training step and rescales the survivors, so the network cannot rely on any one unit and effectively trains an exponential family of thinned sub-networks that share weights. At test time all units are used, which approximates averaging those sub-networks; keeping dropout on and averaging several passes gives Monte Carlo dropout, a cheap uncertainty estimate. This page covers inverted dropout, its interpretation as an adaptive L2 penalty and as approximate Bayesian inference, where to place it and what rate to use. In the exercises you show that for a linear model dropout adds p/(1 − p) Σ wⱼ²xⱼ² to the loss, then train a network on 60 points and find, honestly, that dropout did not raise test accuracy but did cut the test cross-entropy from 1.61 to 0.48 with Monte Carlo averaging.

Level 0: Foundation

★☆☆☆☆ Introductory⏱ 5 minGeneral audience. No mathematics required.

Train with random units missing

At every training step dropout picks hidden units at random and switches them off. The network never knows which units it will have, so it cannot build fragile chains in which one unit fixes another’s mistakes; each unit must be useful on its own. At test time every unit is on. It is like training a huge crowd of smaller networks that share their weights and then letting them vote.

Regularisation lab: a small network on 40 noisy points
test cross-entropy during training
lowest test loss 0.200 at epoch 272
train accuracy 0.925 · test accuracy 0.870 · final test cross-entropy 0.297
With no regularisation the network fits all 40 noisy training points with a contorted boundary, and its test loss rises after an early minimum (the dot): overfitting. Each regulariser trades some training fit for a smoother boundary. Early stopping keeps the weights from the dot (here the test loss stands in for a validation set, which makes it look slightly better than it would in practice). Try the strength slider: too little does nothing, too much underfits. Results vary with the data, so press "new data" before trusting a comparison.
Why engineers care

Dropout is one line of code and was central to the 2012 ImageNet breakthrough. It is still standard in transformers’ attention and feed-forward layers and in many fully connected heads. Keeping it on at test time and averaging several passes gives a cheap estimate of a model’s uncertainty, useful when a perception system must know when it is unsure.

📝 Quick check (Level 0)
0/3 answered
  1. 1. Dropout during training…
  2. 2. At test time, standard dropout…
  3. 3. Averaging several dropout passes at test time is called…

Level 1: Beginner

★★☆☆☆ Basic⏱ 20 minSecondary-school mathematics: arithmetic and elementary algebra.

By hand

  • Mask: each unit is kept with probability 1 − p: mᵢ ~ Bernoulli(1 − p).
  • Inverted dropout: h̃ = m ⊙ h/(1 − p) during training, h at test time. The division keeps E[h̃] = h, so no rescaling is needed at test time. Example: h = (1, 2, 3, 4), mask (1, 0, 1, 0), p = 0.5 gives (2, 0, 6, 0).
  • Sub-networks: n droppable units give 2ⁿ masks; with 1024 units, about 10³⁰⁸ sub-networks share one set of weights.
  • Expected units kept: n(1 − p), for example 512 of 1024 at p = 0.5.
  • Linear model with input dropout: the expected squared error is (y − wᵀx)² + (p/(1 − p))·Σ wⱼ²xⱼ². This is an L2 penalty weighted by each feature’s size: dropout is data-dependent weight decay. At p = 0.5 the factor is 1; at p = 0.2 it is 0.25.
  • Typical rates: 0.1 in transformers, 0.5 in large fully connected layers, 0.1–0.2 on inputs.
📝 Quick check (Level 1)
0/3 answered
  1. 1. Inverted dropout divides kept units by…
  2. 2. The penalty factor p/(1 − p) at p = 0.5 is…
  3. 3. Number of dropout masks for 10 units:

Level 2: Intermediate

★★★☆☆ Intermediate⏱ 25 minUndergraduate students and practising engineers.

Dropout in code

Exercise 1.

  • Averaging 4000 inverted-dropout masks recovered every activation to within 0.08.
  • For a linear model, the expected loss over masks matched the formula (y − wᵀx)² + (p/(1 − p))Σwⱼ²xⱼ²: 2.762 by formula, 2.759 by 200 000 random masks, against a plain squared error of 1.27.

Practice.

  • Use nn.Dropout(p) and remember model.train() and model.eval(): forgetting eval() leaves dropout on at test time.
  • Place it after activations in fully connected layers and on attention weights and residual branches in transformers.
  • Dropout is rarely used inside convolutional layers with batch normalisation, because the two interact badly through the variance shift between training and test (Li et al., 2019). Spatial dropout (E4-4) is the convolutional version.
  • For Monte Carlo dropout, keep only the dropout layers in training mode at test time and average 10–50 passes.
model.eval()
for m in model.modules():
    if isinstance(m, torch.nn.Dropout): m.train()       # Monte Carlo dropout
probs = torch.stack([model(x).softmax(-1) for _ in range(20)]).mean(0)
🐍 Exercise 1: dropout as adaptive weight decay
Implement inverted dropout, check it preserves the mean, and verify the expected loss of a linear model under input dropout.
📝 Quick check (Level 2)
0/3 answered
  1. 1. Forgetting model.eval() at test time…
  2. 2. Dropout with batch norm in CNNs is problematic because of…
  3. 3. Typical transformer dropout rate:

Level 3: Advanced

★★★★☆ Advanced⏱ 25 minGraduate level, with full derivations and proofs.

Theory

Adaptive regularisation. For generalised linear models, Wager, Wang and Liang (2013) showed that dropout is, to second order, an L2 penalty scaled by the Fisher information of each feature. Rare features with large values are penalised more than with plain weight decay. Exercise 1 checks the exact squared-error case.

Approximate ensembling. Using all units with inverted scaling at test time (the weight-scaling rule) is exact for a single linear layer. For deep nonlinear networks it is an approximation to the geometric mean of the sub-networks’ predictions (Baldi and Sadowski, 2013).

Approximate Bayesian inference. Gal and Ghahramani (2016) showed that training with dropout and an L2 penalty approximates variational inference in a Bayesian network with a particular approximate posterior. Averaging T stochastic passes approximates the predictive distribution, and their spread estimates model uncertainty. The approximation is crude, and MC dropout’s uncertainty estimates are usually weaker than deep ensembles’.

Co-adaptation. Hinton et al.’s original motivation was preventing units from co-adapting, so that each feature is useful in many contexts.

📝 Quick check (Level 3)
0/3 answered
  1. 1. To second order, dropout in GLMs is an L2 penalty scaled by…
  2. 2. The weight-scaling rule is exact for…
  3. 3. MC dropout approximates…

Level 4: Expert

★★★★★ Expert⏱ 25 minResearchers: original papers and open problems.

Does dropout help on 60 points?

History.

  • G. Hinton et al. (2012) and N. Srivastava et al. (2014) introduced dropout; A. Krizhevsky et al. (2012) used it in AlexNet.
  • S. Wager, S. Wang and P. Liang (2013) interpreted it as adaptive regularisation.
  • Y. Gal and Z. Ghahramani (2016) interpreted it as approximate Bayesian inference and introduced MC dropout.
  • Transformers (Vaswani et al., 2017) use dropout on attention weights and residual branches.

Exercise 2. A 2–64–64–2 ReLU network with inverted dropout on both hidden layers, trained with Adam (1000 full-batch steps) on 60 noisy two-moons points and tested on 2000. Means of three seeds:

p train acc test acc test CE (all units) test acc (MC, 20 passes) test CE (MC)
0 1.000 0.873 1.609 — —
0.3 0.989 0.878 1.299 0.878 0.855
0.5 0.983 0.868 1.245 0.870 0.695
0.7 0.961 0.863 0.990 0.874 0.475
  • Dropout did not improve test accuracy: all rates stayed within 0.86–0.88, within seed noise. The networks still fitted the training set almost perfectly.
  • It improved confidence. With all units at test time the cross-entropy fell from 1.61 to 0.99 at p = 0.7. Averaging 20 dropout passes cut it to 0.48, a third of the no-dropout value. The mistakes became less confident.
  • Lesson: on tiny data, dropout alone is a weak fix for accuracy (compare L2 in E4-1), but MC averaging is a cheap way to get better-calibrated probabilities.
🐍 Exercise 2 (research): dropout on 60 points
Train a ReLU network with several dropout rates and compare accuracy and cross-entropy with all units on and with Monte Carlo averaging.

Dropout in AI, robotics and aerospace

  • Transformers for language, vision and planning use dropout on attention and residual paths.
  • Uncertainty in perception and control: MC dropout gives a cheap uncertainty signal used, for example, to flag unreliable depth or collision predictions, and in model-based reinforcement learning.
  • Small labelled datasets from new sensors are where regularisers like dropout are most needed, and where exercise 2’s caution applies.

References

  1. N. Srivastava, G. Hinton, A. Krizhevsky, I. Sutskever, R. Salakhutdinov (2014). “Dropout: a simple way to prevent neural networks from overfitting.” JMLR 15.
  2. S. Wager, S. Wang, P. Liang (2013). “Dropout training as adaptive regularization.” Advances in NeurIPS.
  3. Y. Gal, Z. Ghahramani (2016). “Dropout as a Bayesian approximation: representing model uncertainty in deep learning.” Proc. ICML.
  4. P. Baldi, P. Sadowski (2013). “Understanding dropout.” Advances in NeurIPS.
  5. X. Li, S. Chen, X. Hu, J. Yang (2019). “Understanding the disharmony between dropout and batch normalization by variance shift.” Proc. CVPR.