THE GENIUS PROJECT
โ›ฐ๏ธ Lesson 2 of 6 ยท 3D game inside

How Networks Learn

๐Ÿ•’ About 35 minutes ๐Ÿงฎ Loss, gradients, learning rate, epochs ๐ŸŽฎ Gradient Hill: descend in the fewest steps

Lesson 1 left one giant question: who sets the weights? Answer: an algorithm called gradient descent, and it is best understood as a hike. Every possible setting of the weights is a spot on a landscape, and the height at that spot is how WRONG the network is there. Learning = walking downhill. Today you take that walk yourself.

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:

loss = average of (prediction − truth)²

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:

wnew = wold − learning rate × gradient
๐Ÿงญ Why the minus sign finds downhill

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:

๐ŸขToo small

Baby steps. You WILL reach the valleyโ€ฆ in ten thousand steps. Training takes forever and can stall on flat ground.

๐Ÿฆ˜Too big

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:

๐Ÿ”ฎPredictrun inputs through the network
๐Ÿ“Scorecompute the loss against the truth
๐ŸงญFeel the slopebackprop finds every gradient
๐Ÿ”งNudgeupdate every weight, repeat

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.

prediction = 2 × 3 = 6,   miss = 6 − 12 = −6,   loss = (−6)² = 36

Now the slope. For squared error, calculus hands you a clean recipe: gradient = 2 × miss × input. No mystery, just arithmetic:

gradient = 2 × (−6) × 3 = −36
wnew = 2 − 0.05 × (−36) = 2 + 1.8 = 3.8
next pass: 3.8 × 3 = 11.4,   miss = 11.4 − 12 = −0.6,   loss = (−0.6)² = 0.36

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
  1. The voxel landscape is a real loss function. The glowing golden ball is the current weight setting. Lower ground = smaller loss.
  2. Set your learning rate, then hit Take a step: the ball moves one gradient-descent update. Or press Auto-descend to run steps automatically.
  3. 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.
  4. 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.
Steps 0 Loss โ€“ Best run โ€“
Learning rate: 0.60
Pick a learning rate and take your first step downhill.
Check your understanding

During training, the loss goes 8.2 โ†’ 3.1 โ†’ 9.5 โ†’ 2.0 โ†’ 11.8, bouncing wildly. What is the most likely problem?

A bouncing, rising loss is the classic signature of an oversized learning rate: every update leaps across the valley to the other slope and each step overshoots. (A too-small rate would crawl smoothly, and a too-small network would plateau, not bounce.) First fix to try: cut the learning rate (by 10x is common).
๐ŸŒซ๏ธ Misconception: "the algorithm can see the whole landscape"

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.

๐ŸŒ€ Why local minima matter less than you'd think

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.

๐Ÿ”— Where you already met this

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.

๐Ÿ“Œ Lesson recap

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.