g↗genai/ learner
Neural Networks and Deep Learning / Lesson 03

Gradient descent: improving predictions

Training can improve a model through many small changes. Follow one simple update, then see how the step size affects what happens next.

Concept + interactive labBeginner friendly

A guess can improve in steps.

Imagine a bead resting somewhere on the inside of a smooth bowl. It can move toward the low point a little at a time. In training, the “bowl” is a picture of how well different model settings perform; the model does not literally roll downhill.

This lesson follows six ideas in order: prediction, error, loss, slope, learning rate, and update.

Use one invented example: a tiny model predicts a package’s mass using a single adjustable number, w. The known target is 4 units, and the first prediction is w = 0. The error is prediction minus target, so it starts at −4 units.

A loss turns the mismatch into a score. For this example, use L(w) = ½(w − 4)². Squaring makes the score non-negative, and a prediction nearer 4 has a lower score. The loss starts at 8; at the target, it is 0.

Keep the example small: this toy has one adjustable number and one target. A real model can have many adjustable numbers and many training examples.

Use the slope to choose a direction.

The gradient tells which way the loss rises most steeply at the current setting. For this one-number example, its slope rule is dL/dw = w − 4. This derivative is supplied as the rule for the toy; the optional math pathway explains derivatives in more depth.

At w = 0, the slope is −4. A negative slope means the loss falls if w moves a little to the right. Gradient descent subtracts the slope multiplied by the learning rate from the current setting.

New setting = current setting − learning rate × gradientThe learning rate scales the slope to set the amount of change in one update.

Work it through with a learning rate of 0.25. The first update is 0 − 0.25 × (−4) = 1. The error shrinks, and the loss drops from 8 to 4.5. From there, the slope is 1 − 4 = −3, so another update gives 1 − 0.25 × (−3) = 1.75, with loss about 2.53.

Gradient descent. A direction, then a step. w = 0; Slope = −4; Loss = 8; Rate = 0.25; w = 1; Loss = 4.5; Target = 4. The arrow moves down the bowl toward the target. Analogy: low point; a little at a time. Key takeaways: The learning rate scales the slope; Training repeats updates.
One small update lowers loss as the prediction moves toward its target.

An update is one calculated change to the adjustable setting. Training repeats updates; it does not usually jump straight from the first guess to a perfect answer.

The steepest-descent direction and learning-rate update are standard optimization ideas. See Goodfellow, Bengio and Courville, Deep Learning, sections on gradient-based optimization and optimization for training deep models.

Change the step size.

In the example above, 0.25 takes a moderate step toward the target. A lower learning rate makes each step smaller; a high one can jump across the low point. Watch how the next setting and loss respond.

  1. Start with the selected rate, 0.25, and take one step.
  2. Reset, choose 0.05, and compare how far the marker moves.
  3. Reset, choose 2.2, and watch the marker cross the target.
01 / Follow the loss downhillTOY SIMULATION

This made-up example has one adjustable prediction, w, and one known target: 4. Start at w = 0. Each step uses the slope of this bowl and the selected rate to calculate a new value.

Step 0. Prediction w = 0.00; loss = 8.00.

Current slope = -4.00. The next update is w− rate × slope.

The toy loss bowl and update pathA U-shaped curve shows the loss for each prediction. Its lowest point is at the target, 4. The highlighted marker shows the current prediction, and the connected dots show earlier update positions in order.target 4-2.06.0Prediction wLoss L(w)
The vertical axis rescales to keep the whole path visible. Each dot is a calculated update; the ball-shaped marker is repositioned between steps, with no simulated rolling or momentum.

Invented target and values. This deterministic toy uses the exact gradient of L(w) = ½(w − 4)², with no added randomness. It is not a live model or a complete training setup.

What this bowl leaves out.

With this exact bowl starting at w = 0, a rate of 0.25 steadily reduces the loss. A rate of 2.2 overshoots the target on the first update and raises the loss; later updates alternate across the target and move farther out. This is a result for the stated toy equation, not a rule that every large rate behaves the same way in every model.

A real training run changes many parameters using examples and a chosen loss. Its loss surface can have more complicated shapes, so a rate that helps in one setting may be too small or too large in another. Gradient descent describes a repeated update process, not a promise of instant or perfect learning.

This lesson showed a slope for one adjustable number. How error supplies gradients across multiple layers belongs in the next lesson on backpropagation. Batches, epochs and training settings come later.

Quick questions

Does one update guarantee the best prediction?
No. It changes the setting once; later steps may still be needed.
Does a larger rate always help?
No. It can make progress faster in some cases, but it can also overshoot.
✎ Try it yourselfKnowledge check · Practice only

Follow one update

A toy model starts at w = 0. Its target is 4, its loss is L(w) = ½(w − 4)², and its update rule is new w = current w − learning rate × (w − 4). With a learning rate of 0.25, what is w after one update?
THE TAKEAWAY

A direction, then a step.

Gradient descent uses the loss slope to choose a direction, then the learning rate sets the step size. Training repeats those updates, checking whether they improve the chosen loss.

Chapter 6 contents →