Dropout and regularization

core 10 minfundamentalsregularizationtraining

Builds on:Forward pass

The idea

Modern networks have enough parameters to memorize their training sets outright, so generalization comes from constraining how they fit — regularization. The deep-learning toolkit has one method with a genuinely novel mechanism (dropout), plus classical tools carried over.

Dropout. During training, each unit is independently zeroed with probability pp; survivors are scaled by 1/(1−p)1/(1-p) (this is inverted dropout, what every framework implements). Formally, with mask entries mi∼Bernoulli(1−p)m_i \sim \mathrm{Bernoulli}(1-p):

a~i=mi1−p ai,E[a~i]=(1−p)1−pai=ai\tilde{a}_i = \frac{m_i}{1-p}\, a_i, \qquad \mathbb{E}[\tilde{a}_i] = \frac{(1-p)}{1-p} a_i = a_i

The expectation is preserved, so at test time you simply switch dropout off and run a normal forward pass. Why it works, two complementary stories: (1) no co-adaptation — a unit cannot depend on a specific other unit existing, so features become individually useful and redundant; (2) implicit ensemble — every mask is a different subnetwork with shared weights, and the test-time network approximates averaging exponentially many of them.

The rest of the toolkit: weight decay (penalize ∥θ∥2\|\theta\|^2; use AdamW so it is not mangled by adaptive scaling), early stopping (halt when validation loss turns; free and always on), data augmentation (label-preserving transforms — the highest-leverage option for images and audio), and label smoothing (soften the one-hot target to 1−α+α/K1-\alpha+\alpha/K for the correct class — 0.910.91 at α=0.1\alpha=0.1, K=10K=10 — and α/K\alpha/K for each wrong class; discourages overconfident logits).

Batch/layer normalization sit adjacent: they exist to stabilize optimization, not to regularize, but BN's minibatch noise has a mild regularizing side effect, and their mechanics are tested in the same interviews — key facts in the cheat sheet.

Worked example

A hidden layer outputs a=(2,−1,3,0.5)a = (2, -1, 3, 0.5) with dropout p=0.5p = 0.5. One training step draws mask m=(1,0,1,0)m = (1, 0, 1, 0):

a~=(1,0,1,0)⊙(2,−1,3,0.5)1−0.5=(4,  0,  6,  0)\tilde{a} = \frac{(1, 0, 1, 0) \odot (2, -1, 3, 0.5)}{1 - 0.5} = (4,\; 0,\; 6,\; 0)

Surviving units are doubled; dropped units contribute nothing (and get no gradient this step — the mask gates the backward pass identically). The next minibatch draws a fresh mask, say m=(0,1,1,1)m = (0, 1, 1, 1), giving a~=(0,−2,6,1)\tilde{a} = (0, -2, 6, 1): a different subnetwork now takes the gradient step, though it shares every weight with the first. Training is effectively a lottery over 24=162^4 = 16 subnetworks of this layer — that is the ensemble picture in miniature.

Check the expectation for the first unit across the mask distribution: it survives with probability 0.50.5 at value 44, else 00 — expected value 0.5⋅4=20.5 \cdot 4 = 2, exactly the original activation. Downstream weights therefore see the same average input during training as they will at test time, when the layer just emits (2,−1,3,0.5)(2, -1, 3, 0.5) untouched. Without the 1/(1−p)1/(1-p) scaling, training-time activations would average half the test-time ones, and the network would arrive at inference systematically miscalibrated.

Cheat sheet

Dropout

Norm layers (the facts interviews want)

Batch normLayer norm
Normalizes overbatch, per channelfeatures, per example
Formula core(x−μB)/σB2+ϵ(x - \mu_B)/\sqrt{\sigma_B^2 + \epsilon}, then γ,β\gamma, \betasame, with per-example μ,σ\mu, \sigma
Train vs evaldifferent (batch stats vs running stats)identical
Small/variable batchesbreaks below ~8unaffected
Home turfconvnetstransformers, RNNs

Other regularizers

Symptom → move: big train/val gap → augment + early stop + decay + dropout, in that order; train accuracy also low → you have a bias problem, regularizing makes it worse.