An engineer wants Keras training to automatically halt if the validation loss has not improved for a specified number of consecutive epochs. Which callback provides this behavior?
Select an answer to reveal the explanation.
Short Explanation and Infographic
This one's almost named exactly what it does: EarlyStopping. You give it a metric to watch, usually val_loss, and a patience value — say, 5 epochs — and if that metric doesn't improve for that many epochs in a row, training stops on its own. That saves you time and helps prevent overfitting from grinding on past the point of usefulness. That's the correct answer. ModelCheckpoint is a close relative that saves weights along the way, but it doesn't decide when to stop training. LearningRateScheduler adjusts the learning rate according to a schedule you define, which is about training dynamics, not stopping the loop. And CSVLogger just writes your metrics to a CSV file for record-keeping — purely a logging tool, no control over training duration at all.
Full explanation below image
Full Explanation
EarlyStopping is the Keras callback specifically designed to monitor a chosen metric — most commonly val_loss — and halt training automatically once that metric fails to improve for a specified number of consecutive epochs, controlled by the patience parameter. For example, setting monitor='val_loss' and patience=5 means training will stop if validation loss has not improved for 5 epochs in a row. This directly addresses overfitting by preventing the model from continuing to train long after it has stopped generalizing better, and it also saves compute time by avoiding unnecessary additional epochs. EarlyStopping can optionally restore the model's weights from the best-performing epoch via restore_best_weights=True, though its core function is deciding when to stop, not saving files to disk.
ModelCheckpoint is a related callback, but its purpose is to save the model (or its weights) to disk, typically only when a monitored metric improves (save_best_only=True). It does not control whether or when training stops; it simply persists checkpoints as training proceeds. Many workflows combine EarlyStopping and ModelCheckpoint together, but they serve distinct roles.
LearningRateScheduler is a callback that adjusts the optimizer's learning rate over the course of training according to a schedule (for example, decaying it after certain epochs, or a custom function of epoch number). This affects how the model learns during each step but has no mechanism for halting training based on a lack of improvement in validation loss.
CSVLogger is a simple logging callback that streams epoch results (loss, accuracy, and other metrics) to a CSV file for record-keeping and later analysis. It is a passive observer of training progress and has no influence over whether training continues or stops.
Memory aid: EarlyStopping controls when training ends, ModelCheckpoint controls what gets saved, LearningRateScheduler controls how the optimizer's step size changes, and CSVLogger controls where metrics get recorded — four different callback responsibilities that are easy to confuse but serve non-overlapping purposes.