该系列仅在原课程基础上部分知识点添加个人学习笔记,或相关推导补充等。如有错误,还请批评指教。在学习了 Andrew Ng 课程的基础上,为了更方便的查阅复习,将其整理成文字。因本人一直在学习英语,所以该系列以英文为主,同时也建议读者以英文为主,中文辅助,以便后期进阶时,为学习相关领域的学术论文做铺垫。- ZJ
转载请注明作者和出处:ZJ 微信公众号-「SelfImprovementLab」
知乎:https://zhuanlan.zhihu.com/c_147249273
CSDN:http://blog.csdn.net/junjun_zhao/article/details/79075145
1.10 vanishing/exploding gradients (梯度消失与梯度爆炸)
(字幕来源:网易云课堂)
One of the problems of training neural network, especially very deep neural networks, is data vanishing/exploding gradients. What that means is that when you’re training a very deep network, your derivatives or your slopes can sometimes get either very very big or very very small, maybe even exponentially small, and this makes training difficult. In this video, you see what this problem of exploding or vanishing gradients really means, as well as how you can use careful choices of the random weight initialization to significantly reduce this problem.
训练神经网络尤其是深度神经网络所面临的一个问题是,梯度消失或梯度爆炸,也就是说 当你训练深度网络时,导数或坡度有时会变得非常大,或非常小 甚至以指数方式变小, 这加大了训练的难度,这节课 你将会了解梯度消失或爆炸问题的真正含义,以及如何更明智地选择随机初始化权重,从而避免这个问题。
Let’s say you’re training a very deep neural network like this, to save space on the slide, I’ve drawn it as if you have only two hidden units per layer, but it could be more as well. But this neural network will have parameters
假设你正在训练这样一个极深的神经网络,为了节约幻灯片上的空间,我画的神经网络每层只有两个隐藏单元,但它可能含有更多,但这个神经网络会有参数
Now, let’s say that each of you weight matrices
假设每个权重矩阵
Now, conversely, if we replace this with 0.5 , so something less than 1, then this becomes 0.5 to the power of L. This matrix becomes 0.5 to the L minus one times X, again ignoring
相反地 如果权重是 0.5 ,它比 1 小,这项也就变成了
So the intuition I hope you can take away from this is that at the weights W, if they’re all, you know, just a little bit bigger than 1 or just a little bit bigger than the identity matrix, then with a very deep network, the activations can explode. And if W is you know just a little bit less than identity. So this maybe here’s 0.9, 0.9, then you have a very deep network, the activations will decrease exponentially. And even though I went through this argument in terms of activations increasing or decreasing exponentially as a function of L, a similar argument can be used to show that the derivatives or the gradients the computer is going to send will also increase exponentially or decrease exponentially as a function of the number of layers. With some of the modern neural networks, let’s say if L equals 150. Microsoft recently got great results with 152 layer neural network. But with such a deep neural network, if your activations or gradients increase or decrease exponentially as a function of L, then these values could get really big or really small. And this makes training difficult, especially if your gradients are exponentially smaller than L, then gradient descent will take tiny little steps. It will take a long time for gradient descent to learn anything.
我希望你得到的直观理解是,权重 W 只比 1 略大一点,或者说只比单位矩阵大一点,深度神经网络的**函数将爆炸式增长,如果 W 比 1 略小一点,可能是 0.9,0.9,在深度神经网络中,**函数将以指数级递减,虽然我只是论述了对 L 函数的**函数,以指数级增长或下降,它也适用于与层数 L 相关的导数或梯度函数,也是呈指数增长,或呈指数递减,对于当前的神经网络 假设 L=150,最近 Microsoft 对 152 层神经网络的研究取得了很大进展,在这样一个深度神经网络中,如果作为 L 的函数的**函数或梯度函数以指数级增长或递减,它们的值将会变得极大或极大,从而导致训练难度上升,尤其是梯度与 L 相差指数级,梯度下降算法的步长会非常非常小,梯度下降算法将花费很长时间来学习。
To summarize, you’ve seen how deep networks suffer from the problems of vanishing or exploding gradients. In fact, for a long time this problem was a huge barrier to training deep neural networks. It turns out there’s a partial solution that doesn’t completely solve this problem, but that helps a lot which is careful choice of how you initialize the weights. To see that, let’s go to the next video.
总结一下,今天我们讲了深度神经网络是如何产生梯度消失或爆炸问题的,实际上 在很长一段时间内 它曾是训练深度神经网络的阻力,虽然有一个不能彻底解决此问题的解决方案,但是已在如何选择初始化权重问题上提供了很多帮助,我们下节课继续讲。
重点总结:
梯度消失与梯度爆炸
如下图所示的神经网络结构,以两个输入为例:
这里我们首先假定
-
W[l] 的值大于1的情况:如:
W[l]=[1.50 01.5] ,那么最终,y^=W[L][1.5 001.5]L−1X ,**函数的值将以指数级递增; -
W[l] 的值小于1的情况:如:
W[l]=[0.50 00.5] ,那么最终,y^=W[L][0.5 000.5]L−1X ,**函数的值将以指数级递减。
上面的情况对于导数也是同样的道理,所以在计算梯度时,根据情况的不同,梯度函数会以指数级递增或者递减,导致训练导数难度上升,梯度下降算法的步长会变得非常非常小,需要训练的时间将会非常长。
在梯度函数上出现的以指数级递增或者递减的情况就分别称为梯度爆炸或者梯度消失。
参考文献:
[1]. 大树先生.吴恩达Coursera深度学习课程 DeepLearning.ai 提炼笔记(2-1)– 深度学习的实践方面
PS: 欢迎扫码关注公众号:「SelfImprovementLab」!专注「深度学习」,「机器学习」,「人工智能」。以及 「早起」,「阅读」,「运动」,「英语 」「其他」不定期建群 打卡互助活动。