Forward and Backward Propagation (C1W4L06)
Key Takeaways
The video explains forward and backward propagation in deep learning, including the use of sigmoid activation functions and vectorization for efficiency. It also discusses the importance of organizing hyperparameters in deep neural networks.
Full Transcript
in the previous video you saw the basic blocks of implementing a deep neural network a for propagation step for each layer and a corresponding backward propagation step let's see how you can actually implement these steps will start to for propagation recall that what this will do is input a L minus 1 and output a L and the cash ZL and we just said that from implementational point of view maybe we'll cache WL + BL as well just to make the functions call a bit easier in the programming exercise and so the equations for this should already look familiar the way to implement a fourth function is just this equals WL x a l minus 1 plus B L and then a l equals the activation function applied to Z and if you want a vector rise implementation then it's just that times a L minus 1 plus B with the be adding beeping uh python for costing and a l equals he applied element wise to z and remember on the diagram for the forth step right we had this chain of bosses going forward so you initialize that with feeding and a 0 which is equal to X so you know you initialize this really what is the input to the first one right it's really um a zero which is the input features to either for one training example if you're doing one example at a time or a capital zero the entire training set if you are processing the entire training set so that's the input to the first fort function in the chain and then just repeating this allows you to compute forward propagation from left to right next let's talk about the backward propagation step here your goes to input D al and output D al minus 1 and D wo and DB let me just write out the steps you need to compute these things DZ l is equal to da l alamin Weis product with G of L prime Z of L and then computed derivatives DW l equals d ZL times AF l minus 1 i didn't explicitly put that in the cache but it turns out you need this as well and then DB l is equal to DZ l and finally da of L minus 1 there's equal to WL transpose times DZ l ok and I don't want to go through the detailed derivation for this but it turns out that if you take this definition the da and plug it in here then you get the same formula as we had in there previously for how you compute DZ l as a function of the previous DZ ow in fact well if I just plug that in here you end up that DZ L is equal to WL plus 1 transpose DZ l plus 1 times G L prime z FL I know this is a looks like a lot of algebra but actually double check for yourself that this is the equation we had written down for back propagation last week when we were doing in your network with just a single hidden layer and as reminder this times this element-wise product but so all you need is those four equations to implement your backward function and then finally I'll just write out the vectorized version so the first line becomes DZ l equals d a o element-wise product with GL prime of z oh maybe no surprise there DW l becomes 1 over m DZ l times a o minus 1 transpose and then DB l becomes 1 over m and Peter Som DZ L then access equals 1 keep dims equals true we talked about the use of an Peter Som in the previous week to compute DB and the finally da L minus 1 is WL transpose times D Z of L so this allows you to input this quantity da over here and output DW l DP l the derivatives you need as well as da L minus 1 right as follows so that's how you implement the backward function so just to summarize um take the input X you might have the first layer maybe has a rather activation function then go to the second layer maybe uses another value activation function goes to the third layer maybe has a sigmoid activation function if you're doing binary classification and this outputs y hat and then using Y hat you can compute the loss and this allows you to start your backward iteration I draw the arrows for us I guess I don't have to change pens too much where you were then have back prop compute the derivatives compute you know DW 3 DB 3 DW 2 DP 2 DW 1 DB 1 and along the way you would be computing I guess the cash would transfer Z 1 Z 2 Z 3 and here you pass backward da - and da one this could compute da zero but we won't use that so you can just discard that right and so this is how you implement for a prop and back prop for a three-layer your network now there's just one last detail that I didn't talk about which is for the forward recursion we would initialize it with the input data X how about the backward recursion well it turns out that D a of L when you're using logistic regression when you're doing binary classification is equal to Y over a plus 1 minus y over 1 minus a so turns out that the derivative of the loss function with respect to the output we're expected Y hat can be shown to be equal to dis if you're familiar with calculus if you look up the loss function L and take derivatives respect to Y hat and respect to a you can show that you get that formula so this is the formula that you should use for da for the final layer capital L and of course if you were to have a vectorized implementation then you initialize the backward recursion not with this there will be a capital A for the layer L which is going to be you know the same thing for the different examples right over a for the first training example plus 1 minus y for the first training example over 1 minus a for the first training example both on top down to the M training example so 1 minus a of them so that's how you to implement the vectorized version that's how you initialize the vectorized version of backpropagation so you've now seen the basic building blocks of both for propagation as well as back propagation now if you implement these equations you will get a correct implementation for prop and back prop to get you the derivatives you need you might be thinking wow those are all equations I'm slightly confused I'm not quite sure I see how this works and if you're feeling that way my advice is when you get to this week's programming you will be able to implement these for yourself and there'll be much more concrete and I know there was a lot of equations and maybe some of equations didn't make complete sense but if you work through the calculus and the linear algebra which is not easy so you know feel free to try but that's actually a bundle more difficult derivations in machine learning it turns out the equations roll down at just the calculus equations for computing the derivatives especially in background but once again if this feels a little bit abstract a little bit mysterious to you my advice is when you've done their prime exercise it will feel a bit more concrete to you although I have to say you know even today when I implement a learning algorithm sometimes even I'm surprised when my learning algorithm implementation works and it's because lot of the complexity of machine learning comes from the j-turn rather than from the lines of code so sometimes you feel like you implement a few lines of code not question what it did but there's almost magically works and because of all the magic is actually not in the piece of code you write which is often you know not too long it's not it's not exactly simple but there's not you know ten thousand a hundred thousand lines of code but you feed it so much data that sometimes even don't work the machine learning for a long time sometimes it's so you know surprises me a bit when my learning algorithm works because a lot of the complexity of your learning algorithm comes from the data rather than necessarily from your writing you know thousands and thousands of lines of code all right so that's um how you implement deep neural networks in the game this will become more concrete when you've done their primary exercise before moving on I want to discuss in the next video want to discuss hyper parameters and parameters it turns out that when you're training deep nets being able to organize your hyper parameters as well will help you be more efficient in developing your networks in the next video let's talk about exactly what that means
Original Description
Take the Deep Learning Specialization: http://bit.ly/2VEe1I1
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 · 1 of 60
← Previous
Next →
▶
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
Forward and Backward Propagation (C1W4L06)
DeepLearningAI
deeplearning.ai's Heroes of Deep Learning: Yuanqing Lin
DeepLearningAI
deeplearning.ai's Heroes of Deep Learning: Ruslan Salakhutdinov
DeepLearningAI
deeplearning.ai's Heroes of Deep Learning: Yoshua Bengio
DeepLearningAI
deeplearning.ai's Heroes of Deep Learning: Pieter Abbeel
DeepLearningAI
deeplearning.ai's Heroes of Deep Learning: Ian Goodfellow
DeepLearningAI
deeplearning.ai's Heroes of Deep Learning: Andrej Karpathy
DeepLearningAI
Using an Appropriate Scale (C2W3L02)
DeepLearningAI
Gradient Checking (C2W1L13)
DeepLearningAI
Gradient Checking Implementation Notes (C2W1L14)
DeepLearningAI
Learning Rate Decay (C2W2L09)
DeepLearningAI
Understanding Mini-Batch Gradient Dexcent (C2W2L02)
DeepLearningAI
Mini Batch Gradient Descent (C2W2L01)
DeepLearningAI
The Problem of Local Optima (C2W3L10)
DeepLearningAI
Exponentially Weighted Averages (C2W2L03)
DeepLearningAI
Tuning Process (C2W3L01)
DeepLearningAI
Understanding Exponentially Weighted Averages (C2W2L04)
DeepLearningAI
Bias Correction of Exponentially Weighted Averages (C2W2L05)
DeepLearningAI
Gradient Descent With Momentum (C2W2L06)
DeepLearningAI
Normalizing Activations in a Network (C2W3L04)
DeepLearningAI
Hyperparameter Tuning in Practice (C2W3L03)
DeepLearningAI
Adam Optimization Algorithm (C2W2L08)
DeepLearningAI
RMSProp (C2W2L07)
DeepLearningAI
Fitting Batch Norm Into Neural Networks (C2W3L05)
DeepLearningAI
Why Does Batch Norm Work? (C2W3L06)
DeepLearningAI
Batch Norm At Test Time (C2W3L07)
DeepLearningAI
Softmax Regression (C2W3L08)
DeepLearningAI
Deep Learning Frameworks (C2W3L10)
DeepLearningAI
Neural Network Overview (C1W3L01)
DeepLearningAI
Training Softmax Classifier (C2W3L09)
DeepLearningAI
Why Deep Representations? (C1W4L04)
DeepLearningAI
Gradient Descent For Neural Networks (C1W3L09)
DeepLearningAI
Neural Network Representations (C1W3L02)
DeepLearningAI
TensorFlow (C2W3L11)
DeepLearningAI
Activation Functions (C1W3L06)
DeepLearningAI
Explanation For Vectorized Implementation (C1W3L05)
DeepLearningAI
Getting Matrix Dimensions Right (C1W4L03)
DeepLearningAI
Understanding Dropout (C2W1L07)
DeepLearningAI
Building Blocks of a Deep Neural Network (C1W4L05)
DeepLearningAI
Why Non-linear Activation Functions (C1W3L07)
DeepLearningAI
Computing Neural Network Output (C1W3L03)
DeepLearningAI
Backpropagation Intuition (C1W3L10)
DeepLearningAI
Train/Dev/Test Sets (C2W1L01)
DeepLearningAI
Deep L-Layer Neural Network (C1W4L01)
DeepLearningAI
Random Initialization (C1W3L11)
DeepLearningAI
Other Regularization Methods (C2W1L08)
DeepLearningAI
Normalizing Inputs (C2W1L09)
DeepLearningAI
Derivatives Of Activation Functions (C1W3L08)
DeepLearningAI
Parameters vs Hyperparameters (C1W4L07)
DeepLearningAI
Vectorizing Across Multiple Examples (C1W3L04)
DeepLearningAI
What does this have to do with the brain? (C1W4L08)
DeepLearningAI
Dropout Regularization (C2W1L06)
DeepLearningAI
Vanishing/Exploding Gradients (C2W1L10)
DeepLearningAI
Basic Recipe for Machine Learning (C2W1L03)
DeepLearningAI
Bias/Variance (C2W1L02)
DeepLearningAI
Forward Propagation in a Deep Network (C1W4L02)
DeepLearningAI
Weight Initialization in a Deep Network (C2W1L11)
DeepLearningAI
Numerical Approximations of Gradients (C2W1L12)
DeepLearningAI
Regularization (C2W1L04)
DeepLearningAI
Why Regularization Reduces Overfitting (C2W1L05)
DeepLearningAI
More on: ML Maths Basics
View skill →Related Reads
📰
📰
📰
📰
100 PYTHON INTERVIEW QUESTIONS & ANSWERS
Medium · Programming
GossipGraD: Scalable Deep Learning using Gossip Communication based AsynchronousGradient Descent
Dev.to AI
9 Python Insights Every ML Engineer Gains Over Time
Medium · AI
9 Python Insights Every ML Engineer Gains Over Time
Medium · Data Science
🎓
Tutor Explanation
DeepCamp AI