Step 1: measure the wrongness (loss)
Before you can improve, you must measure. Suppose your network predicts tomorrow at 31ยฐ and reality says 29ยฐ. The miss is 2ยฐ. Do that for every example in your training data, square each miss (so big misses hurt extra and minus signs stop cancelling), and average. That number is the loss, specifically the mean squared error you met in Week 3:
Key mental flip: the loss depends on the weights. Change a weight, every prediction shifts, and the loss moves. So the loss is a function OF the weights: a landscape where every location is a weight setting and the altitude is the error. Training is the search for the lowest valley.
Step 2: find downhill (the gradient)
Standing on a hillside in fog, how do you find downhill? Feel the slope under your feet. The gradient is exactly that: for each weight, it says "if you nudge this weight up, does the loss rise or fall, and how steeply?" Networks compute it with a technique called backpropagation, which is just the chain rule from calculus applied very efficiently. Then you step OPPOSITE to the gradient, because the gradient points uphill:
The gradient for one weight is just a slope: "if this weight goes up a tiny bit, the loss changes by THIS much." If that slope is positive, raising the weight raises the loss, so the weight should go DOWN, and subtracting a positive number does exactly that. If the slope is negative, raising the weight lowers the loss, so the weight should go UP, and subtracting a negative number pushes it up. One minus sign handles both cases automatically. Bonus: a steeper slope means a bigger update, so the formula naturally takes big strides on steep ground and careful small ones near the valley floor.
Step 3: pick your stride (the learning rate)
The learning rate is the most important knob in deep learning, and the game below exists to burn it into your instincts:
Baby steps. You WILL reach the valleyโฆ in ten thousand steps. Training takes forever and can stall on flat ground.
You leap clean over the valley and land on the far slope, sometimes HIGHER than you started. The loss bounces around or explodes.
One pass through all the training data is called an epoch. Real training runs dozens of epochs, checking the loss after each. You will watch that live in Lesson 4.
Put the three steps together and you get the loop that every deep network on Earth runs, millions of times over:
One gradient-descent step, fully by hand
Numbers make this real. Take the tiniest possible model: prediction = w × x, a single weight. One training example: input x = 3, true answer 12. Start with w = 2 and a learning rate of 0.05.
Now the slope. For squared error, calculus hands you a clean recipe: gradient = 2 × miss × input. No mystery, just arithmetic:
One honest step, 99% of the error gone. Now watch the learning rate ruin the same setup: at rate 0.5 the update is 2 − 0.5 × (−36) = 20, the prediction becomes 60, the miss is 48, and the loss explodes to 2304. Same slope, same formula, wrong stride. That is the entire drama of the game below.
๐ฎ Gradient Hill: the game
How to play
- The voxel landscape is a real loss function. The glowing golden ball is the current weight setting. Lower ground = smaller loss.
- Set your learning rate, then hit Take a step: the ball moves one gradient-descent update. Or press Auto-descend to run steps automatically.
- Reach the deep green valley (the global minimum) in as few steps as you can. Under 12 steps is analyst level. Under 8 is Adrian level.
- Experiment: crank the rate to 2.5+ and watch the overshooting. Drop it to 0.1 and feel the crawl. Beware the small side-valley: that is a local minimum, comfortable but not the best.
During training, the loss goes 8.2 โ 3.1 โ 9.5 โ 2.0 โ 11.8, bouncing wildly. What is the most likely problem?
In the game you view every hill and valley from above, so it is tempting to assume the computer just spots the lowest point and jumps there. It cannot. The landscape for a real network lives in millions of dimensions, and computing the loss at every possible weight setting would take longer than the age of the universe. Gradient descent only ever feels the slope directly under its feet, one spot at a time, like hiking in thick fog. That is why the learning rate matters so much, and why training is a long walk of small steps instead of one clever leap.
In your 2D game, getting trapped in the side valley is easy. Real networks have millions of dimensions, and in that huge space there is almost always SOME direction that still leads down. Optimizers like Adam (the one you will use in Keras) also add momentum, like a heavy ball that rolls through small dips. So relax: your Colab training will not need you to babysit every step.
In Week 2, the line of best fit appeared the instant you called fit(), like magic. This loop IS the magic. Finding the best line means minimizing the same squared-error loss you met today, just with two knobs (slope and intercept) instead of millions. Same loss, same downhill walk, smaller mountain. And when your Week 3 model trained on financial data, a cousin of this exact walk ran under the hood. Deep learning did not replace what you learned; it scaled it up.
1) The loss measures how wrong the current weights are. 2) The gradient says which way is uphill, so you step the other way. 3) The learning rate sets the stride: too small crawls, too big bounces. 4) An epoch is one pass through the data. You now understand the sentence "we trained the model for 50 epochs with learning rate 0.001". That is literally all it means.
Next: the two architectures you will actually use, for seeing and for remembering.