Long-Short-Term-Memories(LSTM)

1.传统RNN存在的问题

循环神经网络一文中,对前向传播、后向传播进行了仔细的推导,回顾一下,可以发现传统RNN很容易产生梯度消失、爆炸的问题。

可能公式会显得有点抽象,这里举一个例子:

那么,LSTM是如何解决这个问题的呢?

2.RNN && LSTM

如图1所示,这就是一个传统的RNN模型,激活函数用的是tanh


图1

图2与图1拥有类似的网络结构,只不过内部会更加复杂,即包括输入、忘记、输出门


图2

下面,我们来看看LSTM每一个门具体是如何运转的

3.初识LSTM

在介绍LSTM各个门之间如何运作之前,先看下LSTM网络中图标的含义,如图3所示:


图3

LSTM 通过精心设计称作为“门”的结构来去除或者增加信息到细胞状态的能力。门是一种让信息选择式通过的方法。他们包含一个 sigmoid 函数和一个 pointwise 乘法操作。


图4

下面,依据图2从左到右依次介绍:

忘记门(forget gate),利用sigmoid函数将数据转换到[0,1]区间,从而实现“忘记”。


图5

输入门(input gate)


图6

更新细胞(cell)状态


图7

输出门(output gate)


图8

至此,也完成了LSTM前向传播的介绍过程

4.LSTM变体

(1)Gers & Schmidhuber (2000)增加了 “peephole connection”。即让门层也会接受细胞状态的输入。


图9

(2)通过使用 coupled 忘记和输入门。不同于之前是分开确定什么忘记和需要添加什么新的信息,这里是同时做出决定。仅仅当将要输入在当前位置时忘记,仅仅输入新的值到那些已经忘记旧的信息的那些状态 。


图10

(3)Gated Recurrent Unit (GRU),由 Cho, et al. (2014) 提出。它将忘记门和输入门合成了一个单一的更新门。同样还混合了细胞状态和隐藏状态,和其他一些改动。最终的模型比标准的 LSTM 模型要简单(减少了一个门),也是非常流行的变体。


图10

5.换个角度看LSTM、GRU

下面把LSTM、GRU的核心部分分解开来看:

LSTM:


图11

其中:

GRU:


图12

其中:

6.前向传播、反向传播推导

下面的推导公式来自于参考文献2

定义:
- is the weight of the connection from unit i to unit j
- the network input to unit j at time t is denoted
- activation of unit j at time t is
- The subscripts , and refer respectively to the input gate, forget gate and output gate of the block
- The subscripts c refers to one of the C memory cells
- The peephole weights from cell c to the input, forget and output gates are denoted , and respectively
- is the state of cell c at time t (i.e. the activation of the linear cell unit)
- f is the activation function of the gates, and g and h are respectively the cell input and output activation functions
- Let I be the number of inputs, K be the number of outputs and H be the number of cells in the hidden layer.

前向传播:


后向传播:

推荐:一份不错的RNN(LSTM)代码:
(1)rnn-from-scratch
(2)lstm for learning

参考文献:
(1)http://colah.github.io/posts/2015-08-Understanding-LSTMs/
(2)A. Graves. Supervised Sequence Labelling with Recurrent Neural Networks. Textbook, Studies in Computational Intelligence, Springer, 2012.
(3)DeepLearning for NLP

  • 5
    点赞
  • 44
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值