You have implemented backpropagation by hand and want to test it with gradient checking. Why is the central difference preferred to the forward difference, how do you compare it with your analytic gradient, and what goes wrong if is too large or too small? Illustrate with at and ?
Deep learning, Backpropagation
Level L3 Intermediate. Length Medium. Nature Th+Mat Both.
What's being asked
Whether you know how to test a backprop implementation, including the order of the numerical error and its practical limits.
Key idea
Taylor expansion shows that the forward difference has error while the central difference has error . The numerical gradient is compared with the analytic one by relative error, and must balance truncation error (large ) against round-off error (tiny ).
Steps
- Expand . Subtracting, the even terms cancel: , an error. The forward difference has error.
- Example. so . Central: , an error of . Forward: , an error of .
- Compare using a relative error, because absolute error depends on the scale: . In double precision with , values below about are good and values above about signal a bug.
- If is too large, truncation error dominates. If is too small (say ), and agree in almost all digits, so subtracting them loses precision (round-off error roughly ).
- Check each parameter in turn (or a random subset), run the check on a tiny network and batch, and use double precision.
- Switch off random behaviour (dropout, data augmentation) or fix its random seed, otherwise changes between the two evaluations. Also turn off batch-norm updates of running statistics, and test away from kinks such as the ReLU at .
Common mistakes
- Using the forward difference and then deciding that a gradient is wrong because the error is about , when it is the expected truncation error.
- Leaving dropout on during the check, so the two loss evaluations use different masks.
- Using single precision or a tiny such as , which makes round-off error larger than the quantity being measured.
- Using gradient checking inside training. It costs two forward passes per parameter, so it is a debugging tool only.
How long your answer should be
Half a page; 4–5 minutes.
Last checked on 4 December 2026.
Read this
Previous in Deep learning: A scalar parameter starts at and is trained with Adam using learning rate , , and . The first two gradients are and . What are and , and what would the first step have been without bias correction?
Next in Deep learning: A network has input , two hidden units, and one linear output . All weights and biases start at . The loss is and the learning rate is . What happens over two gradient-descent steps (a) with sigmoid hidden units and (b) with ReLU hidden units, and what happens to the two hidden units?