
Understanding Gradient Checks for Artificial Neural Networks
Learn about gradient checks in artificial neural networks, including finite differences, comparing numerical and analytic gradients, handling relative errors, and debugging procedures to ensure correct gradient computations.
Download Presentation

Please find below an Image/Link to download the presentation.
The content on the website is provided AS IS for your information and personal use only. It may not be sold, licensed, or shared on other websites without obtaining consent from the author. If you encounter any issues during the download, it is possible that the publisher has removed the file from their server.
You are allowed to download the files provided on this website for personal or commercial use, subject to the condition that they are used lawfully. All files are the property of their respective owners.
The content on the website is provided AS IS for your information and personal use only. It may not be sold, licensed, or shared on other websites without obtaining consent from the author.
E N D
Presentation Transcript
Gradient Checks for ANN Yujia Bao Mar 7, 2017
Finite Difference Let ?(?) be any differentiable function, we can approximate its derivative by d?(?) d? =? ? + ? ?(? ?) 2? + ?(?2) for some very small number ?.
How to compare the numerical gradient with the analytic gradient?
Relative Error Let ?? be the numerical gradient calculated using finite difference, and ?? be the analytic gradient calculated using back prop. Define the relative error ?? ?? ????? = max ?? , ?? ,???????
Relative Error ????? > 10 4usually means the analytic gradient is wrong. ????? < 10 4is fine for sigmoid activation (including logistic, tanh, softmax). But if you are using (leaky) ReLU, then 10 4might be too large. ????? < 10 7means your analytic gradient is correct.
Debugging Procedure Goal: Check the gradient for a single weight ? is computed correctly. Given: One example (Input features with a label) Forward prop and Backward prop to get the gradient for ?. Let ? ? + ? (I usually choose ? = 10 5). Forward prop to get the output, and then compute the loss. Let ? ? 2? (Now ? is ??????? ?). Forward prop to get the output, and then compute the loss. Check the relative error. Recover the origin weight by ? ? + ?.
Debugging Procedure Suppose our network has the following structure: Input -> Conv1 -> Pool1 -> Conv2 -> Pool2 -> ReLU -> Output If the gradients from Input to Conv1 are correct, then we are done! Otherwise, we check the gradients from Pool1 to Conv2 (since there is no weights from Conv1 to Pool1). If it is correct, then this means there are some bugs in our Back prop code from Pool1 to Input. And so on