LLMUnit 1 · The foundations · Day 03

Recurrent Neural Network Regularization

Dropout breaks an LSTM's memory if you put it everywhere. Put it only between layers, never along time, and big recurrent models stop overfitting.

AuthorsWojciech Zaremba, Ilya Sutskever, Oriol Vinyals
Year / venue2014 · arXiv (1409.2329)
Core ideaDropout on non-recurrent connections only
Study time2–3 h

Original: arXiv:1409.2329 · Code, notebook and exercises: 30u30 Day 3

Start here (no maths needed)

To stop a big memory-network from just memorising its homework, you switch off random parts of it while it trains, but never the part that carries its memory.

Think of it like this

Imagine a football team that only practises with all 11 players every time. They might rely too much on one star player. A coach could make random players sit out each drill, so everyone learns to play well. That is "dropout". But if the coach also kept taping over the team's playbook between plays, the team would forget the plan. This paper says: bench random players, but leave the playbook alone.

How it works

  1. The network has layers stacked on top of each other, and it also passes a memory forward through time.
  2. During training, random parts of the signal going up between layers are switched off for a moment.
  3. The memory going forward in time is never switched off.
  4. So the network has to learn several ways to get the answer, which makes it better on new examples.
  5. When the network is actually used, nothing is switched off.

Why robots care

Robot training data is expensive. Someone has to show the robot a task by hand, again and again. With only a few hundred examples, a big network can just memorise them and fail on anything new. Tricks like this help a robot's memory-network learn the skill instead of the exact examples.

Try it

Words to know

Overfitting
When a program memorises its training examples but does badly on new ones.
Regularisation
Any trick that stops overfitting.
Dropout
Switching off random parts of a network during training.
Recurrent connection
The link that carries memory from one time step to the next.

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

In 2014, dropout was the best regulariser for feed-forward nets, but it was widely believed not to work for RNNs: noise on the recurrent connection gets amplified step after step. So people kept RNNs small to avoid overfitting. This short paper shows the fix is about where you drop. Apply dropout to the vertical connections (input to layer 1, layer to layer, top layer to output) and leave the horizontal, time-to-time connections clean. Large LSTMs then generalise much better on language modelling, speech, translation and captioning.

2. The core idea

Take a stack of L LSTM layers. Superscript l is the layer, subscript t the time step. h0_t is the input word vector. Each layer computes its four gates from two vectors: the output of the layer below at this step, and its own output at the previous step. The paper's change is one operator, D, which zeroes a random subset of its input:

(i, f, o, g) = (σ, σ, σ, tanh)( W · [ D(h^{l−1}_t) , h^l_{t−1} ] + b )
c^l_t = f ⊙ c^l_{t−1} + i ⊙ g
h^l_t = o ⊙ tanh(c^l_t)
prediction at t uses D(h^L_t)

3. Deep dive

The L+1 argument

Follow a fact from the input at time t−k to the prediction at time t. It enters through the input dropout, travels sideways through the recurrent connections for k steps, and climbs one layer at a time to the output. Under this scheme it meets dropout once per vertical hop, so L+1 times in total, and that number doesn't depend on k. If you also dropped the recurrent connection, every extra time step would add another hit, and long-range memory would decay geometrically.

Interactive: count the dropout hits

A fact enters at step t−k and is needed at step t. Dashed arrows have dropout. Each mask keeps a unit with probability 1−p, so a single unit's path survives all masks with probability (1−p)hits.

Hits, paper
–
Hits, naive
–
Survive, paper
–
Survive, naive
–

The survival number is a simplification: real information is spread over many units, so one dropped unit doesn't erase a fact. But the scaling is the point: with the naive scheme the damage grows with distance, with the paper's scheme it doesn't.

What the experiments showed

Limits and what came after

4. Why it matters for robotics

5. How to study it

  1. Read the paper (8 pages, about 45 min). Focus on Section 3.2 and Figures 2–3.
  2. In the 30u30 Day 3 folder, read implementation.py and find exactly where the dropout masks are applied. Run train_minimal.py.
  3. Do the exercises: the dropout exercise is the paper itself. The others (normalisation, weight decay, early stopping, full pipeline) are standard companions.
  4. Experiment: add dropout to the recurrent path too and compare validation perplexity and the train/validation gap.
  5. Stretch: implement variational dropout (one mask per sequence) and compare.

6. Self-check

Which connections get dropout in this scheme?

Only the non-recurrent ones: input to the first layer, each layer to the next at the same time step, and the top layer to the output.

How many times is information hit by dropout between input and prediction?

L+1, where L is the number of layers, independent of how many time steps it travels.

Why did people keep RNNs small before this paper?

Without a working regulariser, large RNNs overfit. The best unregularised PTB model in the paper had just 200 units per layer.

Training accuracy went down but validation went up. Is that bad?

No. Dropout makes training harder on purpose. The useful number is validation or test performance, and that improved.

How did later work manage to regularise the recurrent path?

By sampling one dropout mask per sequence and reusing it at every step (variational dropout), or by dropping recurrent weights rather than activations (DropConnect, as in AWD-LSTM).

7. Further reading