Skip to content
AI360XpertBeta
Core ML

Visual explainer

Dropout

Trace independent masks, survivor scaling and evaluation through four activations. See why matching expectations does not match every prediction.

Dropout temporarily removes randomly selected activations during training. Surviving activations are scaled so their expectation stays unchanged; evaluation uses the complete layer. This can reduce dependence on particular combinations of units, but it adds noise and does not guarantee a validation improvement.

A fixed readout adds four activation contributions.
A fixed readout adds four activation contributions.

Start with a deliberately small synthetic readout: four activations are all 1, and each outgoing weight is 2. The four short mint strokes represent equal contributions of 2, so the linear readout is 8. Connector lengths are schematic; only the contribution strokes encode magnitude. There is no bias or alternate path. We freeze weights to isolate what masking does; this sequence does not simulate an entire training run.

Sample Independent Masks

Independent mask draws can leave different numbers of survivors.
Independent mask draws can leave different numbers of survivors.

Circles survive; crosses are dropped. The two rows are possible fresh draws, not a rule that changes just one unit each time. At drop probability p = 0.5, mask [1,0,1,0] has two survivors, while [1,1,1,0] has three. Each complete mask has probability 1/16. Independence means half survive on average, not exactly half on every call.

Scale The Survivors

Inverted dropout doubles survivors when the keep probability is one half.
Inverted dropout doubles survivors when the keep probability is one half.

The bars show activations on identical vertical scales: the original value 1 becomes either 2 or 0. Let q = 1 − p be the keep probability and mᵢ the sampled zero-or-one mask. Inverted dropout computes:

hi′=mihiq.h'_i = \frac{m_i h_i}{q}.

With q = 0.5 and mask [1,0,1,0], h′ = [2,0,2,0]. The fixed outgoing weights remain 2, giving contributions [4,0,4,0] and readout 8. With three survivors the readout would be 12. Scaling changes activations during training; it does not overwrite learned weights. This is the convention documented by PyTorch Dropout.

Restore The Full Layer

Evaluation restores all activations without scaling inverted-dropout outputs.
Evaluation restores all activations without scaling inverted-dropout outputs.

All four activation bars return to height 1, using the same activation scale as the previous picture. The inverted-dropout operation becomes identity in evaluation: [1,1,1,1] reaches the same fixed readout and sums to 8.

The original dropout paper also describes the equivalent placement of scaling at test time: leave training survivors unscaled, then multiply their outgoing weights by q for evaluation. Choose one convention consistently. Applying both corrections scales twice.

Match The Expected Sum

Dropout preserves the linear sum in expectation rather than in every draw.
Dropout preserves the linear sum in expectation rather than in every draw.

The five bars count all 16 equally likely masks. From left to right, the readouts 0, 4, 8, 12 and 16 occur for 1, 4, 6, 4 and 1 masks. Bar height counts masks, while horizontal position gives readout. The dashed line locates the expected readout, 8:

E[S]=0+4(4)+6(8)+4(12)+1616=8.\mathbb{E}[S]=\frac{0+4(4)+6(8)+4(12)+16}{16}=8.

For each activation, E[mᵢhᵢ/q] = hᵢ. Here S = 4K with K binomial with four trials and success probability 0.5. Its variance is 16, so matching the mean leaves substantial per-call variation. No train/test accuracy figure follows from this arithmetic.

Change The Drop Rate

A larger drop rate makes each survivor larger.
A larger drop rate makes each survivor larger.

Zoom into one original activation of 1. The outcome bars share a new scale of 45 SVG units per activation unit, rather than 80 in the earlier activation views. At p = 0.5 it is 0 or 2, each with probability 0.5. At p = 0.75 it is 0 with probability 0.75 or 4 with probability 0.25. Both means equal 1; the latter has variance 3 instead of 1. Bar height encodes the surviving value, not its probability.

A higher rate adds stronger noise and can make a small model underfit. Tune rates and placement with validation data; 0.5 is a teaching choice here, not a universal prescription for hidden layers.

Switch To Evaluation

Training mode produces varying readouts for the same fixed input.
Training mode produces varying readouts for the same fixed input.

Three possible training calls produce sums 0, 8 and 12 for the same input and frozen weights. Three evaluation calls give 8. The rulers share the 0–16 scale; vertical stacking in the lower lane separates identical observations and carries no numerical meaning. The bracket spans these selected training outcomes, not the full distribution.

For an ordinary deterministic prediction with a PyTorch module, call model.eval(); disabling gradient recording alone does not switch dropout off. Deliberately sampling at inference, as in Monte Carlo dropout, is a different procedure that needs aggregation and its own interpretation. A thinned network shares parameters with the full network; it is not an independently trained ensemble member.

Gate The Backward Path

The sampled mask also gates the local backward derivative.
The sampled mask also gates the local backward derivative.

Read this scene right to left, following the backward arrows. For a fixed sampled mask, ∂h′ᵢ/∂hᵢ = mᵢ/q. An upstream derivative of 1 therefore becomes 2 for a kept activation and 0 for a dropped activation when q = 0.5. Arrow length compares these derivative magnitudes; circles show the local multiplier.

The same forward mask controls this local backward path. Zero through one dropped activation does not mean every gradient of a shared weight, batch or alternate network path vanishes.

Nonlinear Outputs Differ

A nonlinear output can differ from the mean of masked outputs.
A nonlinear output can differ from the mean of masked outputs.

Keep one activation h = 1 and p = 0.5, then apply f(z) = max(0, z − 1), a ReLU with a bias of −1. The left plot uses z horizontally and f(z) vertically. Masked values z = 0 and z = 2 give outputs 0 and 1 with equal probability. Their mean is 0.5, shown by the right bar. Deterministic evaluation gives f(1) = 0, shown by the cross. Right-side heights use 180 SVG units per output unit.

Thus E[f(h′)] = 0.5 differs from f(E[h′]) = 0. Scaling preserves an activation's expectation, and a linear readout's expectation, but generally does not reproduce the average output of an entire nonlinear network.

Where It Breaks

A high drop rate can remove every activation in a narrow layer.
A high drop rate can remove every activation in a narrow layer.

Return to the four-unit layer with a deliberately high p = 0.75. The pictured mask drops all four activations, so this bias-free readout becomes 0 and the local paths through the layer carry no gradient. Independence gives:

P(all dropped)=p4=0.754=0.31640625.P(\text{all dropped})=p^4=0.75^4=0.31640625.

About 31.6% of draws empty this narrow layer. Other layers, biases and skip paths can change a real network's behavior; this calculation concerns this four-unit bottleneck. Dropout is useful only when its regularization benefit outweighs lost signal and optimization noise. Check held-out performance rather than assuming that more masking helps.

The Quick Version

  • Four fixed contributions establish the readout before masking.
  • Independent draws do not fix the survivor count.
  • Inverted dropout divides survivors by the keep probability.
  • Evaluation uses the full layer without another scaling correction.
  • Matching expectations still leaves random readouts.
  • Higher drop rates enlarge survivors and increase variance.
  • Evaluation mode disables ordinary dropout sampling.
  • The forward mask also gates the local backward derivative.
  • Nonlinear outputs need not equal their masked-output average.
  • High rates can empty narrow layers and discard useful signal.