Gradient Checking (C2W1L13)

DeepLearningAI · Beginner ·📐 ML Fundamentals ·8y ago

Key Takeaways

Explains gradient checking in deep learning

Full Transcript

gradient checking this technique this helped me save tons of time and help me find bugs in my implementation of backpropagation many times let's see how you can use it to to debug or to verify that your implementation of that top is correct so your new network will have some set of parameters W 1 V 1 and so on up to WL PL so to implement gradient checking the first thing you should do is take all your parameters and reshape them into a giant vector theta so so what you should do is take W which is a matrix and reshape it into a vector you'll take all of these WS and reshape them into vectors and then concatenate all of these things so that you have a giant vector theta giant vector parameters theta so instead of a cost function J being a function of you know the W's and B's you will now have the cost function J being just a function of theta mixed with W and be ordered the same way you can also take DW 1 DB 1 and so on and reshape them into Big John vector D theta of the same dimension as theta right so same as before reshape DW 1 into the matrix EB ones already vector reshape dwl all the DWS which are matrices remember DW 1 has the same dimension as W 1 DB 1 is sin which the B 1 so the same sort of reshaping and concatenation operation you can then reshape all of these derivatives into a giant vector D theta which is same dimension as theta so the question is now is D theta the gradient or the slope of the cost function J so just how you implement gradient checking and often abbreviate gradient checking into grande check so first remember that J is now a function of the giant parameter theta right so you can also expand without the J is a function of theta 1 theta 2 theta 3 and so on right however whatever the dimension of this giant parameter vector theta so the implement drag check what you're going to do is implement a loop so that for each I so each component of data let's compute D theta aprox I to be and we're going to take a two sided difference so I take J of theta theta 1 theta 2 up to theta I and we're going to nudge theta I to add epsilon to this so just you know increase play the I by epsilon and keep everything all the same and because it taking a two-sided difference we're going to do the same on the other side will stay to open now minus epsilon and then all of the other elements of theta are left alone and then we'll take this and we divided by 2 theta and what we saw on from the previous video is that this should be approximately equal to D theta I which which is supposed to be the partial derivative of G with respect to I guess data I if D theta I is you know the derivative of the cost function J so what you're going to do is you're going to compute this for every value of I and at the end you now end up with two vectors you end up with this D theta aprox and this is going to be the same dimension as D theta and both of these are in turn the same dimension as theta and what you want to do is check of these vectors are approximately equal to each other so in detail well how do you define whether or not two vectors are really reasonably close to each other what I do is the following on I would compute the Euclidean distance between these two vectors D theta aprox minus D theta so just - OH - normal this notice there's no square on top so this is the sum of squares of elements of the differences and then you take a square root to get the Euclidean distance and then just to normalize by the lengths of these vectors are divided by D theta aprox plus D theta just take the Euclidean length or from the defectors the role for the denominators just in case any of these vectors in really small a really large you know the denominator turns this formula interracial so when you implement this in practice I use epsilon equals maybe 10 to the minus 7 so you know one year minus seven and with this range of epsilon if you find that this formula gives you a value like ten to the minus seven or smaller then that's great it means that your derivative approximation is very likely correct now this is just very small value it is maybe on the range of ten to the minus five I would take a careful look maybe this is okay but I might double check the components of this vector and make sure that none of the components are to launch and some of the components of this difference are very large there may be other bug somewhere and if this formula on the left is you know on the order of ten to the minus three then I would worry it would be much more concerned that maybe there's a bug somewhere but you should really be getting values much smaller than 10 minus vo and if there's any bigger than 10 to minus C then I would be quite concerned I was seriously worried about whether or not there's about and I would then you should then look at the individual components of theta to see you know if there's a specific value of I for which D theta cross I is very different from D theta I and use that to try to track down whether or not some of your derivative computations might be incorrect and after some amount of debugging if finally it ends up being this kind of very small value then you probably have a correct implementation so when implementing your network will often happen as results in plan for problems and back prop and then I might find that this graduate gives a relatively big value in and I was suspected it must be a bug go in debug debug debug and after debugging for a while if I find it a partial strand check with a small value then you know you can be much more confident that is them correct so you now know how a gradient checking works doesn't help me find lots of both in my implementations at neural nets and I hope will help you too in the next video I want to share you some tips or some notes on how to actually implement gradient checking let's go onto the next video

Original Description

Take the Deep Learning Specialization: http://bit.ly/2vxxRu1 Check out all our courses: https://www.deeplearning.ai Subscribe to The Batch, our weekly newsletter: https://www.deeplearning.ai/thebatch Follow us: Twitter: https://twitter.com/deeplearningai_ Facebook: https://www.facebook.com/deeplearningHQ/ Linkedin: https://www.linkedin.com/company/deeplearningai
Watch on YouTube ↗ (saves to browser)
Sign in to unlock AI tutor explanation · ⚡30

