Calculus & Derivatives
Theme
Palette
Download
Caption (tap to copy)
📖 Deep dive (full written explanation)
This post shifts from 'what is a derivative' to 'why does it matter so much.' The honest answer is that derivatives are not background mathematics you can safely skim — they are the literal mechanism by which a model learns. Strip them out and training is impossible.
The aim here is to make that mechanism vivid. By the end you should see the phrase 'the model learned' and immediately think 'derivatives of the loss told each weight which way to move, and it moved.' That reframing is the whole point of the post.
Learning is slope-following, full stop. A fresh model has random weights and therefore a large loss. For each weight, the derivative of the loss tells you the direction in which loss increases. Stepping the opposite way — downhill — reduces the error a little. Do this millions of times across all the weights and the model gradually settles into a configuration that fits the data.
The critical realization is that there is no other source of direction. The slope is the only thing telling the optimizer which way is 'better.' Remove it and you're left guessing in a space with millions of dimensions, where random search never converges in any reasonable time.
When a function depends on many inputs — and a neural network's loss depends on millions of weights — the single-number derivative generalizes to a vector called the gradient. Each component is a partial derivative: how the loss responds to one specific weight while all others are held fixed.
A key property is that the gradient points in the direction of steepest increase of the function. Since we want to decrease the loss, we step in the opposite direction, −∇L. The gradient bundles together, in one object, the direction and relative steepness for every parameter simultaneously, which is exactly what an optimizer needs.
The cycle diagram lays out the core training loop that every model runs: predict (forward pass), measure the loss (how wrong the prediction was), compute the gradient (the derivatives of loss with respect to each weight, via backprop), and update the weights (step against the gradient). Then it repeats.
Drawing it as a cycle is deliberate — training is iterative, and each pass through nudges the weights a little closer to a good configuration. Three of the four stages are pure calculus or depend on it directly, which underscores how central derivatives are to the whole process.
This snippet strips gradient descent down to its essence on a one-dimensional problem: minimizing (w − 4)², whose minimum is obviously at w = 4. The derivative is 2(w − 4), and each iteration steps w against that slope scaled by the learning rate.
Watching w climb 0.8, 1.44, 1.952, 2.362, 2.689… toward 4 demonstrates the entire principle in miniature. A real neural network does exactly this, just with millions of weights and a far more complex loss surface. The mechanism — compute slope, step opposite, repeat — is identical. Everything else is scale and bookkeeping.
The learning rate is where the derivative meets a practical knob. The gradient supplies the direction and the steepness; the learning rate decides how far along that direction you actually move on each step. It scales the slope into an actual displacement.
This is why the learning rate is famously the most important hyperparameter. Set it too small and training crawls, taking forever to descend. Set it too large and you leap past the minimum and bounce or diverge. Crucially, the learning rate only makes sense in relation to the gradient's magnitude — a fact that becomes obvious once you see the derivative behind it, and mysterious if you don't.
The comparison contrasts healthy gradient behavior with the pathological cases. Healthy gradients are finite and non-zero, flow back to every layer, and produce a loss that decreases steadily. Pathological gradients are either near zero or near infinity, which starves early layers of signal or destabilizes the whole network, leaving the loss stalled or exploding.
The reason to internalize this contrast is diagnostic. When training misbehaves, the symptom you see is in the loss curve, but the cause usually lives in the gradients. Knowing what healthy versus broken slopes look like turns vague frustration into a targeted investigation.
Vanishing and exploding gradients are the most famous calculus-driven failure modes in deep learning, and they fall straight out of the chain rule. Backpropagation computes a layer's gradient by multiplying together the local derivatives along the path from the loss back to that layer. In a deep network that's a long product of many numbers.
If those numbers are mostly less than 1, the product shrinks geometrically toward zero — vanishing — and early layers receive almost no learning signal. If they're mostly greater than 1, the product blows up — exploding — and updates become wildly unstable. These aren't bugs in your code; they're direct consequences of multiplying many derivatives, and they motivated architectural fixes like ReLU, residual connections, and normalization.
The bar chart makes the activation-derivative point concrete by comparing peak slopes. Sigmoid's derivative tops out at just 0.25, so every sigmoid layer can shrink the backpropagated gradient to at most a quarter of its incoming size. Tanh peaks at 1.0, which is better but still saturates at the extremes. ReLU has a slope of exactly 1 for any positive input, so it passes gradients through undiminished where it's active.
This is the quantitative reason ReLU displaced sigmoid and tanh in deep networks. The choice of activation function is, in large part, a choice about derivative behavior — about whether gradients survive the trip back through many layers.
These practical notes connect the calculus to engineering decisions you'll actually make. ReLU beating sigmoid was substantially a story about derivatives surviving depth. Gradient clipping directly caps the magnitude of slopes to prevent explosions. Normalization layers (batch norm, layer norm) keep activations — and therefore gradients — in a well-scaled range. And debugging stuck training very often comes down to printing and inspecting gradient statistics.
The through-line is that an enormous amount of modern deep-learning practice is, underneath, gradient management. Recognizing that lets you reason about new techniques by asking 'what does this do to the slopes?'
The closing mistake is tuning the learning rate blindly without considering the gradient's scale. The learning rate and the gradient magnitude multiply together to produce the actual step size, so they can't be reasoned about independently. If gradients are large, even a conservative-sounding learning rate can cause divergence; if gradients are tiny, a normal-looking rate produces no movement at all.
The fix is to monitor gradient norms alongside the loss curve. The norm tells you whether your slopes are healthy, vanishing, or exploding, which often explains learning-rate behavior that otherwise looks random. Watching only the loss is like driving while looking solely at the speedometer and never the road.
That closes the 'why it matters' post. The key transfer: training is derivatives in a loop — the loss is differentiated with respect to every weight, and each weight steps against its slope, scaled by the learning rate. Vanishing/exploding gradients, activation choices, and learning-rate tuning are all downstream of this one mechanism.
The next post opens the engine: the concrete rules that let you differentiate any function by hand, including the chain rule that makes backpropagation possible.