深度学习笔记之循环神经网络——GRU的反向传播过程
引言
上一节介绍了门控循环单元 ( Gate Recurrent Unit,GRU ) (\text{Gate Recurrent Unit,GRU}) (Gate Recurrent Unit,GRU),本节我们参照 LSTM \text{LSTM} LSTM反向传播的格式,观察 GRU \text{GRU} GRU的反向传播过程。
回顾: GRU \text{GRU} GRU的前馈计算过程

GRU \text{GRU} GRU的前馈计算过程表示如下:
为了后续的反向传播过程,将过程分解的细致一些。其中 Z ~ ( t ) , r ~ ( t ) \widetilde{\mathcal Z}^{(t)},\widetilde{r}^{(t)} Z
(t),r
(t)分别表示更新门、重置门的线性计算过程。
{ Z ~ ( t ) = W H ⇒ Z ⋅ h ( t − 1 ) + W X ⇒ Z ⋅ x ( t ) + b Z Z ( t ) = σ ( Z ~ ( t ) ) r ~ ( t ) = W H ⇒ r ⋅ h ( t − 1 ) + W X ⇒ r ⋅ x ( t ) + b r r ( t ) = σ ( r ~ ( t ) ) h ~ ( t ) = Tanh [ W H ⇒ H ~ ⋅ ( r ( t ) ∗ h ( t − 1 ) ) + W X ⇒ H ~ ⋅ x ( t ) + b H ~ ] h ( t ) = ( 1 − Z ( t ) ) ∗ h ( t − 1 ) + Z ( t ) ∗ h ~ ( t ) \begin{cases} \begin{aligned} & \widetilde{\mathcal Z}^{(t)} = \mathcal W_{\mathcal H \Rightarrow \mathcal Z} \cdot h^{(t-1)} + \mathcal W_{\mathcal X \Rightarrow \mathcal Z} \cdot x^{(t)} + b_{\mathcal Z} \\ & \mathcal Z^{(t)} = \sigma(\widetilde{\mathcal Z}^{(t)}) \\ & \widetilde{r}^{(t)} = \mathcal W_{\mathcal H \Rightarrow r} \cdot h^{(t-1)} + \mathcal W_{\mathcal X \Rightarrow r} \cdot x^{(t)} + b_{r} \\ & r^{(t)} = \sigma(\widetilde{r}^{(t)}) \\ & \widetilde{h}^{(t)} = \text{Tanh} \left[\mathcal W_{\mathcal H \Rightarrow \widetilde{\mathcal H}} \cdot (r^{(t)} * h^{(t-1)}) + \mathcal W_{\mathcal X \Rightarrow \widetilde{\mathcal H}} \cdot x^{(t)} + b_{\widetilde{\mathcal H}}\right] \\ & h^{(t)} = (1 -\mathcal Z^{(t)}) * h^{(t-1)} + \mathcal Z^{(t)} * \widetilde{h}^{(t)} \end{aligned} \end{cases} ⎩
⎨
⎧Z
(t)=WH⇒Z⋅h(t−1)+WX⇒Z⋅x(t)+bZZ(t)=σ(Z
(t))r
(t)=WH⇒r⋅h(t−1)+WX⇒r⋅x(t)+brr(t)=σ(r
(t))h
(t)=Tanh[WH⇒H
⋅(r(t)∗h(t−1))+WX⇒H
⋅x(t)+bH
]h(t)=(1−Z(t))∗h(t−1)+Z(t)∗h
(t)
场景设计
上述仅描述的是 GRU \text{GRU} GRU关于序列信息 h ( t ) ( t = 1 , 2 , ⋯ , T ) h^{(t)}(t=1,2,\cdots,\mathcal T) h(t)(t=1,2,⋯,T)的迭代过程。各时刻的输出特征以及损失函数于循环神经网络相同:
- 使用 Softmax \text{Softmax} Softmax激活函数,其输出结果作为模型对 t t t时刻的预测结果:
{ C ( t ) = W H ⇒ C ⋅ h ( t ) + b h y ^ ( t ) = Softmax ( C ( t ) ) \begin{cases} \mathcal C^{(t)} = \mathcal W_{\mathcal H \Rightarrow \mathcal C} \cdot h^{(t)} + b_{h} \\ \hat y^{(t)} = \text{Softmax}(\mathcal C^{(t)}) \end{cases} { C(t)=WH⇒C⋅h(t)+bhy^(t)=Softmax(C(t)) - 关于 t t t时刻预测结果 y ^ ( t ) \hat y^{(t)} y^(t)与真实分布 y ( t ) y^{(t)} y(t)之间的偏差信息使用交叉熵 ( CrossEntropy ) (\text{CrossEntropy}) (CrossEntropy)进行表示:
其中n Y n_{\mathcal Y} nY表示预测/真实分布的维数。
L ( t ) = L [ y ^ ( t ) , y ( t ) ] = − ∑ j = 1 n Y y j ( t ) log [ y ^ j ( t ) ] \mathcal L^{(t)} = \mathcal L \left[\hat y^{(t)},y^{(t)}\right] = - \sum_{j=1}^{n_\mathcal Y} y_j^{(t)} \log \left[\hat y_j^{(t)}\right] L(t)=L[y^(t),y(t)]=−j=1∑nYyj(t)log[y^j(t)] - 所有时刻交叉熵结果的累加和构成完整的损失函数 L \mathcal L L:
L = ∑ t = 1 T L ( t ) = ∑ t = 1 T L [ y ^ ( t ) , y ( t ) ] \begin{aligned} \mathcal L & = \sum_{t=1}^{\mathcal T} \mathcal L^{(t)}\\ & = \sum_{t=1}^{\mathcal T} \mathcal L \left[\hat y^{(t)},y^{(t)}\right] \end{aligned} L=t=1∑TL(t)=t=1∑TL[y^(t),y(t)]
反向传播过程
T \mathcal T T时刻的反向传播过程
以 T \mathcal T T时刻重置门 ∂ L ∂ W h ( T ) ⇒ Z ( T ) \begin{aligned}\frac{\partial \mathcal L}{\partial \mathcal W_{\mathcal h^{(\mathcal T)} \Rightarrow \mathcal Z^{(\mathcal T)}}}\end{aligned} ∂Wh(T)⇒Z(T)∂L的反向传播为例:
- 计算梯度 ∂ L ∂ L ( T ) \begin{aligned}\frac{\partial \mathcal L}{\partial \mathcal L^{(\mathcal T)}}\end{aligned} ∂L(T)∂L:
其中仅有L ( T ) \mathcal L^{(\mathcal T)} L(T)一项存在梯度,其余项均视作常数。
∂ L ∂ L ( T ) = ∂ ∂ L ( T ) [ ∑ t = 1 T L ( t ) ] = 0 + 0 + ⋯ + 1 = 1 \frac{\partial \mathcal L}{\partial \mathcal L^{(\mathcal T)}} = \frac{\partial}{\partial \mathcal L^{(\mathcal T)}} \left[\sum_{t=1}^{\mathcal T} \mathcal L^{(t)}\right] = 0 + 0 + \cdots + 1 = 1 ∂L(T)∂L=∂L(T)∂[t=1∑TL(t)]=0+0+⋯+1=1 - 计算梯度 ∂ L ( T ) ∂ C ( T ) \begin{aligned}\frac{\partial \mathcal L^{(\mathcal T)}}{\partial \mathcal C^{(\mathcal T)}}\end{aligned} ∂C(T)∂L(T):
关于Softmax \text{Softmax} Softmax激活函数与交叉熵组合的梯度描述,见循环神经网络—— Softmax \text{Softmax} Softmax函数的反向传播过程一节,这里不再赘述。
{ L ( T ) = − ∑ j = 1 n Y y j ( T ) log [ y ^ j ( T ) ] y ^ ( T ) = Softmax [ C ( T ) ] ⇒ ∂ L ( T ) ∂ C ( T ) = y ^ ( T ) − y ( T ) \begin{aligned} & \begin{cases} \mathcal L^{(\mathcal T)} = -\sum_{j=1}^{n_{\mathcal Y}}y_j^{(\mathcal T)} \log \left[\hat y_j^{(\mathcal T)}\right] \\ \hat y^{(\mathcal T)} = \text{Softmax}[\mathcal C^{(\mathcal T)}] \end{cases} \\ & \Rightarrow \frac{\partial \mathcal L^{(\mathcal T)}}{\partial \mathcal C^{(\mathcal T)}} = \hat y^{(\mathcal T)} - y^{(\mathcal T)} \end{aligned} { L(T)=−∑j=1nYyj(T)log[

本文详细介绍了GRU循环神经网络的前馈计算与反向传播过程,重点讨论了T时刻的反向传播路径,包括从T到T-1时刻的梯度传播。GRU相比于LSTM,减少了反向传播路径的数量和参数更新,降低了过拟合风险,同时利用更新门和重置门来缓解梯度消失问题。
最低0.47元/天 解锁文章
28万+

被折叠的 条评论
为什么被折叠?



