Foundations / Gradient Descent & Backpropagation
Gradient Descent & Backpropagation
IntermediateBackpropagation efficiently computes gradients of the loss with respect to every weight using the chain rule.
Gradient descent
Parameters move in the negative-gradient direction, scaled by the learning rate η. For a smooth loss and a nonzero gradient, a sufficiently small step decreases the loss; an excessively large step can increase it.
θ contains the learnable parameters, t is the optimization step, and ηₜ > 0 is the learning rate.
The chain rule
For a network computing L = l(f₃(f₂(f₁(x)))), the gradient flows backward layer by layer. Each layer only needs its local derivative and the gradient arriving from above.
This illustrates a single scalar computation path with a₁ = f₁(x), a₂ = f₂(a₁), and a₃ = f₃(a₂). For vectors, backpropagation uses Jacobian-transpose–vector products and sums contributions from every path.
Training loop
for epoch in range(epochs):
for x, y in loader:
y_hat = model(x) # forward pass
loss = loss_fn(y_hat, y) # compute loss
optimizer.zero_grad()
loss.backward() # backpropagation
optimizer.step() # update weightsVanishing & exploding gradients
- Repeated multiplication of small derivatives shrinks gradients toward zero in deep networks.
- Remedies: ReLU, careful initialisation (He / Xavier), batch/layer normalisation, residual connections, gradient clipping.
Interview questions & answers
Q1. How are backpropagation and gradient descent different?
Answer: Backpropagation computes derivatives of the loss with respect to parameters by applying the chain rule backward through the computation graph. Gradient descent uses those derivatives to update parameters. Computing a gradient does not itself change the weights.
Q2. What happens if the learning rate is too large or too small?
Answer: A rate that is too large can overshoot useful regions and make training oscillate or diverge. A very small rate can make progress unnecessarily slow. Tune it using validation performance and learning curves; a schedule can reduce the rate as training progresses.
Q3. What causes vanishing and exploding gradients?
Answer: Backpropagation multiplies local derivatives through layers or time steps. Repeated contraction can shrink gradients, while repeated amplification can make them explode. Suitable initialization, residual connections and gated recurrent units help gradient flow; gradient clipping limits exploding gradients.