Deciding When a Training Run Has Done Enough
Training loss can improve after predictions on unseen records stop improving. Keep separate curves, choose a stopping rule in advance, and restore the best saved model.
13 sections · 4 questions · 2 coding challenges
The arrow keys move between sections too.
Treating Training Time as a Choice
BOTIE
Stopping based on validation is a separate model-selection decision. The examples here use fixed recorded curves so we can inspect the choice without confusing changing optimiser settings with an independently evaluated improvement.
Sources for this history
Should Botie Keep Training Because the Loss Is Falling?
The model keeps fitting the training records more closely, but its error on the validation records has begun to increase. Continuing just because the training loss falls can make the final model less useful.
We will distinguish optimisation progress from generalisation, keep the best validation checkpoint, and make the rules for reducing the learning rate or stopping explicit.
The validation history is illustrative; each position refers to a saved state.
Step 1 of 4
Keep the curves separate
Training and validation describe different records.
Vertical: Loss
Horizontal: Epoch (zero based)
Step 2 of 4
Identify the best saved state
Minimum validation loss occurred before the final update.
Vertical: Loss
Horizontal: Epoch (zero based)
Step 3 of 4
Restore that state
Stopping later does not make the last parameters the best ones.
Vertical: Loss
Horizontal: Epoch (zero based)
Step 4 of 4
The validation winner still needs a final evaluation
Choosing a checkpoint uses the validation results to make a modelling decision. Keep the final test data out of that choice so they can answer how the selected model behaves on data that did not select it.
| Data | Role |
|---|---|
| Training | Adjust the parameters |
| Validation | Choose the checkpoint and stopping settings |
| Final test | Evaluate the selected procedure |
Training
- Role
- Adjust the parameters
Validation
- Role
- Choose the checkpoint and stopping settings
Final test
- Role
- Evaluate the selected procedure
Stopping and restoring are two separate training decisions
The checkpoint position selects the state that performed best on the declared validation criterion.
Which saved state earned the best validation result?
The latest checkpoint is not automatically the best one. Change the validation sequence and check which saved state the declared criterion selects.
BOTIE
Position of the best validation checkpoint
1
Follow the operations
1. Validation losses in checkpoint order
- 00.8
- 10.5
- 20.55
- 30.6
2. Find the smallest
1
3. Result
1
This does not evaluate the final test or prove that later unobserved epochs would be worse.
1. Record What Each Curve Measures
Training loss reports the objective on records used to update parameters. Validation measures a held-out choice criterion. Use consistent evaluation mode, preprocessing, and aggregation so a change in the curve has an interpretable meaning.
Training and validation loss need not be directly comparable when regularisation or augmentation differs. Log those conditions rather than assuming every gap is overfitting.
A curve is evidence about a defined calculation, not a diagnosis by itself.
2. Define Improvement and Patience
We need to decide what counts as an improvement before watching the run. Does a better metric go up or down, and how large must the change be? Whenever the criterion improves, save a copy of the model. A patience count lets us allow some unsuccessful checks before stopping. Reset that count on improvement, and stop when it reaches the limit we chose.
Validation losses = [0.8, 0.5, 0.55, 0.6]
Best zero-based epoch = 1
With patience 2, stop after epoch 3
Restore the checkpoint from epoch 1Off-by-one errors are common, so write whether patience counts completed unsuccessful checks.
3. Change the Learning Rate Deliberately
A fixed schedule uses the update or epoch index. A plateau schedule responds to a monitored metric. Both require clear timing: a rate used for the current update is different from a rate changed afterward.
Changing batch size changes updates per epoch. If a schedule is specified in updates, do not silently reinterpret it in epochs when comparing runs.
Learning-rate scheduling and early stopping can coexist, but their counters and purposes differ.
The most recent state need not be the best state
These three saved checkpoints were evaluated by the same validation loss. Choose the minimum and keep its position attached to the saved state.
import numpy as np
validation_loss = np.array([0.2, 0.4, 0.3])
best_position = int(np.argmin(validation_loss))
print(best_position)
print(f'{validation_loss[best_position]:.2f}')0
0.20The first checkpoint wins here. Stopping after the third check would not justify returning the third checkpoint instead.
4. Reserve the Final Test for the Final Choice
Repeatedly selecting settings against validation can overfit that validation set. Keep an untouched final test and report the selection process, seed variation, and important subgroup errors.
A plateau may come from a bad learning rate, poor features, wrong labels, or a bug. Check a small batch fit, gradient correctness, data alignment, and a simple baseline before spending more time on a long run.
Botie’s workshop finds the checkpoint index. The coding task also implements the stopping counter.
5. The Best Validation Step May Be Earlier Than the Last Step
Early stopping needs a record of the best validated state, not only a counter of disappointing epochs. If training continues for several checks after the best score, the final parameters can be worse than the saved ones.
Copy the parameter arrays when recording the checkpoint. Storing another reference to mutable weights lets later updates overwrite the supposed best state. Keep training and validation losses separate, and never use the final test score to decide when to stop.
6. Trace Patience and the Restored Checkpoint
Patience counts consecutive validation checks without a qualifying improvement. Declare whether equality counts, what minimum improvement is required and how often validation runs.
The example stores a step identifier instead of parameter arrays so we can see the decision clearly. A real run would save the full fitted state at that step.
Stop after two non-improving checks
Lower validation loss is better; any strict decrease resets patience.
import numpy as np
losses = [1., .8, .7, .71, .72, .69]
best, best_step, stale = float('inf'), None, 0
for step, loss in enumerate(losses):
if loss < best:
best, best_step, stale = loss, step, 0
else:
stale += 1
if stale >= 2:
break
print(step, best_step, best)4 2 0.7The run stops before the later hypothetical improvement is observed. Patience is a chosen rule with a tradeoff, not knowledge of the future loss curve.
7. Try to Fit a Tiny Batch before Investigating Generalisation
If a flexible network cannot fit a tiny clean batch, inspect labels, shapes, loss conventions and gradients before collecting more data. Check that parameters change and that a small step can reduce the chosen loss.
Once that mechanism works, restore the intended regularisation and evaluate on independent data. Successfully memorising a tiny batch is a debugging check. It is deliberately not evidence of useful generalisation.
Check yourself
Questions on Parts 1 to 7
Question 1 of 4
Which zero-based checkpoint is best?
Use the information below.
Validation losses [0.8,0.5,0.55,0.6], lower is better.Try it with Botie
Build with Botie
Write and run Python