Backprop step-through
Backpropagation is the chain rule, applied in an order that reuses work. The forward pass computes every value from the inputs to the loss. The backward pass then walks the same graph in reverse, and at each node multiplies the gradient arriving from the right by that node’s own local derivative.
Weight the two inputs, add the bias, then apply the sigmoid activation.
Forward pass
Hidden unit 1
z₁ = w₁₁·x₁ + w₁₂·x₂ + b₁
= 0.4 · 1 + (−0.2) · 0.5 + 0.1
= 0.4
h₁ = σ(z₁) = 1 / (1 + e^(−z₁))
= 1 / (1 + e^(−0.4))
= 0.5987
Network and example
wⱼₖ: input k to hidden unit j. bⱼ: hidden bias. vⱼ: hidden unit j to the output. c: output bias.
| Step | Pass | Works on |
|---|---|---|
| Forward pass | Hidden unit 1 | |
| Forward pass | Hidden unit 2 | |
| Forward pass | Output | |
| Forward pass | Loss | |
| Backward pass | Loss | |
| Backward pass | Output | |
| Backward pass | Weight v₁ (hidden 1 to output) | |
| Backward pass | Weight v₂ (hidden 2 to output) | |
| Backward pass | Hidden unit 1 | |
| Backward pass | Hidden unit 2 |
Gradients so far
| Parameter | Value | ∂L/∂parameter | After update |
|---|---|---|---|
| w₁₁ | 0.4 | – | – |
| w₁₂ | −0.2 | – | – |
| b₁ | 0.1 | – | – |
| w₂₁ | 0.3 | – | – |
| w₂₂ | 0.6 | – | – |
| b₂ | −0.1 | – | – |
| v₁ | 0.5 | – | – |
| v₂ | −0.4 | – | – |
| c | 0.2 | – | – |
What it shows
A network learns by finding how much each weight changes the loss. Backpropagation does this by working backwards, so each step reuses what the last one found.
This network is small enough to follow by eye: two inputs, two or three hidden units and one output. You choose the weights, activations and loss, then step through one node or edge at a time. Each step shows the rule in symbols, the same rule with numbers, and the result.
How to read it
- The forward pass runs first. Each hidden unit computes a weighted sum z, then its activation h. The output unit does the same, and the loss comes last.
- The backward pass starts at the loss. Each line multiplies local derivatives. The last factor is the input a weight multiplied, or 1 for a bias.
- Round nodes are units and the square is the loss. Edge labels show the weight going forward and ∂L/∂weight going back.
- Apply update subtracts the learning rate times each gradient from its parameter, then restarts the steps. Watch the loss fall.
- The gradient check compares each gradient with a numerical estimate. Relative error below 1e−7 is a match. 1e−2 or more is likely a bug.
Questions
Why does backpropagation go backwards?
The loss depends on early weights only through every node after them. Starting from the loss and moving back lets each node reuse the gradient already computed for the nodes to its right, so the whole gradient costs about as much as one forward pass instead of one pass per weight.
Why does cross-entropy give ŷ − t?
With a sigmoid output and binary cross-entropy, the sigmoid’s slope ŷ(1 − ŷ) cancels the 1/(ŷ(1 − ŷ)) in the loss derivative, leaving ∂L/∂s = ŷ − t. Choose cross-entropy and compare the output step with the mean squared error one.
What does a gradient check tell me?
It compares the gradient from your backward pass with a slow numerical estimate. If the relative error is around 1e−7 or smaller, the backward pass is almost certainly right. Around 1e−2 or larger, it is probably wrong. Checks are run on small networks and then switched off.
Why does a ReLU unit sometimes show zero gradients?
ReLU has slope 0 for negative inputs, so a unit whose sum z is below zero passes no gradient back to its weights. This tool also uses slope 0 at exactly z = 0. Numerical checks near that kink can disagree slightly, which is why a ReLU error of 1e−4 is acceptable.
Learn it properly
Sources
Explore further
- microgradAndrej Karpathy’s tiny autograd engine: backpropagation you can read in one sitting.
Last updated
More tools
All tools- explorerVector similarity explorerDrag vectors to see cosine, dot product and distance agree and disagree, or paste embeddings of any length.Open tool
- explorerMatrix transform visualiserSee a 2×2 matrix stretch, turn, flip or squash the plane, with its determinant and eigenvectors.Open tool
- explorerProbability distribution explorerPlot six common distributions, with mean, variance, mode and the probability of any interval.Open tool