Training a neural network for a fixed number of epochs is a naive strategy. If you train too few epochs the model underfits; too many and it overfits — and you have no way of knowing in advance which epoch produces the best generalisation. Keras callbacks solve this by injecting custom logic at specific points during training: at the start or end of each epoch, at the start or end of each batch, or when training begins or ends. EarlyStopping monitors a validation metric and halts training automatically when improvement stalls, preventing both wasted compute and overfitting. ModelCheckpoint saves the model's weights to disk whenever a validation metric improves, ensuring you always have the best-performing checkpoint regardless of when training stops. ReduceLROnPlateau dynamically reduces the learning rate when training stagnates. TensorBoard streams metrics to a visual dashboard. These four callbacks together implement a production-grade training loop with zero additional code beyond the callbacks list — they are the difference between a research script and a reliable training pipeline.
25 minadvanced
Callbacks — EarlyStopping, ModelCheckpoint
Analogy🏏Cricket
🏏 Think of it like cricket: The Duckworth-Lewis-Stern (DLS) method, the ICC bowling economy metric, and the net run rate each measure team performance but optimise for completely different things — DLS cares about wickets-in-hand, economy cares about runs-per-over, NRR cares about tournament-wide margins. Using the wrong metric to evaluate a bowler is like using MSE for classification: technically computable but optimising the wrong thing entirely. Just as you would never rank a spinner by batting average, you should never use MSE when your model predicts probabilities. Just as focal DLS adjustments down-weight easy chases and amplify close finishes, focal loss down-weights easy examples and amplifies hard minority-class examples. The choice of scoring metric defines what excellence means — and so does the choice of loss function.
Lesson 9 of 35
0% complete