前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >【串讲总结】RNN、LSTM、GRU、ConvLSTM、ConvGRU、ST-LSTM

【串讲总结】RNN、LSTM、GRU、ConvLSTM、ConvGRU、ST-LSTM

作者头像
千与编程
发布2023-04-28 13:37:41
9950
发布2023-04-28 13:37:41
举报
文章被收录于专栏:公众号:千与编程

前言

平时很少写总结性的文章,感觉还是需要阶段性总结一些可以串在一起的知识点,所以这次写了下。因为我写的内容主要在时序、时空预测这个方向,所以主要还是把rnn,lstm,gru,convlstm,convgru以及ST-LSTM

一、 RNN

最为原始的循环神经网络,本质就是全连接网络,只是为了考虑过去的信息,输出不仅取决于当前输入,还取决于之前的信息,也就是输出由之前的信息(也就是状态state)和此时的输入决定。

1.1 结构图

1.2 公式

h_{t}=\tanh \left(W_{h h} h_{t-1}+W_{x h} x_{t}\right)
\mathrm{y}_{\mathrm{t}}=\mathrm{W}_{\mathrm{hy}} \mathrm{h}_{\mathrm{t}}

1.3 优缺点

1.3.1 优点

① RNN 很适合处理序列数据,因为考虑了之前的信息

② 可以和CNN一起使用得到更好的任务效果

1.3.2 缺点

① 梯度消失、梯度爆炸

② rnn较其他cnn和全连接要用更多的显存空间,更难训练

③ 如果采用tanh、relu为激活函数,没法处理太长的序列

二、LSTM

为了解决梯度消失和爆炸以及更好的预测和分类序列数据等问题,rnn逐渐转变为lstm

2.1 结构图

2.2 公式

\begin{aligned} i^{(t)} &=\sigma\left(W^{(i)} x^{(t)}+U^{(i)} h^{(t-1)}\right) & & \text { (Input gate) } \\ f^{(t)} &=\sigma\left(W^{(f)} x^{(t)}+U^{(f)} h^{(t-1)}\right) & & \text { (Forget gate) } \\ o^{(t)} &=\sigma\left(W^{(o)} x^{(t)}+U^{(o)} h^{(t-1)}\right) & & \text {(Output gate) } \\ \tilde{c}^{(t)} &=\tanh \left(W^{(c)} x^{(t)}+U^{(c)} h^{(t-1)}\right) && \text { (New memory cell) } \\ c^{(t)} &=f^{(t)} \circ \mathbf{c}^{(t-1)}+i^{(t)} \circ \tilde{c}^{(t)} && \text { (Final memory cell) } \\ h^{(t)} &=o^{(t)} \circ \tanh \left(c^{(t)}\right) & & \end{aligned}

2.3 扩展

实际应用中一般不采用单层的lstm,而是多层,在很多时序数据中双向的表现也很不错

2.3.1 双向lstm

2.3.2 深层双向lstm

三、 GRU

因为LSTM的训练比较慢,而GRU在其上稍微修改,速度可以快很多,而精度基本不变,所以GRU也十分流行

3.1 结构图

3.2 公式

\begin{aligned} z^{(t)} &=\sigma\left(W^{(z)} x^{(t)}+U^{(z)} h^{(t-1)}\right) & & \text { (Update gate) } \\ r^{(t)} &=\sigma\left(W^{(r)} x^{(t)}+U^{(r)} h^{(t-1)}\right) & & \text { (Reset gate) } \\\tilde{h}^{(t)} &=\tanh \left(Wx^{(t)}+r^{(t)}\circ Uh^{(t-1)}\right) && \text { (New memory cell) } \\h^{(t)} &=(1-z^{(t)}) \circ{h}^{(t)}+z^{(t)} \circ h^{(t-1)} & & \end{aligned}

3.3 LSTM和GRU的结构区别

可以观看【Deep Learning】详细解读LSTM与GRU单元的各个公式和区别

四、 ConvLSTM和ConvGRU

为了构建时空序列预测模型,同时掌握时间和空间信息,所以将LSTM中的全连接权重改为卷积。

