Training is how a model acquires useful weights from data instead of relying on rules written by a programmer. In supervised learning, examples pair inputs with expected outputs. A loss function measures the gap between predictions and targets; that feedback guides changes to the weights. Once trained, the model can use those weights to make predictions. section 1.3 section 2.4
When MNIST training stalls
Suppose a digit classifier reaches only 20%–40% training and validation accuracy. With an RMSprop learning rate of 1.0, its updates are too large to reach a good fit. Lowering the rate to 1e-2 lets the same model train. If loss is stuck, try changing the learning rate first; a larger batch size can also make gradients less noisy. section 5.3.1
A training loop repeats a small set of operations:
- Draw a batch of inputs and targets, then run a forward pass to obtain predictions. section 2.4
- Compute a loss that measures the mismatch between predictions and targets. section 2.4
- Compute gradients and let the optimizer move weights toward lower loss. The learning rate controls the size of the move. section 2.6
- Repeat across batches; one pass through the training data is an epoch. section 2.5.3
def fit(model, images, labels, epochs, batch_size=128): for epoch_counter in range(epochs): print(f"Epoch {epoch_counter}") batch_generator = BatchGenerator(images, labels) for batch_counter in range(batch_generator.num_batches): images_batch, labels_batch = batch_generator.next() loss = one_training_step(model, images_batch, labels_batch) if batch_counter % 100 == 0: print(f"loss at batch {batch_counter}: {loss:.2f}")
The `fit` function makes the outer structure concrete: repeat epochs, visit each batch, run one training step, and report loss. section 2.5.3
For routine supervised training, configure a Keras model with an optimizer, loss, and monitoring metrics, then call `fit()`. Metrics such as accuracy are reported but are not directly minimized. If the learning algorithm needs more control, write a custom loop; or override `keras.Model.train_step()` to keep `fit()` features such as callbacks. Low training loss alone is not the goal: check validation performance to guard against overfitting. section 3.6.4 section 7.4.4 section 5.0























