Skip to content
mlmentorship

Dropout

Randomly zero out a fraction of activations during training. The simplest stochastic regularizer; still standard in vision and many NLP architectures.

Published · 5 min read ·Core ·Foundation
Reading depth

Summary

Inverted dropout randomly masks activations and scales survivors to preserve each activation’s conditional expectation. Standard evaluation replaces that random operation with identity; it does not exactly average an arbitrary nonlinear network. Mask correlation and placement are part of the regularizer, not merely implementation details.

The mechanism (inverted dropout)

For fixed finite and :

  1. Sample a binary mask with independently.
  2. Compute .

Then and . For the pictured and , mask A produces and B produces . Their coordinate average is x; independently sampled masks need not arrive as complementary pairs. For coordinate two, the random output is zero or four with equal probability: mean two, variance four.

Worked expectation

Scaling preserves expected activation, not every realized training pass

Preserve the expectation, not each realizationWith keep probability 1/2, activation 4 becomes either 0 or 8. Their average is 4; neither individual pass preserves the input.One draw follows one branch450% chance050% chance8Neither realization equals four0.5 x 0 + 0.5 x 8 = 4Only the expectation is preserved.
Derivation

Training: mask, then scale survivors by 2

For p = 0.5, the keep probability is 1 - p = 0.5, so 1 / (1 - p) = 2.

Vector1234
Input x1234
Mask Akeepdropkeepdrop
Output A2060
Mask Bdropkeepdropkeep
Output B0408

Expectation: average restores x

The paired masks are only an illustration; independently sampled masks have the same expectation.

Vector1234
Mean(A, B)1234
Inference y1234

E[mixi / (1 - p)] = (1 - p)xi / (1 - p) = xi

Read it this way: a survivor doubles because it survives with probability one-half. The two illustrative masks average back to x. This establishes an activation expectation, not an exact nonlinear model average.
Check: Does inverted dropout guarantee that two real training passes average exactly to the unmasked input?
Read it this way: With keep probability 1/2, activation 4 becomes either 0 or 8. Their average is 4; neither individual pass preserves the input.
Does one pass return the mean of the two branches?

For the counterexample , , and , but . Preserving E[y] therefore does not prove an exact ensemble prediction after subsequent nonlinear computation.

Change Drop Probability

New task: Reduce p from one-half to one-quarter for coordinate value two.

Picture and change: The retained value becomes with probability , rather than four with probability one-half.

Check: Mean remains two while variance falls from four to . One retained output is not the expectation.

Use when: Held-out behavior supports changing stochastic regularization strength; no architecture-independent rate is optimal.

Share a Mask over a Feature Map

New task: Drop whole channels in a two-channel activation.

Picture and change: Broadcast mask [1,0] over spatial positions at p one-half. Channels constant at one and three become constant maps two and zero.

Check: Independent element masking could keep just one pixel in the second channel; this channel-shared mask cannot. Marginal expectations still match, but correlations between masked positions differ.

Use when: The intended regularizer removes an entire correlated feature map.

PyTorch nn.Dropout(p) follows its module’s train/eval mode; standard evaluation returns x without inverted scaling.

Disabling gradient recording with no_grad alone does not change that mode. Evaluation mode alone does not disable gradients.

Where to apply

ArchitectureWhere dropout typically goesTypical
CNNElement or channel masking at chosen sitesTune against a matched baseline
TransformerSelected attention, FFN, or residual sitesZero is also a candidate
RNNInter-layer or explicitly time-shared masksMatch the recurrent implementation
EmbeddingsSelected input featuresPreserve task semantics

Variants

Relation to other regularization

Noise-induced penalties can be derived for restricted models, but dropout is not generally identical to weight decay. Normalization, augmentation, and masking can interact rather than contributing independent benefits.

Common pitfalls

  • Mode confusion: intentionally sampling dropout at inference differs from standard evaluation and does not automatically yield calibrated uncertainty.
  • Unsupported causality: a smaller train/validation gap alone does not prove improved deployment quality.
  • Wrong mask units: element, channel, timestep-shared, weight, and branch masks induce different dependencies.