04
Following the slope
A gradient describes local change. A learning rate decides how far to trust that direction.
Read the local slope
A derivative describes how quickly a quantity changes near the current input. With two parameters, a partial derivative varies one while holding the other fixed. The gradient collects these partial derivatives into a vector.
Differentiate our MSE expression with respect to and :
At the starting point , the gradient is . A small increase in lowers loss locally; a small increase in raises it. The negative gradient therefore points toward increasing and decreasing .
Direction is not distance
Gradient descent proposes a step opposite the gradient. Write all parameters together as and choose a positive learning rate :
The gradient describes local slope, not the entire path ahead. A finite step can go too far and raise loss. See the update and curvature discussion in Deep Learning, §4.3.
Try two independent single steps from the same starting point. With :
The new loss is , down from 3.75. But produces , with loss 4.95—higher than the starting value.
Derived from the same toy, always starting at w=0.5, b=2.5 (CL-009). Each point is a separate one-step experiment, not the next step in a training history. The larger-rate example is evaluated without clipping parameters to the lab window.
The horizontal axis is the candidate step size. Every plotted point starts from the same parameters and takes one step; these are not successive updates or epochs. The second bias, −1.1, is outside the interactive surface's viewing window. The mathematical calculation is not clamped to that window.
Reproduce one step
The canonical JavaScript module computes losses directly from the three data rows. With Node.js and the local companion module in the same folder, this focused excerpt reproduces the smaller step:
import { gradientStep } from './model.mjs';
const next = gradientStep({
weight: 0.5, bias: 2.5, rate: 0.25
});
console.log(next.loss.toFixed(3)); // 1.229
The displayed value is deterministic toy arithmetic, rounded to three decimals. There is no network, random initialization, or training dataset download. The rate is a demonstration choice, not a recommendation for another model.
A training-loss curve would instead place update number or epoch on its horizontal axis and record the losses encountered during optimization. Always read the axes before interpreting a “loss curve.” And even a well-behaved downward curve leaves another question: is its loss measuring the task we care about?