首页 > 其他 > 详细

cs224n - Vanishing Gradients and Fancy RNNs

时间:2019-04-07 18:08:27      阅读:154      评论:0      收藏:0      [点我收藏+]

Vanishing Gradients and Fancy RNNs

Vanishing gradient problem

技术分享图片

Why is vanishing gradient a problem?

技术分享图片

Another explanation: Gradient can be viewed as a measure of
the effect of the past on the future. If the gradient becomes vanishingly small over longer distances (step t to step t+n), then we can’t tell whether:

  • There’s no dependency between step t and t+n in the data
  • We have wrong parameters to capture the true dependency between t and t+n

Effect of vanishing gradient on RNN-LM


技术分享图片

Why is exploding gradient a problem?

If the gradient becomes too big, then the SGD update step
becomes too big:
\[ \theta^{\text {new}}=\theta^{\text { old }}-\alpha \nabla_{\theta} J(\theta) \]
This can cause bad updates: we take too large a step and reach
a bad parameter configuration (with large loss). In the worst case, this will result in Inf or NaN in your network (then you have to restart training from an earlier checkpoint).

Gradient clipping: solution for exploding gradient

Gradient clipping: if the norm of the gradient is greater than
some threshold, scale it down before applying SGD update

Intuition: take a step in the same direction, but a smaller step

技术分享图片

How to fix vanishing gradient problem?

The main problem is that it’s too difficult for the RNN to learn to preserve information over many timesteps. In a vanilla RNN, the hidden state is constantly being rewritten:
\[ \boldsymbol{h}^{(t)}=\sigma\left(\boldsymbol{W}_{h} \boldsymbol{h}^{(t-1)}+\boldsymbol{W}_{x} \boldsymbol{x}^{(t)}+\boldsymbol{b}\right) \]

Long Short-Term Memory (LSTM)

技术分享图片
技术分享图片

How does LSTM solve vanishing gradients?

  • The LSTM architecture makes it easier for the RNN to preserve information over many timesteps
  • LSTM doesn’t guarantee that there is no vanishing/exploding gradient, but it does provide an easier way for the model to learn long-distance dependencies

Gated Recurrent Units (GRU)

技术分享图片

LSTM vs GRU

  • The biggest difference is that GRU is quicker to compute and has fewer parameters
  • There is no conclusive evidence that one consistently performs better than the other
  • LSTM is a good default choice (especially if your data has particularly long dependencies, or you have lots of training data)
  • Rule of thumb: start with LSTM, but switch to GRU if you want something more efficient

Conclusion: Though vanishing/exploding gradients are a general
problem, RNNs are particularly unstable due to the repeated
multiplication by the same weight matrix

Bidirectional RNNs

技术分享图片

Multi-layer RNNs

技术分享图片

cs224n - Vanishing Gradients and Fancy RNNs

原文:https://www.cnblogs.com/curtisxiao/p/10666150.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!