A callback is an object passed to model.fit() that observes training state and acts automatically. It can monitor metrics, save models, adjust parameters, or stop training instead of leaving a long run unattended. section 7.3.2
When built-in callbacks do not cover a needed action, subclass keras.callbacks.Callback and implement lifecycle methods. Each method receives logs containing recent training or validation information; batch and epoch methods also receive an index. section 7.3.3
Record and plot batch losses
A LossHistory callback initializes per_batch_losses at training start, appends logs.get("loss") after every batch, and plots the collected values at epoch end before clearing the list. Pass an instance through callbacks=[LossHistory()] in model.fit(). section 7.3.3
Choose a lifecycle hook according to when the action belongs:
- Use on_epoch_begin or on_epoch_end for epoch-level evaluation, plotting, or generated-output inspection. section 17.2.6


















