What Learning Means
Gradient descent
Rolling downhill to the best parameters
The one algorithm behind nearly all of modern machine learning: how a model, told only how wrong it is, feels its way downhill to being right.
A model "learns" by adjusting numbers - its weights - until its mistakes shrink. But which way should each weight move, and by how much? Gradient descent gives a stunningly simple answer: measure how wrong you are, find the downhill direction, and take a small step. Repeat. That's the whole trick that trains linear regression, every neural network, and the largest language models on Earth.
The picture to hold in your head
A loss landscape you can roll down
Let's make it concrete with a single weight and the simplest possible landscape - a bowl. The loss is : it's zero when (the model is perfect) and rises the further drifts either way. The whole game is to find the bottom of the bowl without being told that it sits at 3.
The is the slope of the landscape under your feet - and crucially, it points uphill, toward more error. So to go down, we step in the opposite direction. That single sentence is the entire update rule:
The update rule
Read it as "the new is the old , nudged against the slope." The minus sign is what makes it descent - flip it to a plus and you'd climb toward more error. For our bowl the slope has a tidy form (you'll derive rules like this later):
The number (alpha) is the - the size of each step. It's the one knob you get to tune, and getting it wrong is the classic beginner trap. Let's see why.
Roll the ball yourself
Click anywhere on the curve to drop a ball at that weight. The amber line is the gradient - the slope where the ball sits - and it always tilts uphill. The blue arrow is the step we actually take, pointing the opposite way, into the hollow ring where the ball will land next. Press Step for one move, or Run to animate the whole descent and leave a trail. Then drag and watch everything change.
Ready - press Step for one move, or Run to animate.
The learning rate is everything - crank it past 1.0
Why does that happen? With our bowl, one step multiplies the distance-to-the-bottom by . When is small that factor is just under 1, so the gap shrinks a little each time - slow but safe. At the factor is exactly 0, so you leap to the bottom in a single step. Past the factor exceeds 1 in size, so the gap grows every step - the ball climbs out. Same algorithm, same bowl; only the step size changed.
One valley, or many?
Our bowl has exactly one low point, so descent can't miss - it's a landscape. Real models rarely enjoy that luxury. Their loss surfaces are lumpy, with many dips: a is a valley you can get stuck in, while the is the deepest valley of all. Gradient descent only feels the ground at its feet, so it can settle into a shallow dip and stop. In practice a bag of tricks - momentum, randomness, and the sheer high-dimensional roominess of big models - usually finds a valley that's good enough, even if it isn't provably the deepest.
# descend the bowl J(w) = (w - 3)^2
w = 6.0 # start the ball somewhere
alpha = 0.3 # the learning rate
for step in range(15):
grad = 2 * (w - 3) # dJ/dw: the slope here
w = w - alpha * grad # step against the slope
print(w, (w - 3) ** 2) # weight, and the lossCheck yourself
If the learning rate α is set far too large, gradient descent will most likely:
The update rule w := w - α·(dJ/dw) moves the weight:
Recall: what does the learning rate α control, and what goes wrong at each extreme?
Tie the one knob to both failure modes. Try to state it, then check.
Primary source
Ask your teacher