+10 XP

Differentiation & Gradient Descent

This is the reason we learn derivatives. Almost every model that learns — an AI like GPT, or a model of a real neuron — learns the same way: by following a slope downhill to make its mistakes smaller. It's called gradient descent, and it's the staple of all model training.

Every model has knobs.

A model is just a machine with adjustable knobs (called weights and biases). GPT has billions of them. For any setting of the knobs, you can measure how wrong the model is — that number is the error.

Big error = bad model. Small error = good model. The whole job of training is finding the knob settings that make the error as small as possible — the bottom of the valley from the last lesson.

The blindfolded hiker.

You can't try every combination — with a billion knobs, there are more settings than atoms in the universe. So instead, picture standing blindfolded on a foggy mountain, trying to reach the lowest point.

You can't see the valley. But you can feel the slope under your feet. So you feel which way is downhill, take a small step, feel again, step again — until the ground goes flat (slope = zero). You've reached the bottom.

That slope you feel? It's the derivative. That's the entire trick.

Gradient descent = roll downhill until the derivative is zero. The derivative tells you which way is "down" for the error. ("Gradient" is just the word for the slope when you have many knobs at once.)

Why the derivative — why not just look at the error itself?

The error value alone only tells you how wrong you are right now. It's like an altimeter in the fog: it reads your height, but it doesn't tell you which way to step.

The derivative does. For each knob it gives you two things at once:
• Its sign → which way to turn that knob to make the error go down.
• Its size → how strongly the error reacts to that knob, so you know whether to nudge it a little or a lot.

That's the whole reason we measure the error through its derivative: the error says "you're lost," but the derivative says "...and here's exactly which way home, for every knob." Without it you'd be blindly trying random settings — hopeless with millions of knobs.

How AI actually trains — the cat example.

Show the model: "The cat sat on the ___"

1. It guesses "dog." Wrong. Measure the error.
2. Compute the derivative of the error with respect to every knob — "if I nudge this weight up, does the error go up or down?"
3. Nudge every knob a tiny bit in the downhill direction.
4. Show the next example. Repeat — millions of times.

Each step lowers the error a hair. Do it millions of times and the model slides down the valley until its guesses are great. That's all "learning" in machine learning is.

Same idea in neuroscience — fitting a neuron.

Say you record a real neuron and want a math model that reproduces it. Same recipe — but now the knobs aren't AI weights, they're biological: synaptic weights and time constants.

Measure how far your model's output is from the real recording (error), then use gradient descent to tune those knobs until the model matches the neuron. Same blindfolded hiker, different mountain.

And maybe the brain itself does this. When you practice piano and hit a wrong note, your brain gets an error signal and adjusts its synapses to do better next time. It's not identical to the AI math — but the principle, use the error to nudge the knobs in the right direction, may be how real brains learn too. One simple idea — follow the slope — sits under AI, neuroscience models, and possibly your own learning right now.