Stochastic gradient descent (SGD) trains a model by repeatedly adjusting its parameters to reduce loss. Mini-batch SGD randomly selects a small batch, runs a forward pass, computes loss and gradients during the backward pass, then moves parameters slightly opposite the gradient. The learning rate controls the update size. section 2.4.3 section 2.6
A training update follows this loop:
- Draw a random batch of samples and targets. section 2.4.3
- Run the model on the batch to produce predictions. section 2.4.3
- Measure prediction error with a loss function and compute gradients with backpropagation. section 2.5 section 2.6
- Update the weights in the direction that reduces the batch loss. section 2.4.3
Training a digit classifier
A Keras model can classify normalized 28×28 MNIST images with two Dense layers. Compiling with Adam, sparse categorical cross-entropy, and accuracy selects the optimizer, feedback signal, and metric; fitting for five epochs with batches of 128 performs mini-batch updates. The same training process can be understood as repeatedly moving the network’s weight tensors toward lower loss. section 2.5
Mini-batch SGD balances two extremes: true SGD uses one sample per update, while batch gradient descent uses all available data. Larger batches can make each update more accurate but more expensive. A learning rate that is too small slows descent; one that is too large can send updates to unhelpful locations. Optimizers can specify variations such as Adam, RMSProp, or SGD with momentum. section 2.4.3 section 2.6
Figure 2.17 SGD down a 1D loss curve (one learnable parameter)
Use the one-parameter loss-curve figure to visualize how gradient-based updates descend toward lower loss. section 2.4.3











