Quiz: reading training curves
Before this unit: Regularisation and data augmentation (previous unit); Day 36: Neural networks.
See also: Day 38: Evaluation and statistics.
Short questions on diagnosing training from its curves. Try each on paper first, then open the answer. K balanced classes: guessing gives the loss \ln K.
Q1. Training loss 0.02, validation loss rising for 40 epochs. Diagnosis, and two fixes?
Training and validation are moving apart.
Overfitting. Fixes: more data or augmentation, weight decay or dropout, a smaller network, and early stopping (keep the weights with the lowest validation loss).
Q2. A 5-class classifier: both losses stay at 1.61 from the first epoch on. What has gone wrong?
\ln 5 = ?
\ln 5 = 1.61: the network only learns the class frequencies, so its inputs carry no information about the class: images not loaded, all zeros, scaled to almost nothing, or the same image for every example. Look at the inputs.
Q3. Both curves fall smoothly and together, and are still falling clearly when training stops. What do you change?
Underfitting or not finished?
Training is not finished: the learning rate is probably too low (or there were too few epochs). Raise the learning rate or train longer. Underfitting would show curves that have already flattened at a high level.
Q4. The loss jumps up and down by large amounts from epoch to epoch and does not settle; once it became NaN. What first?
Each step overshoots.
Lower the learning rate (by 3–10 times) and use a schedule that decays it. Also check the inputs for huge values and the loss for a log of 0.
Q5. A cell classifier reports 95 % accuracy. 95 % of the cells are “normal”. Is it good?
What does “always normal” score?
Not necessarily: answering “normal” every time also scores 95 %. Look at the recall of the rare class (and its precision). If it is low, use class weights, oversampling or the focal loss, and judge by per-class measures.
Q6. Before starting a two-day training run, what is the cheapest test that the whole pipeline (loading, labels, network, loss) works?
A handful of examples.
Overfit one small batch: a working pipeline learns a few examples to a loss near 0 within seconds or minutes. If it cannot, there is a bug, and no amount of data will fix it.
Q7. With dropout and strong augmentation, the validation loss is lower than the training loss. Bug?
On which images, and with which network, is each loss measured?
Not necessarily: the training loss is measured on augmented images with dropout on (a harder task), the validation loss on clean images with all units. Without dropout or augmentation it would be suspicious (an easier or overlapping validation set).
Q8. (math) Two classes with 80 % and 20 % of the examples. What loss does a network reach that has learnt only the frequencies?
-\sum_k f_k\ln f_k.
-0.8\ln 0.8 - 0.2\ln 0.2 = 0.179 + 0.322 = 0.500. A training loss of 0.5 here means nothing has been learnt.