Search

Search papers and lessons

Dropout

Level 3 · 11 min read

Dropout randomly switches off a fraction of a network's units on each training step, which stops units from relying on each other and acts as a cheap way to average many smaller networks.

On this page

  • Colour = topic mix
  • Linear algebra
  • Probability
  • Learning basics
  • Losses & regularization
  • Neural network basics
  • Discrete math
  • Sign in to see your progress

TL;DR

Dropout is a training trick for neural networks. On every training step, each hidden unit is independently set to zero with some probability pp, and the rest of the network carries on with what is left. At test time nothing is dropped, and the network uses all of its units.

The effect is that no unit can count on a specific neighbour being present, so each one has to learn features that are useful on their own. That reduces Overfitting and, as a side effect, trains something close to an average of a huge number of smaller networks.

Where you'll see it: in the fully connected layers of image classifiers and language models, in the attention and feed-forward blocks of many transformers, and as a standard default in deep learning libraries.

Intuition

A team where anyone might be absent

Picture a team that is told, every morning, that a random half of its members will be away. Nobody can rely on one particular colleague to fix a specific problem. Each person has to learn the whole job well enough to cover for others, and the team as a whole becomes sturdier. If the same people were always together, they could quietly become dependent on each other, with one person handling a narrow case that only works when a partner is there to set it up.

Neural networks do the same thing without help. Units in one layer tend to lock into pairs or small groups that only work together. Those groups can fit the training data very well, which is exactly the problem: the fit is partly memorised quirks of that data, and it breaks on new inputs. This is what the original paper called co-adaptation. Dropout breaks the groups apart by making every unit's neighbours unreliable.

The picture below is a single hidden layer on one step. Hidden 2 is dropped: its dashed connection to the output carries nothing, and whatever it received from the inputs is discarded.

flowchart LR
  i1((input 1)) --> h1((hidden 1))
  i1 --> h2((hidden 2))
  i2((input 2)) --> h1
  i2 --> h2
  i2 --> h3((hidden 3))
  h1 --> o((output))
  h3 --> o
  h2 -. "dropped this step" .-> o

On the next step a different random set of hidden units is dropped, so the network sees a different thinned version of itself every time.

Why this is a regulariser

A regulariser is anything that makes a model less eager to fit the training set perfectly. L2 Regularization does it by penalising large weights. Dropout does it by injecting noise into the forward pass. The network cannot rely on any one path, so it has to spread what it learns across many redundant paths. That redundancy is what generalises.

There is a second, more surprising way to see it. Each training step samples one of the exponentially many sub-networks you get by deleting units, and trains that sub-network on one example. Across the whole run, the weights are shared among all those sub-networks. At test time, the full network with scaled weights approximates the average of their predictions. That is the same idea as Ensemble Learning, done for the price of one extra random number per unit.

The math

Setting up

Consider one layer with activations h=(h1,…,hn)\mathbf{h} = (h_1, \dots, h_n), where nn is the number of hidden units and hjh_j is the output of unit jj. Choose a keep probability qq with 0<q≤10 \lt q \le 1. The drop probability is p=1−qp = 1 - q. For each unit, draw an independent mask bit

mj∼Bernoulli(q),m_j \sim \mathrm{Bernoulli}(q),

so mj=1m_j = 1 means "keep" and mj=0m_j = 0 means "drop", each with the probabilities described in the Bernoulli distribution.

The training-time output is the elementwise product of the mask and the activations, divided by qq:

h~j=mjq hj.\tilde{h}_j = \frac{m_j}{q}\, h_j.

The division by qq is called inverted dropout. It is the form almost every modern library uses, and it is explained below.

Why divide by the keep probability

Look at the expected value of one unit's output. Since E[mj]=q\mathbb{E}[m_j] = q,

E[h~j]=E[mj]q hj=qq hj=hj.\mathbb{E}[\tilde{h}_j] = \frac{\mathbb{E}[m_j]}{q}\, h_j = \frac{q}{q}\, h_j = h_j.

On average, the training-time output equals the activation the unit would have produced with no dropout. So at test time we can simply use every unit with no scaling, and the expected input to the next layer is unchanged. That is the whole reason for the 1/q1/q factor: it moves the scaling from test time to training time, so inference is free.

How noisy is a single unit?

Dropout does not change the average output, but it adds variance. For a single unit with fixed activation hh, the output h~=mh/q\tilde{h} = m h / q takes the value h/qh/q with probability qq and 00 with probability 1−q1-q. Because m2=mm^2 = m for a bit, E[m2]=q\mathbb{E}[m^2] = q, and so

