Back to Neural Networks Training and Debugging
Neural Networks Training and Debugging · Lesson 2 of 2 in this module
Understand gradient contributions
- Starting information
A weight affects two paths to a loss
- Relationship or operation
Calculate each path's contribution, then add
- Consequence
One total gradient for that weight
Backpropagation traces how a parameter changes loss through connected operations. All updates use the same pre-update values.
The idea in everyday terms
Think of two adjustable knobs connected in a chain. The first changes an intermediate value and the second changes the final prediction. To improve the prediction, we need to know how much each knob contributes to the error. Backpropagation calculates these sensitivities by working backward through the chain.
What to watch in the experiment
First calculate and keep the forward values. Then work backward, multiplying the sensitivities along each connection. Keep both weights fixed while calculating both gradients. Only after that does the optimizer use the gradients to change the weights together.
What this does not establish
A gradient is a local sensitivity, not a new weight or a guarantee of a better final model. Updating a weight midway changes the calculation and no longer reproduces this simultaneous update.
Full worked explanation, calculations and control definitions
Use this reference for the detailed mechanism and control meanings. Derivations explicitly marked optional are enrichment.
First, keep the forward values
We compute h = w₁x, prediction = w₂h, and L = ½(prediction − target)². The factor ½ makes the derivative simpler; it is a different scaling from the previous lesson, so compare losses within this example.
With input 2, target 10, and weights 3 and 1, hidden value h = 6, prediction = 6, and loss = 8. Keep these intermediate values: the backward pass will reuse them.
Multiply local sensitivities along each path
The derivative of loss with respect to prediction is prediction − target, here −4. Changing w₂ changes prediction by h times as much, so its gradient is −4 × 6 = −24.
For w₁, the influence passes through h and then w₂. Multiply the local sensitivities: −4 × w₂ × x = −4 × 1 × 2 = −8. This is the chain rule: changes propagate through dependent operations.
Now the optimizer can take a step
Use gradients from the same old weights for both updates. With rate 0.01, w₁ becomes 3.08 and w₂ becomes 1.24. The new prediction is 7.6384 and the loss is about 2.7886. Updating one weight before calculating the other gradient would be a different procedure.
Backpropagation reuses intermediate values rather than perturbing every parameter and rerunning the whole model. Automatic differentiation applies these rules across large graphs. Long chains can shrink or amplify gradients; initialization, residual connections, normalization, and gradient clipping can help.