3.2.10 · D4Training Deep Networks

Exercises — Dropout regularization

2,432 words11 min readBack to topic
Figure — Dropout regularization

Everything below rests on three quantities from the parent note:

Here just means: flip a biased coin that lands "1" (keep) with probability and "0" (drop) with probability . See Bernoulli Distribution if that coin is new to you.


Level 1 — Recognition

Exercise 1.1

A framework documentation says Dropout(p=0.3). Following the PyTorch / original-paper convention, what fraction of neurons are kept on each forward pass, on average?

Recall Solution

p is the drop probability, so means dropped. So on average of neurons are kept. What we did: translated the label into keep-probability using . Why: frameworks name p as drop, and every scaling formula uses .

Exercise 1.2

True or false: dropout is active during test-time inference.

Recall Solution

False. Dropout is a training-only technique. At test time every neuron is used, deterministically. With inverted dropout the scaling was already applied during training, so the test forward pass is a plain forward pass.


Level 2 — Application

Exercise 2.1

A hidden layer outputs . You use inverted dropout with . The sampled mask this step is . Compute the layer's output .

Recall Solution

Step 1 — keep probability. , so the scale factor is . Step 2 — apply mask (elementwise multiply ): Step 3 — rescale survivors by : Why the boost: dropping shrinks the expected signal to ; multiplying survivors by cancels that shrink so the expected output equals the original .

Exercise 2.2

For a single neuron with activation under inverted dropout with , list the two possible values of and the probability of each. Then compute and confirm it equals .

Recall Solution

, scale .

  • Neuron kept (), probability : .
  • Neuron dropped (), probability : .

Expectation: The scaling is exactly what makes the average land back on the un-dropped value.


Level 3 — Analysis

Exercise 3.1

A layer has dropable units. (a) How many distinct thinned sub-networks can dropout sample? (b) What is the probability that a specific sub-network (a specific on/off pattern) is chosen on one step, if ?

Recall Solution

(a) Each unit is independently ON or OFF — 2 states. With independent units the number of patterns is This is the " sub-networks" figure that makes dropout an approximate ensemble. (b) With each unit is ON or OFF with probability , and the units are independent, so every one of the patterns is equally likely: Note: equal probability only holds at . For other a pattern with kept units has probability , which varies across patterns.

Exercise 3.2

Show that under inverted dropout the variance injected into a single activation grows as the drop probability increases. Compute for a fixed activation , then evaluate it at and with , and state which is noisier.

Recall Solution

Write with . A Bernoulli() variable has . Since is a constant multiplier, pull it out (variance scales by the square of a constant): Why : the ratio is small when is small and blows up as — more dropping, more noise. With :

  • : .
  • : .

So injects the variance of — it is noisier. This noise is exactly the "smoother function" mechanism from the parent note, and it is why input layers use a smaller (you don't want to corrupt the raw data too hard).

Figure — Dropout regularization

Level 4 — Synthesis

Exercise 4.1

You are told a network trained without scaling: it used the original (non-inverted) convention, meaning masking with no train-time boost, and a test-time scale-down. Its layer produces raw test-time activation for some unit, and it was trained with . What test-time output should this unit produce, and why is inverted dropout usually preferred over doing this?

Recall Solution

Original convention: no scaling at train time, so during training the next layer saw an expected input of . To match that at test time (all units on), you must scale down by : Why inverted is preferred: inverted dropout puts the scaling into the training path, leaving the test / inference forward pass as a plain, unmodified pass. That means deployment code is simpler and you cannot forget the correction at inference time — the most error-prone moment.

Exercise 4.2

Design choice. You have a 3-layer MLP overfitting badly (train accuracy , val accuracy — a large variance gap). You must pick dropout rates for: (i) the input layer, (ii) the two hidden layers. Choose sensible values, justify each, and explain how you'd expect the generalization gap to move.

Recall Solution

(i) Input layer: small drop, e.g. . Reason: inputs are the raw signal; dropping too many corrupts the data itself (recall from 3.2 that grows fast with ). Pick . (ii) Hidden layers: stronger drop, e.g. . Reason: this is where co-adaptation and memorisation live; maximises the number of effectively-explored sub-networks and injects the most regularising noise. Pick . Expected effect: train accuracy will drop (the model is now handicapped during training — good, it means less memorisation), while val accuracy rises, shrinking the -point gap. This is trading a little bias for a large variance reduction — the exact bargain weight decay and dropout both offer.


Level 5 — Mastery

Exercise 5.1

Ensemble equivalence, worked exactly. Consider a linear unit with two inputs and no bias: output . Apply independent dropout with keep probability to each input using inverted dropout, so the actual output is Show that (dropout is unbiased for a linear unit), i.e. the ensemble's average prediction equals the full-network prediction. Verify numerically with by averaging over all four masks.

Recall Solution

Symbolic. Expectation is linear, and : So the inverted-dropout output is an unbiased estimate of the full output — the average over sub-networks is the full network, exactly, for a linear unit. (For nonlinear units it is only an approximation, which is why test-time scaling is called approximate ensembling.)

Numeric check (, scale ). Full output: . The four equally-likely masks give:

  • :
  • :
  • :
  • :

Average . The ensemble mean lands exactly on the full-network prediction.

Exercise 5.2

Effective learning-rate / weight-scaling insight. A common claim: "for a linear neuron, dropout on the input behaves like an -style penalty on the weights that scales with ." Using the variance result from Exercise 3.2, argue heuristically why larger acts like a stronger weight penalty, and compute the relative penalty strength ratio between and .

Recall Solution

Heuristic. The squared-error loss on a noisy input has an expected value that splits into (loss on the clean signal) (a term proportional to the injected variance). For a linear unit that variance term is . Minimising it pushes down — precisely what an / weight-decay penalty does. The penalty strength is governed by the factor : bigger ⇒ bigger factor ⇒ stronger implicit shrinkage. Ratio. So imposes roughly a stronger implicit weight penalty than . This quantifies why hidden layers (want strong regularisation) use while inputs (want gentle regularisation) use .


Active Recall

Question: Scale factor for surviving activations in inverted dropout
.
Question: Number of sub-networks for dropable units
, equally likely only when .
Question: Injected variance of a single activation
, exploding as .
Question: Is dropout exactly ensemble-equivalent for deep nets
Only for linear units; nonlinearities make it an approximation.

Connections

  • Overfitting and Generalization — every exercise here targets shrinking the generalization gap.
  • Ensemble Methods (Bagging) — Exercises 3.1 and 5.1 make the ensemble view concrete.
  • L2 Regularization (Weight Decay) — Exercise 5.2 links dropout to an implicit weight penalty.
  • Bias-Variance Tradeoff — Exercise 4.2 is a pure bias-variance trade in action.
  • Bernoulli Distribution — the mask throughout.
  • Batch Normalization — an alternative regulariser worth comparing when tuning dropout.
  • 🇮🇳 Hinglish version of the parent note.