3.2.10Training Deep Networks

Dropout regularization

1,727 words8 min readdifficulty · medium2 backlinks

WHAT is Dropout?

  • pp = probability a neuron is dropped (typical: 0.50.5 for hidden, 0.10.10.20.2 for input).
  • q=1pq = 1-p = probability a neuron is kept.
  • Dropout is applied to activations, not weights.

WHY does it work?


HOW: the math, derived from scratch

Training-time forward pass

For a layer output aa, define a mask vector rr where each component is:

riBernoulli(q),q=1pr_i \sim \text{Bernoulli}(q), \qquad q = 1-p

The dropped activation is:

a~i=riai\tilde{a}_i = r_i \, a_i

Only the surviving neurons (ri=1r_i=1) pass forward; the rest are zeroed.

The scaling problem — derived

Why do we need scaling? Look at the expectation of a single dropped activation:

E[a~i]=E[ri]ai=qai\mathbb{E}[\tilde a_i] = \mathbb{E}[r_i]\, a_i = q\, a_i

Why this step? rir_i is Bernoulli(qq), so E[ri]=q\mathbb{E}[r_i] = q. Dropping shrinks the expected signal by a factor qq.

At test time we keep all neurons, so the raw activation is aia_i — which is 1/q1/q times bigger than what the next layer saw during training. The next layer's weights were tuned to the smaller training-scale input, so test activations would be inflated → mismatch.

Fix (two equivalent conventions):

Why inverted is preferred: the test-time / inference code stays clean (just a normal forward pass), and all the extra work happens only during training.


Figure — Dropout regularization

Worked Example 1 — one hidden layer

Suppose a hidden layer produces activations a=[2,4,6,8]a = [2, 4, 6, 8] and we use inverted dropout with p=0.5p = 0.5 so q=0.5q = 0.5.

Sampled mask this step: r=[1,0,1,0]r = [1, 0, 1, 0].

Step 1 — apply mask. ra=[2,0,6,0]r \odot a = [2, 0, 6, 0] Why? Neurons 2 and 4 were dropped → forced to 0.

Step 2 — rescale by 1/q=21/q = 2. a~=[4,0,12,0]\tilde a = [4, 0, 12, 0] Why? On average only half the neurons survive, so surviving ones are boosted 2×2\times to keep the expected sum the same as [2,4,6,8][2,4,6,8].

Check the expectation over many masks: each aia_i appears with prob q=0.5q=0.5, scaled by 22, giving mean 0.52ai=ai0.5\cdot 2\cdot a_i = a_i. Expected activation = original. ✅


Worked Example 2 — why co-adaptation breaks

Two neurons h1,h2h_1, h_2 jointly detect "cat" only when both fire strongly (co-adapted).

  • Without dropout: the net learns y=w1h1+w2h2y = w_1 h_1 + w_2 h_2 that only works when both present.
  • With p=0.5p=0.5: half the time h2h_2 is dropped. The net still gets the "cat" gradient, so h1h_1 alone must carry useful signal.

Why this step matters: the pressure to perform under random absences forces redundant, robust features — the essence of the regularization.


Common Mistakes


Recall Feynman: explain to a 12-year-old

You're on a sports team and the coach randomly benches some players every practice. Because you never know who'll be missing, everyone has to learn to play well and cover for each other. On game day (test time) everyone plays — and the team is way stronger because nobody is a weak link that others secretly relied on. Dropout benches random neurons during practice so the network stops depending on any single one.


Active Recall

What does dropout randomly set to zero during training?
Neuron activations (outputs), each with drop probability pp, independently per forward pass.
In inverted dropout, by what factor are surviving activations scaled at train time?
By 1/q=1/(1p)1/q = 1/(1-p), to keep the expected activation equal to the un-dropped value.
Why is scaling needed at all?
Because dropping reduces the expected activation to qaq\cdot a; without correction, test-time (full) activations would be 1/q1/q times larger than what the next layer was trained on.
Is dropout applied at test time?
No — at test time all neurons are used deterministically; only the scaling correction is applied (baked in for inverted dropout).
What problem in the network does dropout mainly attack?
Co-adaptation / overfitting — neurons over-relying on specific other neurons to fit training noise.
Roughly how many sub-networks does dropout implicitly ensemble over nn dropable units?
About 2n2^n possible thinned sub-networks.
Typical drop probability for hidden layers vs input layers?
~0.5 for hidden layers, ~0.1–0.2 (smaller) for input layers.
E[riai]\mathbb{E}[r_i a_i] where riBernoulli(q)r_i\sim\text{Bernoulli}(q)?
qaiq\,a_i, since E[ri]=q\mathbb{E}[r_i]=q.

Connections

  • Overfitting and Generalization — dropout is a tool to reduce the generalization gap.
  • L2 Regularization (Weight Decay) — alternative/complementary regularizer; dropout acts like an adaptive penalty.
  • Ensemble Methods (Bagging) — dropout ≈ implicit bagging over sub-networks.
  • Batch Normalization — interacts with dropout; often BN reduces the need for it.
  • Bernoulli Distribution — the mask's underlying probability model.
  • Bias-Variance Tradeoff — dropout trades a bit of bias for a large variance reduction.

Concept Map

uses

produces

causes

trains

injects

yields

gives

creates

fixed by

fixed by

preferred over

Dropout regularization

Bernoulli mask r ~ q

Zero neuron with prob p

Prevents co-adaptation

Approximate ensembling 2^n subnets

Adds multiplicative noise

Smoother loss surface

Expected activation = q times a

Scaling problem train vs test

Inverted dropout scale by 1/q

Original dropout scale by q at test

Hinglish (regional understanding)

Intuition Hinglish mein samjho

Dropout ka core idea simple hai: training ke time har forward pass mein hum randomly kuch neurons ko off kar dete hain (unka output zero). Probability pp se drop hote hain, aur q=1pq = 1-p probability se survive karte hain. Isse network kisi ek neuron par depend karna band kar deta hai — sab neurons ko apne aap useful feature seekhna padta hai. Isko co-adaptation rokna kehte hain, aur yahi overfitting ko kam karta hai.

Ab scaling wali baat zaruri hai. Jab aap neurons drop karte ho, average activation qq guna chhoti ho jaati hai. Test time pe hum saare neurons use karte hain (koi drop nahi), toh activation 1/q1/q guna bada ho jayega — mismatch! Iska fix hai inverted dropout: training mein surviving neurons ko 1/q1/q se multiply kar do. Tab expected activation same rehti hai (q×1/q=1q \times 1/q = 1), aur test time pe kuch bhi extra nahi karna — bas normal forward pass.

Yaad rakho: dropout sirf training mein on hota hai, test/inference mein off. Aur PyTorch mein p ka matlab drop probability hai (kitne gire), keep nahi. Ek acha mental model: coach randomly players ko bench karta hai practice mein, taaki poori team strong bane; match ke din sab khelte hain. Isliye dropout ek sasta ensemble (2n2^n thin networks ka average) bhi de deta hai — regularization + robustness dono free mein.

Go deeper — visual, from zero

Test yourself — Training Deep Networks

Connections