循环神经网络进阶
1.GRU
2.LSTM
3.Deep RNN
4.Bidirection NN
1.GRU
RNN存在的问题:梯度较容易出现衰减或爆炸(BPTT)
⻔控循环神经⽹络:捕捉时间序列中时间步距离较⼤的依赖关系
1.1数学表达式
[R_{t} = σ(X_tW_{xr} + H_{t−1}W_{hr} + b_r)\
Z_{t} = σ(X_tW_{xz} + H_{t−1}W_{hz} + b_z)\
widetilde{H}_t = tanh(X_tW_{xh} + (R_t ⊙H_{t−1})W_{hh} + b_h)\
H_t = Z_t⊙H_{t−1} + (1−Z_t)⊙widetilde{H}_t
]
1.2结构
- 重置⻔(reset gate):有助于捕捉时间序列⾥短期的依赖关系;
- 更新⻔(update gate):有助于捕捉时间序列⾥⻓期的依赖关系。
1.3实现
- 官方实现:https://pytorch.org/docs/1.3.0/nn.html#gru
- 手写实现:
2.LSTM
2.1数学表达式
[egin{split}egin{aligned} oldsymbol{I}_t &= sigma(oldsymbol{X}_t oldsymbol{W}_{xi} + oldsymbol{H}_{t-1} oldsymbol{W}_{hi} + oldsymbol{b}_i),\
oldsymbol{F}_t &= sigma(oldsymbol{X}_t oldsymbol{W}_{xf} + oldsymbol{H}_{t-1} oldsymbol{W}_{hf} + oldsymbol{b}_f),\
oldsymbol{O}_t &= sigma(oldsymbol{X}_t oldsymbol{W}_{xo} + oldsymbol{H}_{t-1} oldsymbol{W}_{ho} + oldsymbol{b}_o), end{aligned}end{split}
]
[ ilde{oldsymbol{C}}_t = ext{tanh}(oldsymbol{X}_t oldsymbol{W}_{xc} + oldsymbol{H}_{t-1} oldsymbol{W}_{hc} + oldsymbol{b}_c), \
oldsymbol{C}_t = oldsymbol{F}_t odot oldsymbol{C}_{t-1} + oldsymbol{I}_t odot ilde{oldsymbol{C}}_t, \
oldsymbol{H}_t = oldsymbol{O}_t odot ext{tanh}(oldsymbol{C}_t).
]
2.2结构
- 遗忘门((oldsymbol{F}_t)):控制上一时间步的记忆细胞
- 输入门((oldsymbol{I}_t)):控制当前时间步的输入
- 输出门((oldsymbol{O}_t)):控制从记忆细胞到隐藏状态
- 记忆细胞(候选记忆细胞——( ilde{oldsymbol{C}}_t),记忆细胞——(oldsymbol{C}_t)):⼀种特殊的隐藏状态的信息的流动
2.3实现
- 官方实现:https://pytorch.org/docs/1.3.0/nn.html#lstm
- 手写实现:
3.Deep RNN
3.1数学表达式
[oldsymbol{H}_t^{(1)} = phi(oldsymbol{X}_t oldsymbol{W}_{xh}^{(1)} + oldsymbol{H}_{t-1}^{(1)} oldsymbol{W}_{hh}^{(1)} + oldsymbol{b}_h^{(1)})\
oldsymbol{H}_t^{(ell)} = phi(oldsymbol{H}_t^{(ell-1)} oldsymbol{W}_{xh}^{(ell)} + oldsymbol{H}_{t-1}^{(ell)} oldsymbol{W}_{hh}^{(ell)} + oldsymbol{b}_h^{(ell)})\
oldsymbol{O}_t = oldsymbol{H}_t^{(L)} oldsymbol{W}_{hq} + oldsymbol{b}_q
]
3.2结构
3.3使用
4.Bidirection RNN
4.1数学表达式
[egin{aligned} overrightarrow{oldsymbol{H}}_t &= phi(oldsymbol{X}_t oldsymbol{W}_{xh}^{(f)} + overrightarrow{oldsymbol{H}}_{t-1} oldsymbol{W}_{hh}^{(f)} + oldsymbol{b}_h^{(f)})\
overleftarrow{oldsymbol{H}}_t &= phi(oldsymbol{X}_t oldsymbol{W}_{xh}^{(b)} + overleftarrow{oldsymbol{H}}_{t+1} oldsymbol{W}_{hh}^{(b)} + oldsymbol{b}_h^{(b)}) end{aligned} ]
[oldsymbol{H}_t=(overrightarrow{oldsymbol{H}}_{t}, overleftarrow{oldsymbol{H}}_t)
]
[oldsymbol{O}_t = oldsymbol{H}_t oldsymbol{W}_{hq} + oldsymbol{b}_q
]