Var(h~)=h2q2 Var(m)=h2q2 q(1−q)=h2 1−qq.\mathrm{Var}(\tilde{h}) = \frac{h^2}{q^2}\,\mathrm{Var}(m) = \frac{h^2}{q^2}\,q(1-q) = h^2\,\frac{1-q}{q}.

The noise grows as qq shrinks. With q=1q = 1 there is no noise at all, and with q=0.5q = 0.5 the variance equals h2h^2.

0.20.40.60.8102468keep probability qvariance / h^2
  • variance per unit of h squared
Noise injected by dropout into a single unit with activation h. Lower keep probability means each unit is more often silenced, so its surviving output swings more.

The backward pass

Dropout has no learned parameters, so there is nothing new to update. During Backpropagation, the gradient flowing into a unit is multiplied by the same mask and scale used in the forward pass. If a unit was dropped, its gradient is zero for that step. If it was kept, its gradient is multiplied by 1/q1/q. The chain rule does the rest, which is why dropout drops into existing training code with one line.

Test-time behaviour

At inference the mask is switched off:

htest=h.\mathbf{h}_{\text{test}} = \mathbf{h}.

For a single linear layer with weights w\mathbf{w}, the average of w⊤(m⊙h)/q\mathbf{w}^\top (\mathbf{m} \odot \mathbf{h}) / q over all masks is exactly w⊤h\mathbf{w}^\top \mathbf{h}, so the test-time network gives the mean prediction of the thinned networks. For deeper networks this is only an approximation, because the nonlinearities do not commute with the average. In practice it works well enough that the original authors used it as the default.

Worked examples

Example
One unit, two outcomes

Take a single unit with activation h=2h = 2 and keep probability q=0.5q = 0.5.

  1. Mask outcome m=1m = 1, probability 0.50.5: output =1×2/0.5=4= 1 \times 2 / 0.5 = 4.
  2. Mask outcome m=0m = 0, probability 0.50.5: output =0= 0.
  3. Expected output: 0.5×4+0.5×0=20.5 \times 4 + 0.5 \times 0 = 2. This matches the activation h=2h = 2 with no dropout, as the 1/q1/q scaling promised.
  4. Second moment: 0.5×16+0.5×0=80.5 \times 16 + 0.5 \times 0 = 8. Variance =8−22=4= 8 - 2^2 = 4.
  5. Check with the formula: h2(1−q)/q=4×0.5/0.5=4h^2 (1-q)/q = 4 \times 0.5 / 0.5 = 4. It matches.

Interpretation: the unit is right on average, but any single training step gives either a boost to 44 or a silence to 00. The network learns to be robust to that swing.

Example
A hidden layer on one step

A hidden layer has four units with activations h=(0.8, −0.3, 1.2, 0.5)\mathbf{h} = (0.8,\ -0.3,\ 1.2,\ 0.5). Use keep probability q=0.75q = 0.75, so p=0.25p = 0.25 and the scale is 1/q=1.33331/q = 1.3333.

  1. Draw a mask: m=(1,0,1,1)\mathbf{m} = (1, 0, 1, 1). Unit 2 is dropped.
  2. Multiply elementwise: (0.8, 0, 1.2, 0.5)(0.8,\ 0,\ 1.2,\ 0.5).
  3. Scale by 1/q1/q: (0.8×1.3333, 0, 1.2×1.3333, 0.5×1.3333)=(1.0667, 0, 1.6, 0.6667)(0.8 \times 1.3333,\ 0,\ 1.2 \times 1.3333,\ 0.5 \times 1.3333) = (1.0667,\ 0,\ 1.6,\ 0.6667).
  4. This vector is what the next layer receives on this training step.
  5. At test time, the next layer receives (0.8,−0.3,1.2,0.5)(0.8, -0.3, 1.2, 0.5) unchanged.

Notice that the surviving units are amplified, so the next layer sees roughly the same total signal on average, even though a quarter of the units went silent.

Example
Choosing a drop rate for a wide layer