4.1 convLSTM结构图

4.2 convLSTM公式(原paper中)

\begin{aligned} i_{t} &=\sigma\left(W_{x i} * \mathcal{X}_{t}+W_{h i} * \mathcal{H}_{t-1}+W_{c i} \circ \mathcal{C}_{t-1}+b_{i}\right) \\ f_{t} &=\sigma\left(W_{x f} * \mathcal{X}_{t}+W_{h f} * \mathcal{H}_{t-1}+W_{c f} \circ \mathcal{C}_{t-1}+b_{f}\right) \\ \mathcal{C}_{t} &=f_{t} \circ \mathcal{C}_{t-1}+i_{t} \circ \tanh \left(W_{x c} * \mathcal{X}_{t}+W_{h c} * \mathcal{H}_{t-1}+b_{c}\right) \\ o_{t} &=\sigma\left(W_{x o} * \mathcal{X}_{t}+W_{h o} * \mathcal{H}_{t-1}+W_{c o} \circ \mathcal{C}_{t}+b_{o}\right) \\ \mathcal{H}_{t} &=o_{t} \circ \tanh \left(\mathcal{C}_{t}\right) \end{aligned}

4.3 convGRU(原paper中)

\begin{array}{l} \mathcal{Z}_{t}=\sigma\left(\mathcal{W}_{x z} * \mathcal{X}_{t}+\mathcal{W}_{h z} * \mathcal{H}_{t-1}\right) \\ \mathcal{R}_{t}=\sigma\left(\mathcal{W}_{x r} * \mathcal{X}_{t}+\mathcal{W}_{h r} * \mathcal{H}_{t-1}\right) \\ \mathcal{H}_{t}^{\prime}=f\left(\mathcal{W}_{x h} * \mathcal{X}_{t}+\mathcal{R}_{t} \circ\left(\mathcal{W}_{h h} * \mathcal{H}_{t-1}\right)\right) \\ \mathcal{H}_{t}=\left(1-\mathcal{Z}_{t}\right) \circ \mathcal{H}_{t}^{\prime}+\mathcal{Z}_{t} \circ \mathcal{H}_{t-1} \end{array}

4.4 讨论一个小问题

shixingjian博士提出的ConvLSTM通过他的描述来说应该就是其中的W也就是每个权重都从普通的全连接权重改为了卷积。所以应该从左到右转变,正常来说右处应该是不存在i,f以及o三个门只由X和Ht-1决定,而没有C。即不存在以下的结构。

这里咱们再重新看下博士的紧接着nips2016年的文章中所提到的convGRU也是不存在C的,并且可以和gru公式一一对应。

这里我不知道是博士当时就是这么实现的并且效果很好,还是说有无C对三个门的影响对最终的实验结果没有太大的影响,还是说确实是写作失误,这里我不太好给出结论。这里可以断定的是轨迹GRU那篇文章中对于结构完全是从GRU转变为convGRU的这里绝对没问题。我也因此查了几篇期刊和顶会。

摘自ECCV2018

摘自IEEE Trans

之后我又调查了一些文章,很巧妙,顶会基本上都是没有c的形式,而期刊大多都有。这里我做了另外一个调查,github上的实现,大多数都是从LSTM直接转变为的Convlstm的写法也就是不存在C影响三个门,因为我当时复现的时候也是先实现了LSTM,之后加以改为ConvLSTM所以说没太注意,我这回自己也做了下这个实验,没有加上的结构可以很好的作时空预测,反而加上c之后会出现梯度的问题,所以这里大家可以有一些自我的理解。

我个人还是推荐直接从LSTM转变为convLSTM的结构,这个稍后如何编写代码我也会逐步写文章讲解。

五、 ST-LSTM

这里主要给出 ST-LSTM结构及公式。

5.1 ST-LSTM结构图

5.2 ST-LSTM公式

