Recommended resources
The freely available resources this lesson will direct you to.
- Lecture 6: Backpropagationwww.youtube.com
- CS231n Winter 2016: Lecture 4: Backpropagation, Neural Networks 1www.youtube.com
- 5.3. Forward Propagation, Backward Propagation, and Computational Graphs — Dive into Deep Learning 1.0.3 documentationd2l.ai
- CS231n Deep Learning for Computer Visioncs231n.github.io
Welcome back. Last time, you turned a model’s probability for the correct class into a cross-entropy loss. That gave you a way to measure an error. Today’s question is different: if an input changes slightly, how much does the final output change?
You’ll use the chain rule to answer that question for a computation with two operations. This is the small-scale version of the calculation that lets a neural network find gradients of its loss. Allow about 35–40 minutes for the video and the worked examples.
One computation, two operations
Consider a number that is first processed by a function . Call the intermediate result . A second function turns into the final result :
A computation graph keeps these operations separate. The image below shows that structure; its is the intermediate value we are calling .

Suppose a small change in produces about three times that change in . If a small change in then produces about twice that change in , the change in is about six times the original change in . The chain rule expresses this multiplication of local rates of change:
A derivative here is a rate of change at a particular input value. The important detail is that the outer function’s derivative, , is evaluated at the intermediate value , not necessarily at the original input .
Forward values, backward gradients
Watch the two-operation example in Michigan Online’s Lecture 6: Backpropagation. The lecturer uses an addition operation followed by a multiplication operation. Pay attention to the difference between calculating the output and calculating how sensitive that output is to an input.
Michigan Online’s “Lecture 6: Backpropagation” shows a forward pass through a small computation graph and a backward pass that applies the chain rule.
Watch the worked graph, from the introduction of the addition-and-multiplication example through the gradients for its inputs. Then watch the local view to see why each operation needs only its own derivative and the gradient arriving from later in the graph.
Here is that calculation in compact form. The graph has three inputs and two operations:
With , , and , the forward pass calculates and then . Keeping available matters: its value is needed when calculating a gradient.
The backward pass starts at the final result. The derivative of with respect to itself is . At the multiplication operation, changing while holding fixed changes at a rate of . Changing while holding fixed changes at a rate of :
The addition operation has a local derivative of with respect to either of its inputs. To find the effect of on the final result, multiply the gradient already found at by that local derivative:
The same reasoning gives . These are partial derivatives: when considering a change to one input, the other inputs are held fixed. Notice that ’s gradient is , while ’s and ’s are . Their routes through the graph differ, even though they all influence .
Apply the rule to a single-input graph
Let’s use the structure in the image with two different operations:
At , calculate the forward values first. The intermediate value is , and the final value is .
Now work backward. For the squaring operation, , which equals at . For the first operation, . Therefore,
The result says that near , a small increase of in should increase by roughly . As a check, at , the exact output is , an increase of . The derivative gives the local approximation; it need not predict a finite change exactly.
This example also shows a common mistake. Substituting directly into would give , not . The squaring operation receives , so its derivative must be evaluated there.
Connecting gradients to loss
The final output of a training computation is often a loss, like the cross-entropy loss from the previous lesson. For one correct-class probability , you learned that . Imagine a deliberately simplified two-operation model that sets , with . Its operations are:
At , the forward pass gives and . The local derivative of the loss operation is at . The local derivative of the probability operation is . Chaining them gives
This linear rule for is a toy example, not how a real classifier normally computes probabilities. Its purpose is to make the chain rule visible: the negative gradient tells us that, near , increasing slightly would decrease this example’s loss. Finding that gradient and deciding how to change are separate tasks; the latter is the subject of the next lesson.
Key takeaways
For a two-operation graph, calculate intermediate values in the forward pass. Then, working from the output backward, multiply the gradient from the later operation by the earlier operation’s local derivative. Evaluate each local derivative at the value that operation actually received.
That is the chain rule behind backpropagation. Next, you’ll take a supplied gradient and use it to perform one gradient-descent parameter update.