ML5: Neural networks and deep learning

Lesson 2 of 5 · reading 15–25 minutes; practice and project time is on the module page

How networks learn: loss, gradients and optimisers

🎯You'll be able to

Explain a loss function, gradient descent, a learning rate, batches and epochs.

🏠The everyday picture

Finding the lowest point of a valley in fog: you feel which way the ground slopes under your feet and take a step downhill, again and again. Step too far and you overshoot; step too little and you never arrive.

📘What it really is

📝A worked example

Input: a single parameter w, with loss (w − 3)². The slope of the loss is 2 × (w − 3).

Steps with learning rate 0.1, starting at w = 0:

  1. Slope at 0 is −6. New w = 0 − 0.1 × (−6) = 0.6.
  2. Slope at 0.6 is −4.8. New w = 0.6 + 0.48 = 1.08.
  3. Slope at 1.08 is −3.84. New w = 1.08 + 0.384 = 1.464.

Expected output: w moves towards 3, with smaller steps as the slope flattens. With learning rate 1.1 instead, the first step goes to 6.6, the next to −1.32, then 8.18, and the steps grow: the learning rate is too high and training diverges. A network does the same thing for every one of its parameters at once.

🌍Where it's used

📝Case scenario

A team's image model's loss went to "nan" (not a number) after a few hundred steps. The learning rate was too high for their setup, and the numbers had grown until they overflowed. A lower rate and inputs scaled to 0–1 fixed it. They added a check that stops training when the loss stops being a number.

🖱️Try it

Repeat the worked example with learning rate 0.5. Success: the first step lands exactly on 3 (0 − 0.5 × (−6) = 3), which shows why the learning rate matters so much.

⚠️Common mistakes

🛠️For your project

Not needed for the projects; it explains what "training" means in the network you compare in the assignment.

✅Quick check

What does the learning rate control?

Show the answer

How big each step is when the parameters are updated.

What's an epoch?

Show the answer

One full pass over all the training rows.

← PreviousFrom a neuron to a network
ProLearners Assist