GRU(Gated Recurrent Unit)
一个带门的RNN
一般RNN模型中,每个元素受其周围附近的影响较大,难以建立跨度较大的依赖性。由于跨度较大,普通的RNN模型就容易出现梯度消失,捕捉不到他们之间的依赖,造成语法错误。
其中,
a<t>的表达式为
a<t>=tanh(Wa[a<t−1>,x<t>]+ba)
这个结构的缺点是阻断了
a<t>与
a<t−1>的直接性联系,相当于少了一个记忆单元,记住
a<t−1>,这是造成梯度消失的主要原因。
因此,为了解决梯度消失问题,对上述单元进行修改,添加了记忆单元,这种结构称之为Gated Recurrent Unit(GRU)
c~<t>=tanh(Wc[c<t−1>,x<t>]+bc)Γu=σ(Wu[c<t−1>,x<t>]+bu)c<t>=Γu∗c~<t>+(1−Γu)∗c<t−1>
其中
Γu是一种Gate,记忆单元。
Γu的取值范围在[0,1]。
当
Γu=1时,代表更新,
c<t>=c~<t>;
当
Γu=0时,代表记忆,
c<t>=c<t−1>,保留之前的模块输出。
所以,根据$\Gamma_u
的值,能够让模型自己决定是选择更新还是记忆。\Gamma_u $能够保证RNN模型中跨度很大的依赖关系不受影响,消除梯度小时问题。
Long Short Term Memory(LSTM)
LSTM称之为长短期记忆模型,能够有效处理RNN模型中“长期依赖”的问题。
LSTM有3个Gate,分别是Forget Gate(遗忘门),Update Gate(输入门),Output Gate(输出门)。
x<t>是输入,
c<t−1>和
a<t−1>来自上一模块的输出。
c~<t>=tanh(Wc[a<t−1>,x<t>]+bc)Γu=σ(Wu[a<t−1>,x<t>]+bu)Γf=σ(Wf[a<t−1>,x<t>]+bf)Γo=σ(Wo[a<t−1>,x<t>]+bo)c<t>=Γu∗c~<t>+Γf∗c<t−1>a<t>=Γo∗c<t>
其中,
Γu,Γf,Γo分别表示Forget Gate、Update Gate、Output Gate因子,取值范围均在[0,1]之间。这几个范数会在RNN模型训练过程中自适应调整记忆与更新的权重因子,已取得最佳模型训练效果。
如果考虑
c<t−1>,对
Γu,Γf,Γo的影响,可对LSTM表达式进行修改
c~<t>=tanh(Wc[a<t−1>,x<t>]+bc)Γu=σ(Wu[a<t−1>,x<t>,c<t−1>]+bu)Γf=σ(Wf[a<t−1>,x<t>,c<t−1>]+bf)Γo=σ(Wo[a<t−1>,x<t>,c<t−1>]+bo)c<t>=Γu∗c~<t>+Γf∗c<t−1>a<t>=Γo∗c<t>
LSTM是RNN的一个优秀的变种模型,继承了大部分RNN模型的特征,同时解决了神经网络反向传播过程中由于逐步缩减而产生的梯度消失问题。
LSTM非常适合用于处理与时间序列高度相关的问题,例如机器翻译、对话生成、编解码等。