E ExamMaster

Deep Learning · Deep Learning

Training Loop

In Deep Learning because loss, backprop and epochs are how neural parameters are trained.

Training is repeated predict → loss → update.

  • Deep Learning
  • Medium level
  • 4 concepts

1The loop

Each step computes predictions, a scalar loss, and an update to parameters.

Minibatches keep memory bounded — stay under a few dozen samples per batch here.

Animation: a circular loop of four stations - forward, loss, backward, update - with a gold token travelling around it, each station lighting as the token passes. A loss panel on the right extends a falling curve by one segment per lap, through 2.30, 1.42, 0.95 and 0.71. Captions name each phase in turn and the final frame reads every lap around the loop pushes loss down, minibatches keep each lap small
One training step is a lap: predict (forward), score the miss as one number (loss), let every weight learn its share of the blame (backward), then nudge the weights (update). Repeat, and the loss curve falls.
Why must the loss be a single scalar rather than one number per training example?
  1. A gradient is taken of one quantity, so the per-example errors have to be reduced to one before the backward pass can run
  2. The framework has no way to store more than one number at a time
  3. A minibatch always contains exactly one example
  4. Scalar losses simply train faster than vector losses

Every parameter needs one derivative saying which way to move. That only exists once the batch has been collapsed into a single objective, usually by taking the mean.

2Epochs versus steps

An epoch is one pass over the training set; a step is one minibatch update.

Report both when you describe a run — "5 epochs" alone hides batch size.

Figure. An epoch is one pass over the training set. A step is one minibatch update. Report both — saying 5 epochs alone hides batch size.

Two runs both report '5 epochs'. One performed 50 updates and the other 5000. What differed?
  1. The batch size: smaller batches mean many more updates over the same pass through the data
  2. The learning rate used for each update
  3. The number of layers in the network
  4. Whether the data was shuffled between passes

An epoch counts passes over the data and a step counts updates, and the batch size is the exchange rate between them. Quoting one without the other hides how much training happened.

3Backprop intuition

Backpropagation applies the chain rule so each weight knows its local contribution to loss.

You rarely hand-code it; frameworks do — you still must understand vanishing gradients.

Figure. Backpropagation applies the chain rule so each weight knows its local contribution to loss. Frameworks compute it; you still have to understand vanishing gradients.

The early layers of a deep net barely move while the last layer trains fine. Which property of backpropagation explains it?
  1. The gradient reaching an early layer is a product of many factors, and a product of small factors shrinks toward nothing
  2. Early layers hold fewer parameters, so they need fewer updates
  3. The optimizer updates layers in order and runs out of steps
  4. Early layers are frozen by default in most frameworks

The chain rule multiplies a factor per layer on the way back. Where those factors sit below one — a saturated sigmoid, say — the signal decays exponentially with depth.

4Early stopping

Stop when validation loss stops improving — a simple regulariser.

On tiny labs, prefer fewer epochs over heroic training times.

Figure. Training loss falls for as long as you keep going - it is fit to the data the model sees. Validation loss falls only while the model is still learning something general, then turns back up as memorisation starts. The marked minimum is the early stop: quit there and the extra epochs to the right, where only the train curve improves, are never paid for.

Early stopping watches the validation loss rather than the training loss. Why not the training loss?
  1. Training loss usually keeps falling while the model is getting worse on new data, so it can never be the thing that tells you to stop
  2. Training loss is noisier and therefore harder to read
  3. Training loss is not computed during an ordinary loop
  4. Validation loss falls faster, so it reaches its floor sooner

The signal you need is the turn from learning to memorising, and by construction the training loss cannot show it. Only data outside the fit changes direction.

Notes

  • Loss, backprop intuition, epochs and overfitting.
  • Each step computes predictions, a scalar loss, and an update to parameters.
  • An epoch is one pass over the training set; a step is one minibatch update.

Exam traps & shortcuts

  • Keep lab datasets under 2000 rows in the browser runtime.
  • Split train and test before fitting any model that sees labels.

Recap

This lesson in brief:

The loop
Each step computes predictions, a scalar loss, and an update to parameters.
Epochs versus steps
An epoch is one pass over the training set; a step is one minibatch update.
Backprop intuition
Backpropagation applies the chain rule so each weight knows its local contribution to loss.
Early stopping
Stop when validation loss stops improving — a simple regulariser.

Practise Training Loop

Reading is free and needs no account. Practice, mocks and progress live in the app.

  • A 1-question practice set that ends the chapter
  • 4 quick checks with worked explanations
  • Timed mocks scored with the real marking scheme
  • Readiness tracked per topic, kept on your device
Continue with Google — freeNo card, no trial. Works offline once installed.