Skip to content

3.5 Training in practice

ready≈ 11.5 hoursNeeds: 3.3, 3.4, 2.5
  1. 1 Learn
  2. 2 Bridge & derive
  3. 3 Explore (Training-curve clinic, Dropout visualizer)
  4. 4 Do
  5. 5 Check

Neural network bugs are silent. A wrong shape raises an error, but a shuffled label, a missing normalisation or a schedule that never steps just gives a model that is somewhat worse, and nothing tells you why. Karpathy’s recipe is built around that: become one with the data first, start from a model too simple to get wrong, check the loss at initialisation (about log⁡k\log k for kk balanced classes), and overfit a single batch to near zero before scaling up (Karpathy 2019). Only once the model can overfit do you add regularisation to win back validation performance.

Read the curves. Plot training and validation loss together, every time. Loss that spikes or goes NaN means the learning rate is too high. A slow, straight decline means it is too low. A widening gap with rising validation loss means overfitting, and both curves stuck high together mean underfitting. If training loss falls while validation loss stays near chance and then climbs, suspect the data, not the model: what it learns does not carry over. If training loss is stuck near chance too, suspect the model first (CS231n, babysitting the learning process). The clinic below has one real run of each.

Dropout zeroes each hidden unit with probability pp during training, a different random set for every example and every step. No unit can rely on a particular partner, and the network is in effect training an exponentially large family of thinned sub-networks that share weights (Srivastava et al. 2014; UDL §9.3.3). Inverted dropout divides the kept units by 1−p1-p during training, so the expected activation is unchanged and evaluation simply turns dropout off. The full network then approximates the average of all sub-networks. Forgetting to turn it off at evaluation gives random predictions, which is one of the bugs in the lab.

Training-curve clinic

Debugging training

Static view on small screens. Open this page on a laptop to interact.

Case 1 of 6score 0
0.000.751.502.253.00chance: log 2training step → (loss)
training lossvalidation loss

Every curve is a real training run of a small network on a 2-D dataset, computed in your browser with full-batch Adam. Read the shape first: is the training loss falling, and does the validation loss follow it?

Six real training runs of a small network, shown one at a time as training and validation loss curves with the chance level marked. For each, choose a diagnosis: healthy, learning rate too high or too low, overfitting, a data bug, or underfitting. The widget then explains the symptoms and the fix. Keyboard: Tab to a diagnosis button and press Enter; then Next case.

Dropout visualizer

Dropout as an implicit ensemble

Static view on small screens. Open this page on a laptop to interact.

hidden layer 1
hidden layer 2
one thinned sub-network
94% correct
full network, eval mode
95% correct
average of 40 sub-networks
95% correct

The network (two hidden layers of 32 ReLUs) is trained with a fresh random set of dropped units for every example at every step, so it is really training a huge family of thinned sub-networks that share weights. At test time, inverted dropout's 1/(1 − p) scaling during training means the full network can be used as is, and it behaves almost exactly like the average of many sub-networks: an ensemble for the price of one model. A single sub-network is noisier. Changing p retrains the network.

A network trained with dropout on a two-moons dataset. Dots show which of its 64 hidden units a sampled sub-network keeps. Three decision maps compare one thinned sub-network, the full network in evaluation mode, and the average of 40 sub-networks, each with its training accuracy. A slider sets the drop rate and retrains the network. Keyboard: Tab to the slider and the button; arrow keys change the drop rate.

First write inverted dropout and its backward pass. Then the lab: train_a to train_f are six complete training scripts, each with exactly one planted bug, the kind that cost real people days. Run the tests, read which one fails and how, then find and fix the bug in place. Every fix is a one- or two-line change, and the helper functions are correct.

Training in practice stubs/m3_5_spot_the_bug.py

Loading starter file…

Prefer your own editor? Edit exercises/stubs/m3_5_spot_the_bug.py and run mlc check 3.5. The tests are identical; import the results on the progress page.

Hints · dropout 0/3 revealed
Hints · the bug hunt 0/3 revealed

Locally: mlc check 3.5.

1. Training and validation loss both drop fast for a few steps, then the training loss spikes to NaN. First thing to try?
2. Training loss approaches zero; validation loss bottomed out early and has been rising since. This is…
3. A new 10-class classifier starts with a loss of 9.7. What does that suggest?
4. Your model will not learn at all. What is the most useful first experiment?
5. With inverted dropout at p = 0.5, what must happen at evaluation time?
  • not yet: All tests pass (0/?)
  • not yet: Checkpoint quiz ≥ 80%
Finish the items above first.
Learner log: time spent and points of confusion

Every confusion you note becomes a fix before the module is marked stable. Export it from the progress page and attach it to an issue.