Early stopping: halting training at the best validation checkpoint
Intermediate classical-mlevaluationregularizationtraining-loop
Implement:
def best_epoch_with_min_delta(history, min_delta=0.0) -> int: ...
def early_stopping_should_stop(history, patience, min_delta=0.0) -> bool: ...
def train_with_early_stopping(step_fn, max_epochs, patience, min_delta=0.0) -> dict: ...
step_fn(epoch) -> (state, val_loss) is a black box: one epoch of training plus a validation-loss check, for whatever model. This question doesn't care what model it is, just when to stop training it.
- The returned model is whichever epoch's
state had the best validation loss, never necessarily the last epoch's.