A layer has n=1024n = 1024 units and we use drop probability p=0.2p = 0.2, so q=0.8q = 0.8. Assume each unit is kept independently.

  1. Expected number of kept units: nq=1024×0.8=819.2n q = 1024 \times 0.8 = 819.2, so about 819 units stay on each step.
  2. Variance of the kept count: nq(1−q)=1024×0.8×0.2=163.84n q (1-q) = 1024 \times 0.8 \times 0.2 = 163.84.
  3. Standard deviation: 163.84=12.8\sqrt{163.84} = 12.8.
  4. So on a typical step the number of active units is about 819±13819 \pm 13. The layer is always strongly populated, and the noise is a small fraction of its width.
  5. Compare with p=0.5p = 0.5 on the same layer: 512512 kept on average, standard deviation 256=16\sqrt{256} = 16. The relative noise is larger when pp is larger, but the layer still has many active units.

Interpretation: for a wide layer, moderate drop rates are safe because the random subset is still large. For a narrow layer, the same pp removes a much larger share of the capacity on every step.

Tradeoffs and failure modes

Dropout helps most when a model is large relative to its training data and overfits. It helps much less when the model is already small, when data is plentiful, or when another regulariser already does the job. It also slows training, because each step only updates a thinned network and the model usually needs more epochs to converge.

SituationWhat goes wrongBetter choice
Convolutional feature maps with spatial correlationDropping single pixels barely removes information, because neighbours carry the same signalSpatial dropout that drops whole channels, or Data Augmentation
Very small network on a lot of dataNoise costs accuracy without buying regularisationNo dropout, or a small rate such as p=0.1p = 0.1
Batch normalisation directly after dropoutThe variance of the normalisation statistics shifts between training and test, which can hurt accuracyPlace dropout after normalisation, or use a different regulariser
Forgetting to switch off dropout at test timePredictions become random and scores dropMake evaluation mode the default in your training loop
Using dropout as the only defence against OverfittingHeavy overfitting can persistCombine with Early Stopping and L2 Regularization

The most common bug is the test-time switch. Frameworks expose a train and eval mode for exactly this reason, and forgetting to call eval mode is a silent error that looks like a model that generalises badly.

History

Dropout was introduced in 2012 by Geoffrey Hinton and colleagues. Their arXiv paper, "Improving neural networks by preventing co-adaptation of feature detectors", described randomly omitting hidden units during training to stop the units from co-adapting. The same year, the AlexNet network that won the ImageNet classification challenge used the technique in its fully connected layers, which helped show that it worked at scale.

A fuller treatment by Nitish Srivastava and co-authors followed in 2014 in the Journal of Machine Learning Research. It analysed the method more carefully, compared it with other regularisers, and popularised the name and the inverted scaling now used by default. The idea caught on because it needed no extra parameters, almost no code, and worked across many architectures. Later variants such as DropConnect and spatial dropout were built on the same principle.

Check yourself

QuestionRecall: what is the purpose of dropping units during training?Show answer

To stop units from co-adapting, so that no unit depends on a specific neighbour being present. This forces each unit to learn useful features on its own, which reduces overfitting. It also acts like training an average over many thinned sub-networks.

QuestionComputation: with keep probability q=0.6q = 0.6 and activation h=5h = 5, what is the expected output of a unit under inverted dropout, and what is its variance?Show answer

The expected output is h=5h = 5, because the 1/q1/q scaling cancels the keep probability on average. The variance is h2(1−q)/q=25×0.4/0.6=16.67h^2 (1-q)/q = 25 \times 0.4 / 0.6 = 16.67, to two decimal places. The output takes the value 5/0.6=8.335/0.6 = 8.33 with probability 0.60.6 and 00 with probability 0.40.4. Check: 0.6×8.33=50.6 \times 8.33 = 5 and 0.6×8.332−25≈41.67−25=16.670.6 \times 8.33^2 - 25 \approx 41.67 - 25 = 16.67.

QuestionWhy: why does inverted dropout divide by the keep probability during training rather than multiplying by it at test time?Show answer

Dividing during training keeps the expected activation the same as it is without dropout, so the test-time network can use all units with no change. Multiplying at test time would also work, but it adds a step to inference and is easy to forget. Dividing during training means the same forward pass code runs at test time with the mask simply turned off.

QuestionApplied: a team trains a 2048-unit layer and sees the validation loss rise while the training loss keeps falling. Should they raise the dropout rate, and what would you check first?Show answer

A rising gap between training and validation loss is the classic sign of overfitting, so a higher rate is a reasonable first move. Before changing it, check that dropout is actually switched off during validation, because a bug there would look like overfitting. Then try a moderate increase, such as from p=0.2p = 0.2 to p=0.4p = 0.4, and watch the gap. A layer this wide still has many active units at high rates, so the change should not starve the network of capacity.

Sources