DEEP LEARNING / 2. BACKPROPAGATION
Backpropagation
How networks actually learn — chain rule applied recursively
EXPLANATION
Backpropagation is just the chain rule of calculus applied to a computation graph. Nothing more. The goal: compute ∂Loss/∂w for every weight w in the network. Then update: w = w - lr * ∂Loss/∂w Steps: 1. Forward pass → compute predictions, store intermediate values 2. Compute loss → how wrong are we? (MSE, CrossEntropy, etc.) 3. Backward pass → compute gradients layer by layer, from output to input 4. Update → gradient descent step PyTorch does all of this automatically via autograd. You just call loss.backward() and it computes all gradients. But understanding what's happening under the hood is essential for debugging and designing architectures.
DATA FLOW
FORWARD PASS (left to right, store values): x → [Layer1] → h1 → [Layer2] → h2 → [Layer3] → ŷ → Loss BACKWARD PASS (right to left, chain rule): ∂L/∂w3 = ∂L/∂ŷ · ∂ŷ/∂w3 ∂L/∂w2 = ∂L/∂ŷ · ∂ŷ/∂h2 · ∂h2/∂w2 ∂L/∂w1 = ∂L/∂ŷ · ∂ŷ/∂h2 · ∂h2/∂h1 · ∂h1/∂w1 Each gradient = product of all gradients downstream PyTorch: loss.backward() does this automatically
CODE