LLM + RoboticsUnit 2 · Deep learning explosion · Day 12

Dropout: A Simple Way to Prevent Neural Networks from Overfitting

Randomly switch off half the neurons on every training step. Each neuron learns to be useful on its own, and the trained network behaves like an average of exponentially many smaller ones.

AuthorsNitish Srivastava, Geoffrey Hinton, Alex Krizhevsky, Ilya Sutskever, Ruslan Salakhutdinov
Year / venue2014 · JMLR 15
Core ideaRandom thinning as model averaging
Study time2–4 h

Original: jmlr.org · Code, notebook and exercises: 30u30 Day 12

Start here (no maths needed)

If a network has to learn while random parts of it are switched off, it stops relying on any one part and does better on new examples.

Think of it like this

Think of a football team that trains with random players sitting out every practice. Nobody can rely on the one star player always being there, so everyone learns to play well with whoever is on the pitch. On match day the whole team plays, and it's stronger for it.

How it works

  1. During training, every time the network sees an example, it flips a coin for each unit (a tiny part of the network).
  2. Units that lose the coin flip are switched off for that example.
  3. The network learns with whatever units are left.
  4. Next example, new coin flips, so a different set of units is switched off.
  5. When the training is finished, all units are switched on, and their outputs are turned down a bit to make up for it.

Why robots care

A robot often learns from only a few hundred demonstrations, so it can easily memorise them instead of really learning. Dropout helps stop that. Also, if you leave dropout on and ask the robot's network the same question several times, the answers spread out when it is unsure. A robot can use that as a sign to slow down or ask for help.

Try it

Words to know

Unit (neuron)
One small piece of a neural network that passes a number along.
Overfitting
Memorising the training examples instead of learning what works on new ones.
Dropout
Randomly switching off units during training.
Keep probability
The chance that a unit stays switched on.
Uncertainty
How unsure the network is about its answer.

Going deeper: everything below is the full version, with some maths. On a first read, skim the headings and the "Why it matters for robotics" box, and come back for the rest later.

1. Summary

TL;DR

Averaging many separately trained networks reduces overfitting, but it's too slow to train and to run. Dropout gets most of the benefit inside a single network. During training, each unit is kept with probability p and otherwise zeroed, with a fresh random mask for every example. A network with n units becomes a family of 2ⁿ "thinned" networks that all share weights. At test time you use the full network with weights scaled by p, which approximates averaging the whole family. The journal paper shows gains in vision, speech, text and genetics. The method had already helped AlexNet win ImageNet (Day 08).

2. The core idea

For layer l with outputs y⁽ˡ⁾, a standard network computes z = W·y + b, then y⁽ˡ⁺¹⁾ = f(z). With dropout:

r_j ~ Bernoulli(p)                 # 1 = keep, 0 = drop; fresh for every example
ỹ   = r ⊙ y                        # thinned outputs
z   = W · ỹ + b
y'  = f(z)

test time:  W_test = p · W          # no sampling, scaled weights

3. Deep dive

Seeing the masks and the averaging

Interactive: one hidden layer under dropout

Left: a 64-unit hidden layer, with dropped units greyed out. Right: a linear unit that reads this layer. The line shows the running average of its output over k sampled masks, converging to the weight-scaled value (dashed).

Units kept now
–
Weight-scaled
–
MC avg, k=200
–

Each mask is a different thinned network. Their average output lands on p·w·y, the weight-scaled answer, because the unit is linear. Drag p towards 1 and the masks stop doing anything. Drag it low and single samples get very noisy. That noise is both the regulariser and the reason training is slower.

Why it works: three views

The paper adds a practical tip: combine dropout with a max-norm constraint (cap each unit's incoming weight vector at norm c). That allows high learning rates without weights blowing up. Its motivating analogy comes from evolution, where sexual reproduction breaks up co-adapted genes.

Limitations, and what came after

4. Why it matters for robotics

5. How to study it

  1. Read Sections 1–5 and 7 of the paper (about 1.5 h). Skim the RBM section. Keep track of which p convention is in use.
  2. In the 30u30 Day 12 folder, read implementation.py. Compare the naive (scale at test) and inverted (scale at train) versions, then the spatial, DropConnect, DropBlock and MC-dropout variants. Run train_minimal.py.
  3. Work through notebook.ipynb, then the exercises: dropout from scratch, a rate sweep, spatial dropout, Monte Carlo dropout and a comparison with other regularisers.
  4. Check that the forward pass in train mode has the same mean as eval mode, averaged over many masks. That is the demo above in code.
  5. Stretch: train a small regressor on robot-like data (for example joint angles to end-effector position) and plot MC-dropout spread inside and outside the training range.

6. Self-check

In this paper, what does p = 0.8 on the inputs mean?

Each input unit is kept with probability 0.8, so 20% are dropped. In PyTorch you would write Dropout(0.2).

Why scale weights by p at test time?

During training a unit is present only a fraction p of the time. Scaling by p makes the expected input to the next layer at test time match what it saw in training.

How many thinned networks does a net with n droppable units define?

2ⁿ. Each one shares weights with the others, and most are never sampled even once.

Why does dropout slow training?

Every example trains a different random subnetwork, so gradients are noisy and not exactly the gradients of the final network.

How do you get an uncertainty estimate from a dropout network?

Keep dropout on at inference, run several forward passes and look at the spread of the outputs (MC dropout). Calibrate it before relying on it.

7. Further reading