Playlist

Uploads from DeepLearningAI · DeepLearningAI · 9 of 60

1 Forward and Backward Propagation (C1W4L06)
Forward and Backward Propagation (C1W4L06)
DeepLearningAI
2 deeplearning.ai's Heroes of Deep Learning: Yuanqing Lin
deeplearning.ai's Heroes of Deep Learning: Yuanqing Lin
DeepLearningAI
3 deeplearning.ai's Heroes of Deep Learning: Ruslan Salakhutdinov
deeplearning.ai's Heroes of Deep Learning: Ruslan Salakhutdinov
DeepLearningAI
4 deeplearning.ai's Heroes of Deep Learning: Yoshua Bengio
deeplearning.ai's Heroes of Deep Learning: Yoshua Bengio
DeepLearningAI
5 deeplearning.ai's Heroes of Deep Learning: Pieter Abbeel
deeplearning.ai's Heroes of Deep Learning: Pieter Abbeel
DeepLearningAI
6 deeplearning.ai's Heroes of Deep Learning: Ian Goodfellow
deeplearning.ai's Heroes of Deep Learning: Ian Goodfellow
DeepLearningAI
7 deeplearning.ai's Heroes of Deep Learning: Andrej Karpathy
deeplearning.ai's Heroes of Deep Learning: Andrej Karpathy
DeepLearningAI
8 Using an Appropriate Scale (C2W3L02)
Using an Appropriate Scale (C2W3L02)
DeepLearningAI
Gradient Checking (C2W1L13)
Gradient Checking (C2W1L13)
DeepLearningAI
10 Gradient Checking Implementation Notes (C2W1L14)
Gradient Checking Implementation Notes (C2W1L14)
DeepLearningAI
11 Learning Rate Decay (C2W2L09)
Learning Rate Decay (C2W2L09)
DeepLearningAI
12 Understanding Mini-Batch Gradient Dexcent (C2W2L02)
Understanding Mini-Batch Gradient Dexcent (C2W2L02)
DeepLearningAI
13 Mini Batch Gradient Descent (C2W2L01)
Mini Batch Gradient Descent (C2W2L01)
DeepLearningAI
14 The Problem of Local Optima (C2W3L10)
The Problem of Local Optima (C2W3L10)
DeepLearningAI
15 Exponentially Weighted Averages (C2W2L03)
Exponentially Weighted Averages (C2W2L03)
DeepLearningAI
16 Tuning Process (C2W3L01)
Tuning Process (C2W3L01)
DeepLearningAI
17 Understanding Exponentially Weighted Averages (C2W2L04)
Understanding Exponentially Weighted Averages (C2W2L04)
DeepLearningAI
18 Bias Correction of Exponentially Weighted Averages (C2W2L05)
Bias Correction of Exponentially Weighted Averages (C2W2L05)
DeepLearningAI
19 Gradient Descent With Momentum (C2W2L06)
Gradient Descent With Momentum (C2W2L06)
DeepLearningAI
20 Normalizing Activations in a Network (C2W3L04)
Normalizing Activations in a Network (C2W3L04)
DeepLearningAI
21 Hyperparameter Tuning in Practice (C2W3L03)
Hyperparameter Tuning in Practice (C2W3L03)
DeepLearningAI
22 Adam Optimization Algorithm (C2W2L08)
Adam Optimization Algorithm (C2W2L08)
DeepLearningAI
23 RMSProp (C2W2L07)
RMSProp (C2W2L07)
DeepLearningAI
24 Fitting Batch Norm Into Neural Networks (C2W3L05)
Fitting Batch Norm Into Neural Networks (C2W3L05)
DeepLearningAI
25 Why Does Batch Norm Work? (C2W3L06)
Why Does Batch Norm Work? (C2W3L06)
DeepLearningAI
26 Batch Norm At Test Time (C2W3L07)
Batch Norm At Test Time (C2W3L07)
DeepLearningAI
27 Softmax Regression (C2W3L08)
Softmax Regression (C2W3L08)
DeepLearningAI
28 Deep Learning Frameworks (C2W3L10)
Deep Learning Frameworks (C2W3L10)
DeepLearningAI
29 Neural Network Overview (C1W3L01)
Neural Network Overview (C1W3L01)
DeepLearningAI
30 Training Softmax Classifier (C2W3L09)
Training Softmax Classifier (C2W3L09)
DeepLearningAI
31 Why Deep Representations? (C1W4L04)
Why Deep Representations? (C1W4L04)
DeepLearningAI
32 Gradient Descent For Neural Networks (C1W3L09)
Gradient Descent For Neural Networks (C1W3L09)
DeepLearningAI
33 Neural Network Representations (C1W3L02)
Neural Network Representations (C1W3L02)
DeepLearningAI
34 TensorFlow (C2W3L11)
TensorFlow (C2W3L11)
DeepLearningAI
35 Activation Functions (C1W3L06)
Activation Functions (C1W3L06)
DeepLearningAI
36 Explanation For Vectorized Implementation (C1W3L05)
Explanation For Vectorized Implementation (C1W3L05)
DeepLearningAI
37 Getting Matrix Dimensions Right (C1W4L03)
Getting Matrix Dimensions Right (C1W4L03)
DeepLearningAI
38 Understanding Dropout (C2W1L07)
Understanding Dropout (C2W1L07)
DeepLearningAI
39 Building Blocks of a Deep Neural Network (C1W4L05)
Building Blocks of a Deep Neural Network (C1W4L05)
DeepLearningAI
40 Why Non-linear Activation Functions (C1W3L07)
Why Non-linear Activation Functions (C1W3L07)
DeepLearningAI
41 Computing Neural Network Output (C1W3L03)
Computing Neural Network Output (C1W3L03)
DeepLearningAI
42 Backpropagation Intuition (C1W3L10)
Backpropagation Intuition (C1W3L10)
DeepLearningAI
43 Train/Dev/Test Sets (C2W1L01)
Train/Dev/Test Sets (C2W1L01)
DeepLearningAI
44 Deep L-Layer Neural Network (C1W4L01)
Deep L-Layer Neural Network (C1W4L01)
DeepLearningAI
45 Random Initialization (C1W3L11)
Random Initialization (C1W3L11)
DeepLearningAI
46 Other Regularization Methods (C2W1L08)
Other Regularization Methods (C2W1L08)
DeepLearningAI
47 Normalizing Inputs (C2W1L09)
Normalizing Inputs (C2W1L09)
DeepLearningAI
48 Derivatives Of Activation Functions (C1W3L08)
Derivatives Of Activation Functions (C1W3L08)
DeepLearningAI
49 Parameters vs Hyperparameters (C1W4L07)
Parameters vs Hyperparameters (C1W4L07)
DeepLearningAI
50 Vectorizing Across Multiple Examples (C1W3L04)
Vectorizing Across Multiple Examples (C1W3L04)
DeepLearningAI
51 What does this have to do with the brain? (C1W4L08)
What does this have to do with the brain? (C1W4L08)
DeepLearningAI
52 Dropout Regularization (C2W1L06)
Dropout Regularization (C2W1L06)
DeepLearningAI
53 Vanishing/Exploding Gradients (C2W1L10)
Vanishing/Exploding Gradients (C2W1L10)
DeepLearningAI
54 Basic Recipe for Machine Learning (C2W1L03)
Basic Recipe for Machine Learning (C2W1L03)
DeepLearningAI
55 Bias/Variance (C2W1L02)
Bias/Variance (C2W1L02)
DeepLearningAI
56 Forward Propagation in a Deep Network (C1W4L02)
Forward Propagation in a Deep Network (C1W4L02)
DeepLearningAI
57 Weight Initialization in a Deep Network (C2W1L11)
Weight Initialization in a Deep Network (C2W1L11)
DeepLearningAI
58 Numerical Approximations of Gradients (C2W1L12)
Numerical Approximations of Gradients (C2W1L12)
DeepLearningAI
59 Regularization (C2W1L04)
Regularization (C2W1L04)
DeepLearningAI
60 Why Regularization Reduces Overfitting (C2W1L05)
Why Regularization Reduces Overfitting (C2W1L05)
DeepLearningAI

Related Reads

📰
Why Your Betas Explode: The Hidden Geometry of Multicollinearity
Discover how multicollinearity affects regression coefficients and learn to identify its hidden geometry
Towards Data Science
📰
Best current tools for Multi-Objective Surrogate-Based Optimization (MOSBO) on heterogeneous study data meta-analysis?[P]
Learn to apply Multi-Objective Surrogate-Based Optimization (MOSBO) for heterogeneous study data meta-analysis using tools like PyMOO, Platypus, and Scipy
Reddit r/MachineLearning
📰
Quantum Computing: The Future of Advanced Computing
Learn the basics of quantum computing and its potential to revolutionize advanced computing
Medium · Machine Learning
📰
Powering AI in Logistics with High-Quality Data Annotation
Learn how high-quality data annotation powers AI in logistics and why it matters for digital transformation
Medium · Machine Learning
Up next
QR Decomposition is Just Gram-Schmidt with Receipts
DataMListic
Watch →