Recommended resources
The freely available resources this lesson will direct you to.
Hello. In the previous lesson, you used eigenvectors and SVD to reason about a representation geometrically: PCA chooses directions that preserve variance. This lesson shifts from representation geometry to learning: how a model discovers parameter changes that reduce a loss.
You will build the core training loop from first principles. By the end, you should be able to compute gradients through a small neural unit using the chain rule, explain why backpropagation is efficient, and state precisely how gradient descent updates weights and biases. This is the level of explanation expected in an ML interview before discussing optimizer variants, distributed training, or debugging unstable training.
Gradients are local sensitivity measurements
Let a scalar loss depend on parameters collected in a vector . The gradient is the vector of partial derivatives:
Each entry answers a local question: if I make this parameter slightly larger while holding the others fixed, how does the loss change?
- A positive partial derivative means increasing that parameter raises the loss locally.
- A negative partial derivative means increasing it lowers the loss locally.
- A large magnitude means the loss is locally sensitive to that parameter.
- A derivative near zero means the loss changes little for a very small change in that parameter. It does not automatically prove the model has reached a good optimum.
For a small parameter perturbation , the first-order approximation is:
This approximation is the mathematical justification for gradient-based training. It says the dot product between a proposed parameter change and the gradient estimates the corresponding loss change.
CS231n Deep Learning for Computer Vision
Read the relevant portions of Stanford's CS231n optimization notes to reinforce the practical meaning of a derivative, then see the chain rule expressed as a backward pass through a computation.
In “Simple expressions and interpretation of the gradient,” read the derivative intuition. Focus on derivatives as local sensitivity, rather than as merely symbolic calculus. Then, in “Compound expressions with chain rule,” read the scalar chain rule example. Trace the forward values and the backward derivatives separately. Finally, in “Backprop in practice: Staged computation,” read the paragraph beginning the implementation principle. The key engineering habit is to break a forward computation into stages whose local derivatives are simple.
For interview purposes, call the gradient a vector of loss sensitivities. That phrase establishes the connection between calculus and training behavior without implying that a gradient predicts large parameter changes reliably.
The chain rule becomes backpropagation
A model is a composition of operations. Consider one sigmoid neuron:
Here, and are a feature and target, and are learnable parameters, is the prediction, and is the loss for one example.
To calculate how the loss changes with the weight, follow the dependencies from through , then , then . The chain rule multiplies the local derivatives along that path:
The three terms have distinct meanings:
Therefore,
For the bias, the only difference is that:
So:
It is convenient to name the shared error signal:
Then the parameter gradients become:
This compact form is useful for diagnosing learning. For example, if is tiny because a sigmoid is saturated, both the weight and bias will receive tiny updates even if the feature value is informative.

Backpropagation is not a separate kind of calculus. It is an efficient algorithm for applying the chain rule to a computational graph:
- Run the forward pass, computing and caching intermediate values needed for local derivatives.
- Start from the scalar loss, whose derivative with respect to itself is .
- Propagate derivative information backward through each operation.
- At a point where the graph branches in the forward pass, sum gradient contributions from all downstream paths.
The last rule matters in networks with skip connections or any parameter reused in multiple computations. A parameter’s total gradient must capture every route by which changing it can change the loss.
Backpropagation calculus | Deep Learning Chapter 4
Watch “Backpropagation calculus” from 3Blue1Brown. It gives a visual derivation of a weight gradient and then extends the same reasoning to multiple neurons and layers.
Begin with one weight gradient. Focus on the three factors connecting a last-layer weight to the cost: prediction error, activation sensitivity, and incoming activation. Then watch earlier layers to see why an earlier activation can contribute through several downstream units, requiring those contributions to be summed. Finish with the summary, which connects these derivatives to the gradient used for training.
A complete numerical gradient calculation
Take a single example with:
The forward pass is:
Now work backward. First calculate the error signal at the pre-activation:
Then calculate parameter gradients:
The negative gradients mean that, at this point, increasing both and should reduce this example’s loss. This makes intuitive sense: the target is , but the prediction is only , so the model needs a larger logit and hence a larger predicted probability.
For a layer with vector input , output , weight matrix , and bias vector :
Suppose:
If the upstream gradient is:
then the central backward-pass equations are:
This is a useful dimension check from the previous lesson: the gradient of a parameter must have the same shape as that parameter. In particular, must have the same shape as .
For a mini-batch , training usually minimizes average loss:
Thus, its gradient is the average of the per-example gradients:
Modern frameworks compute these vectorized quantities automatically, but the underlying calculation remains this repeated local application of the chain rule.
From gradients to parameter updates
Once backpropagation has produced a gradient, gradient descent chooses a parameter change in the opposite direction:
The scalar is the learning rate.
Substitute the proposed change:
into the first-order approximation:
For a sufficiently small learning rate, this predicted change is non-positive. That is why the negative gradient is the direction of steepest local decrease under the usual Euclidean geometry.
Returning to the numerical neuron example, use:
The update is:
Both parameters increase, as predicted by the negative gradients. The new logit is:
The new prediction is slightly above , closer to the target , and the loss falls.

