ContentsChapter 8 · Neural networks3 of 3

8.3

Training

In this chapter
  1. 8.1From logistic regression to an MLP
  2. 8.2Backpropagation
  3. 8.3Training
Before you readYour gradient points uphill. If one downhill step crosses the bottom of the valley, does the next step necessarily bring you closer to it?
Watch: Gradient descent, how neural networks learn · 3Blue1Brown · Neural networks, ch. 2

Training repeats three operations: run the forward pass, use backprop to compute the gradient of the loss, then move the parameters against that gradient. For all the weights and biases collected in θ\theta a gradient descent step is

θ←θ−η∇θL.\theta\gets\theta-\eta\nabla_\theta L.

The learning rate η\eta scales the update. The gradient changes after every step. For one weight with loss L(w)=12(w−2)2L(w)=\tfrac12(w-2)^2 the slope is w−2w-2 Starting at w=0w=0 a rate of 0.10.1 takes you to 0.20.2 a rate of 11 takes you to 22 and a rate of 22 takes you to 44 With that last rate, the next step goes back to 00 the gradient reverses sign but not size.

012345-1012345
w=1.50w=1.50L(w)=0.13L(w)=0.13
The filled dot is the current weight. Compare rates of 0.1, 1, 2 and 2.1: small steps, one step to the bottom, an oscillation, and steps that move away.
Recall
Can a gradient descent step increase the loss even when it moves against the gradient?

One update, one batch

For a large dataset, computing the exact gradient over all examples at each update is costly. Mini-batch gradient descent uses the mean loss over a small group of examples instead. Backprop gives its gradient; the optimiser uses it for one update. An epoch is one pass through the training set, usually with the examples shuffled before batching. With 1,0001{,}000 examples and batches of 100100 that’s ten updates in one epoch.

A network’s loss over its parameters need not have a single valley like the figure. Reaching a lower training loss isn’t a guarantee of a better model either. Measure the loss on held-out validation examples without updating on them. If training loss keeps falling while validation loss rises, the network may be overfitting.

Recall
What gets averaged before a mini-batch gradient descent update, and what makes one epoch?
Exercise
In the figure's loss L(w)=12(w−2)2L(w)=\tfrac12(w-2)^2 start at w=0w=0 with η=1.5\eta=1.5 What are the weights after the first and second updates?
Exercise
Train for two epochs on 960960 examples with batches of 128128 Keep the last batch even if it's smaller. How many examples are in the last batch of each epoch, and how many updates are there in total?