\begin{array}{l} g_{t}=\tanh \left(\mathcal{W}_{x g} * \mathcal{X}_{t}+\mathcal{W}_{h g} * \mathcal{H}_{t-1}^{l}+b_{g}\right) \\ i_{t}=\sigma\left(\mathcal{W}_{x i} * \mathcal{X}_{t}+\mathcal{W}_{h i} * \mathcal{H}_{t-1}^{l}+b_{i}\right) \\ f_{t}=\sigma\left(\mathcal{W}_{x f} * \mathcal{X}_{t}+\mathcal{W}_{h f} * \mathcal{H}_{t-1}^{l}+b_{f}\right) \\ \mathcal{C}_{t}^{l}=f_{t} \odot \mathcal{C}_{t-1}^{l}+i_{t} \odot g_{t} \\ g_{t}^{\prime}=\tanh \left(\mathcal{W}_{x g}^{\prime} * \mathcal{X}_{t}+\mathcal{W}_{m g} * \mathcal{M}_{t}^{l-1}+b_{g}^{\prime}\right) \\ i_{t}^{\prime}=\sigma\left(\mathcal{W}_{x i}^{\prime} * \mathcal{X}_{t}+\mathcal{W}_{m i} * \mathcal{M}_{t}^{l-1}+b_{i}^{\prime}\right) \\ f_{t}^{\prime}=\sigma\left(\mathcal{W}_{x f}^{\prime} * \mathcal{X}_{t}+\mathcal{W}_{m f} * \mathcal{M}_{t}^{l-1}+b_{f}^{\prime}\right) \\ \mathcal{M}_{t}^{l}=f_{t}^{\prime} \odot \mathcal{M}_{t}^{l-1}+i_{t}^{\prime} \odot g_{t}^{\prime} \\ o_{t}=\sigma\left(\mathcal{W}_{x o} * \mathcal{X}_{t}+\mathcal{W}_{h o} * \mathcal{H}_{t-1}^{l}+\mathcal{W}_{c o} * \mathcal{C}_{t}^{l}+\mathcal{W}_{m o} * \mathcal{M}_{t}^{l}+b_{o}\right) \\ \mathcal{H}_{t}^{l}=o_{t} \odot \tanh \left(\mathcal{W}_{1 \times 1} *\left[\mathcal{C}_{t}^{l}, \mathcal{M}_{t}^{l}\right]\right) \end{array}

5.3 stacking结构

这个模型的复现和编写我会在不久之后专门写一篇文章来讲,并且因为是这种直接stacking的结构会有一些训练的trick,比如Scheduled Sampling等。

Reference

  • https://towardsdatascience.com/understanding-rnn-and-lstm-f7cdf6dfc14e
  • http://www.wildml.com/2015/09/recurrent-neural-networks-tutorial-part-1-introduction-to-rnns/
  • https://towardsdatascience.com/illustrated-guide-to-lstms-and-gru-s-a-step-by-step-explanation-44e9eb85bf21
  • https://medium.com/neuronio/an-introduction-to-convlstm-55c9025563a7
本文参与 腾讯云自媒体同步曝光计划,分享自微信公众号。
原始发表:2020-06-14,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 千与编程 微信公众号,前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体同步曝光计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
目录
  • 前言
  • 一、 RNN
    • 1.1 结构图
      • 1.2 公式
        • 1.3 优缺点
          • 1.3.1 优点
          • 1.3.2 缺点
      • 二、LSTM
        • 2.1 结构图
          • 2.2 公式
            • 2.3 扩展
              • 2.3.1 双向lstm
              • 2.3.2 深层双向lstm
          • 三、 GRU
            • 3.1 结构图
              • 3.2 公式
                • 3.3 LSTM和GRU的结构区别
                • 四、 ConvLSTM和ConvGRU
                  • 4.1 convLSTM结构图
                    • 4.2 convLSTM公式(原paper中)
                      • 4.3 convGRU(原paper中)
                        • 4.4 讨论一个小问题
                        • 五、 ST-LSTM
                          • 5.1 ST-LSTM结构图
                            • 5.2 ST-LSTM公式
                              • 5.3 stacking结构
                              • Reference
                              领券
                              问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档