Code

Run it: the honest number

The tests pass. For the first time, run the training with all three measures:

$ python train.py --dropout 0.3 --weight-decay 1e-4 --patience 5
mlp: 269,322 parameters
epoch  1  loss 0.5656  train acc 80.2%  |  val loss 0.6024  val acc 78.5%
epoch  2  loss 0.4643  train acc 83.2%  |  val loss 0.5130  val acc 81.6%
...
epoch  9  loss 0.2889  train acc 89.4%  |  val loss 0.3878  val acc 86.0%
epoch 10  loss 0.3128  train acc 88.3%  |  val loss 0.4364  val acc 84.4%
epoch 11  loss 0.2745  train acc 89.7%  |  val loss 0.3953  val acc 85.8%
epoch 12  loss 0.2646  train acc 90.1%  |  val loss 0.4042  val acc 86.0%
epoch 13  loss 0.2645  train acc 89.9%  |  val loss 0.3985  val acc 85.4%
epoch 14  loss 0.2668  train acc 89.7%  |  val loss 0.4197  val acc 85.7%
early stop at epoch 14: best val loss was 0.3878
final: train 89.4%  val 86.0%  gap +3.3%
done in 20.6s

See what happened: training stopped at epoch 14 (the best was at epoch 9, and five in a row did not improve), and the weights were put back to epoch 9's. That is why the final "train 89.4 %" is the training accuracy of the epoch-9 model, not of epoch 14.

One table

regularize.py (a new file — provided, you do not write it) trains the same network five ways and prints one table:

$ python regularize.py
config               epochs   train     val     gap
baseline                 30   97.1%   86.7%  +10.4%
dropout 0.3              30   93.8%   87.0%   +6.8%
weight decay 1e-3        30   92.5%   85.7%   +6.9%
early stopping           12   90.7%   85.8%   +4.9%
all three                14   89.4%   86.0%   +3.3%

The same starting state (seed 42) for every row, the same network, the same 5 000 validation images.

How to read it

The gap narrowed — that is real. +10.4 → +3.3 points.

But look at how it narrowed. Validation accuracy: 86.7 → 86.0. It did not rise. Training: 97.1 → 89.4 — it fell. The gap shrank because we pushed the training number down, not because we raised the real one.

To say "regularisation made the network better" from this table is dishonest. The honest version: regularisation made the training accuracy closer to the real one. That is valuable too — now the training number can almost be trusted again — but it is not the same thing.

The panel now shows the filled-in version

In this step fashion.py and train.py in the panel are filled in. It is the reference to compare your files with; later lessons change exactly it.