Stochastic gradient descent (SGD) minimizes a neural network’s loss without processing the entire training dataset for every update. It estimates the gradient from a randomly sampled minibatch, then uses that estimate to update weights and biases. section 9.2.2 section 9.4
If B is a minibatch, SGD averages the losses or gradients for the examples in B and moves parameters in the negative-gradient direction. Geometrically, each update moves the model down its loss hypersurface, although the sampled estimate introduces noise. section 9.2.2 section 9.4
A PyTorch training step follows this sequence:
- Load a shuffled minibatch through a Dataset and DataLoader. section 9.2.3
- Run the model forward and compute the minibatch loss. section 9.2.3
- Clear old gradients, backpropagate the loss, and call optimizer.step() to update parameters. section 9.2.3
Classifying Statsville residents
A neural network receives height and weight and predicts man, woman, or child. A DataLoader supplies shuffled batches of 10 examples; CrossEntropyLoss measures each batch, and optim.SGD(model.parameters(), lr=0.02) updates the model. Across epochs, the loss decreases and predictions become more accurate. section 9.2.3
Figure 9.6 Height and weight of various Statsville residents. Class 0 (man) is represented by the right-most cluster, class 1 (woman) by the middle cluster, and class 2 (child) by the left-most cluster.
Inspect the height-weight clusters that provide the classifier’s training distribution and make minibatch optimization concrete. section 9.2.3