A practical training iteration therefore has four conceptual parts:
- Forward pass: compute predictions from a mini-batch.
- Loss computation: compare predictions with targets.
- Backward pass: use backpropagation to compute parameter gradients.
- Optimizer step: update parameters using the gradients and a learning-rate rule.
The terms are often conflated, so state them distinctly in interviews:
- Backpropagation computes gradients efficiently.
- Gradient descent uses gradients to update parameters.
- Automatic differentiation is the software mechanism that records operations and executes the backward calculations.
- An optimizer implements a particular update rule. Plain SGD is the simplest example.
Gradient Descent, Step-by-Step
Watch the selected parts of StatQuest’s “Gradient Descent, Step-by-Step” for a concrete view of turning derivatives into successive parameter changes.
Watch one parameter descent to connect the sign and magnitude of a derivative to the direction and size of an update. Then watch two parameter descent, focusing on why a gradient contains one derivative per parameter and why learning-rate choice matters. Use the algorithm recap as a concise mental checklist for the training loop.
What can go wrong, and how to validate gradients
The update equation is simple, but it is only a local approximation. Several implementation and optimization issues can make training fail.
Learning rate too large. The first-order approximation no longer predicts the true loss well across such a large step. Loss can oscillate, diverge, or become numerically invalid.
Learning rate too small. Loss may decrease, but impractically slowly. In a finite training budget, this can look like stalled learning.
Feature scale changes gradient scale. In the scalar example,
Scaling by scales the weight gradient by . This is one mathematical reason input normalization often makes optimization more stable.
Incorrect loss reduction. A common implementation bug is summing loss in one place and averaging it in another, changing gradient magnitude with batch size. If training behavior changes dramatically when only batch size changes, inspect loss reduction and learning-rate scaling.
Broken computational graph. Accidental detachment, incorrect tensor broadcasting, in-place mutation, or a non-differentiable operation can eliminate or corrupt a gradient. In a production training pipeline, logging gradient norms by layer and checking for missing gradients should be standard debugging steps.
For a small model or custom operation, use a finite-difference gradient check. For coordinate , compare backpropagation’s derivative with:
where changes only coordinate . This is too expensive for routine large-model training, but it is highly effective for validating a new loss function or custom layer on a tiny deterministic example.
A precise interview response when asked why backpropagation is needed:
“A neural network is a composition of differentiable operations. Backpropagation applies the chain rule from the scalar loss backward through that computation graph, reusing intermediate values to compute the gradient with respect to every parameter efficiently. Gradient descent then subtracts a learning-rate-scaled version of that gradient. The negative sign matters because the gradient points toward the steepest local increase in loss.”
Key takeaways
A gradient is a vector of partial derivatives that describes local loss sensitivity to each parameter. The chain rule lets you compute a parameter gradient by multiplying local derivatives along a dependency path; when a value influences the loss by multiple paths, its contributions add.
Backpropagation is the reverse traversal that computes these gradients efficiently after a forward pass. For a simple sigmoid unit with squared loss:
Gradient descent converts those gradients into learning:
The backward pass computes sensitivities; the optimizer uses them to change parameters. Keeping that distinction clear will help in both deep-learning debugging and technical interviews.
Next, you will begin the Classical Machine Learning and Evaluation module by deriving linear-regression predictions and regularized training objectives.