深度学习笔记之循环神经网络(九)GRU的反向传播过程

news2024/10/7 18:23:43

引言

上一节介绍了门控循环单元 ( 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算法展开图
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)=WHZh(t1)+WXZx(t)+bZZ(t)=σ(Z (t))r (t)=WHrh(t1)+WXrx(t)+brr(t)=σ(r (t))h (t)=Tanh[WHH (r(t)h(t1))+WXH x(t)+bH ]h(t)=(1Z(t))h(t1)+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)=WHCh(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=1nYyj(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=1TL(t)=t=1TL[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=1TL(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[y^j(T)]y^(T)=Softmax[C(T)]C(T)L(T)=y^(T)y(T)
  • 继续计算梯度 ∂ C ( T ) ∂ h ( T ) \begin{aligned}\frac{\partial \mathcal C^{(\mathcal T)}}{\partial h^{(\mathcal T)}}\end{aligned} h(T)C(T)
    ∂ C ( T ) ∂ h ( T ) = ∂ ∂ h ( T ) [ W H ⇒ C ⋅ h ( T ) + b h ] = W H ⇒ C \frac{\partial \mathcal C^{(\mathcal T)}}{\partial h^{(\mathcal T)}} = \frac{\partial}{\partial h^{(\mathcal T)}} \left[\mathcal W_{\mathcal H \Rightarrow \mathcal C} \cdot h^{(\mathcal T)} + b_{h}\right] = \mathcal W_{\mathcal H \Rightarrow \mathcal C} h(T)C(T)=h(T)[WHCh(T)+bh]=WHC

至此,关于梯度 ∂ L ∂ h ( T ) \begin{aligned}\frac{\partial \mathcal L}{\partial h^{(\mathcal T)}}\end{aligned} h(T)L可表示为:
∂ L ∂ h ( T ) = ∂ L ∂ L ( T ) ⋅ ∂ L ( T ) ∂ C ( T ) ⋅ ∂ C ( T ) ∂ h ( T ) = 1 ⋅ [ W H ⇒ C ] T ⋅ ( y ^ ( T ) − y ( T ) ) \begin{aligned} \frac{\partial \mathcal L}{\partial h^{(\mathcal T)}} & = \frac{\partial \mathcal L}{\partial \mathcal L^{(\mathcal T)}} \cdot \frac{\partial \mathcal L^{(\mathcal T)}}{\partial \mathcal C^{(\mathcal T)}} \cdot \frac{\partial \mathcal C^{(\mathcal T)}}{\partial h^{(\mathcal T)}} \\ & = 1 \cdot \left[\mathcal W_{\mathcal H \Rightarrow \mathcal C}\right]^T \cdot (\hat y^{(\mathcal T)} - y^{(\mathcal T)}) \end{aligned} h(T)L=L(T)LC(T)L(T)h(T)C(T)=1[WHC]T(y^(T)y(T))
观察:从 h ( T ) h^{(\mathcal T)} h(T)开始,从 h ( T ) ⇒ W h ( T ) ⇒ Z ( T ) h^{(\mathcal T)} \Rightarrow \mathcal W_{h^{(\mathcal T)} \Rightarrow \mathcal Z^{(\mathcal T)}} h(T)Wh(T)Z(T)传播路径都有哪些。
只有唯一一条,其前馈计算路径表示为:
{ h ( t ) = ( 1 − Z ( t ) ) ∗ h ( t − 1 ) + Z ( t ) ∗ h ~ ( t ) Z ( t ) = σ ( Z ~ ( t ) ) Z ~ ( t ) = W H ⇒ Z ⋅ h ( t − 1 ) + W X ⇒ Z ⋅ x ( t ) + b Z \begin{cases} \begin{aligned} & h^{(t)} = (1 -\mathcal Z^{(t)}) * h^{(t-1)} + \mathcal Z^{(t)} * \widetilde{h}^{(t)} \\ & \mathcal Z^{(t)} = \sigma(\widetilde{\mathcal Z}^{(t)}) \\ & \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} \end{aligned} \end{cases} h(t)=(1Z(t))h(t1)+Z(t)h (t)Z(t)=σ(Z (t))Z (t)=WHZh(t1)+WXZx(t)+bZ
对应反向传播结果表示为:
∂ h ( T ) ∂ W h ( T ) ⇒ Z ( T ) = ∂ h ( T ) ∂ Z ( T ) ⋅ ∂ Z ( T ) ∂ Z ~ ( T ) ⋅ ∂ Z ~ ( T ) ∂ W h ( T ) ⇒ Z ( T ) = [ h ~ ( T ) − h ( T − 1 ) ] ⋅ [ Sigmoid ( Z ~ ( T ) ) ] ′ ⋅ h ( T − 1 ) \begin{aligned} \frac{\partial h^{(\mathcal T)}}{\partial \mathcal W_{h^{(\mathcal T)} \Rightarrow \mathcal Z^{(\mathcal T)}}} & = \frac{\partial h^{(\mathcal T)}}{\partial \mathcal Z^{(\mathcal T)}} \cdot \frac{\partial \mathcal Z^{(\mathcal T)}}{\partial \widetilde{\mathcal Z}^{(\mathcal T)}} \cdot \frac{\partial \widetilde{\mathcal Z}^{(\mathcal T)}}{\partial \mathcal W_{h^{(\mathcal T)} \Rightarrow \mathcal Z^{(\mathcal T)}}} \\ & = \left[\widetilde{h}^{(\mathcal T)} - h^{(\mathcal T - 1)}\right] \cdot \left[\text{Sigmoid}(\widetilde{\mathcal Z}^{(\mathcal T)})\right]' \cdot h^{(\mathcal T - 1)} \end{aligned} Wh(T)Z(T)h(T)=Z(T)h(T)Z (T)Z(T)Wh(T)Z(T)Z (T)=[h (T)h(T1)][Sigmoid(Z (T))]h(T1)
最终,关于 ∂ 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 ∂ W h ( T ) ⇒ Z ( T ) = ∂ L ∂ h ( T ) ⋅ ∂ h ( T ) ∂ W h ( T ) ⇒ Z ( T ) = { [ W H ⇒ C ] T ⋅ ( y ^ ( T ) − y ( T ) ) } ⋅ { [ h ~ ( T ) − h ( T − 1 ) ] ⋅ [ Sigmoid ( Z ~ ( T ) ) ] ′ ⋅ h ( T − 1 ) } \begin{aligned} \begin{aligned}\frac{\partial \mathcal L}{\partial \mathcal W_{\mathcal h^{(\mathcal T)} \Rightarrow \mathcal Z^{(\mathcal T)}}}\end{aligned} & = \frac{\partial \mathcal L}{\partial h^{(\mathcal T)}} \cdot \frac{\partial h^{(\mathcal T)}}{\partial \mathcal W_{h^{(\mathcal T)}\Rightarrow \mathcal Z^{(\mathcal T)}}} \\ & = \left\{\left[\mathcal W_{\mathcal H \Rightarrow \mathcal C}\right]^T \cdot (\hat y^{(\mathcal T)} - y^{(\mathcal T)})\right\} \cdot \left\{ \left[\widetilde{h}^{(\mathcal T)} - h^{(\mathcal T - 1)}\right] \cdot \left[\text{Sigmoid}(\widetilde{\mathcal Z}^{(\mathcal T)})\right]' \cdot h^{(\mathcal T - 1)}\right\} \end{aligned} Wh(T)Z(T)L=h(T)LWh(T)Z(T)h(T)={[WHC]T(y^(T)y(T))}{[h (T)h(T1)][Sigmoid(Z (T))]h(T1)}

T − 1 \mathcal T - 1 T1时刻的反向传播路径

关于 T − 1 \mathcal T - 1 T1时刻的重置门梯度 ∂ L ∂ W h ( T − 1 ) ⇒ Z ( T − 1 ) \begin{aligned} \frac{\partial \mathcal L}{\partial \mathcal W_{h^{(\mathcal T - 1)} \Rightarrow \mathcal Z^{(\mathcal T - 1)}}} \end{aligned} Wh(T1)Z(T1)L,它的路径主要包含两大类

第一类路径:同 T \mathcal T T时刻路径,从对应的 L ( T − 1 ) \mathcal L^{(\mathcal T - 1)} L(T1)直接传至 W h ( T − 1 ) ⇒ Z ( T − 1 ) \mathcal W_{h^{(\mathcal T - 1)}\Rightarrow \mathcal Z^{(\mathcal T - 1)}} Wh(T1)Z(T1)
该路径与上述 T \mathcal T T时刻的路径类型相同,将对应的上标 T \mathcal T T改为 T − 1 \mathcal T - 1 T1即可。
∂ L ( T − 1 ) ∂ W h ( T − 1 ) ⇒ Z ( T − 1 ) = ∂ L ( T − 1 ) ∂ h ( T − 1 ) ⋅ ∂ h ( T − 1 ) ∂ W h ( T − 1 ) ⇒ Z ( T − 1 ) \begin{aligned} \frac{\partial \mathcal L^{(\mathcal T - 1)}}{\partial \mathcal W_{h^{(\mathcal T - 1)} \Rightarrow \mathcal Z^{(\mathcal T - 1)}}} & = \frac{\partial \mathcal L^{(\mathcal T - 1)}}{\partial h^{(\mathcal T - 1)}} \cdot \frac{\partial h^{(\mathcal T - 1)}}{\partial \mathcal W_{h^{(\mathcal T - 1)} \Rightarrow \mathcal Z^{(\mathcal T - 1)}}} \end{aligned} Wh(T1)Z(T1)L(T1)=h(T1)L(T1)Wh(T1)Z(T1)h(T1)
第二类路径:重新观察 W h ( T − 1 ) ⇒ Z ( T − 1 ) \mathcal W_{h^{(\mathcal T - 1)}\Rightarrow \mathcal Z^{(\mathcal T - 1)}} Wh(T1)Z(T1)只会出现在 Z ( T − 1 ) \mathcal Z^{(\mathcal T - 1)} Z(T1)中,并且 Z ( T − 1 ) \mathcal Z^{(\mathcal T - 1)} Z(T1)只会出现在 h ( T − 1 ) h^{(\mathcal T - 1)} h(T1)中。因此:仅需要找出与 h ( T − 1 ) h^{(\mathcal T - 1)} h(T1)相关的所有路径即可,最终都可以使用 ∂ h ( T − 1 ) ∂ W h ( T − 1 ) ⇒ Z ( T − 1 ) \begin{aligned}\frac{\partial h^{(\mathcal T - 1)}}{\partial \mathcal W_{h^{(\mathcal T - 1)} \Rightarrow \mathcal Z^{(\mathcal T - 1)}}}\end{aligned} Wh(T1)Z(T1)h(T1)将梯度传递给 W h ( T − 1 ) ⇒ Z ( T − 1 ) \mathcal W_{h^{(\mathcal T - 1)} \Rightarrow \mathcal Z^{(\mathcal T - 1)}} Wh(T1)Z(T1)
其中‘第一类路径’就是其中一种情况。只不过它是从当前 T − 1 \mathcal T - 1 T1时刻直接传递得到的梯度结果。而第二类路径我们关注从 T \mathcal T T时刻传递产生的梯度信息。
T ⇒ T − 1 \mathcal T \Rightarrow \mathcal T - 1 TT1时刻中,关于 h ( T − 1 ) h^{(\mathcal T - 1)} h(T1)的梯度路径一共包含 4 4 4条:

  • 第一条:通过 T \mathcal T T时刻 h ( T ) h^{(\mathcal T)} h(T)中的 h ( T − 1 ) h^{(\mathcal T - 1)} h(T1)进行传递。
    { Forword :  h ( T ) = ( 1 − Z ( T ) ) ∗ h ( T − 1 ) + Z ( T ) ∗ h ~ ( T ) Backward :  ∂ L ( T ) ∂ W h ( T − 1 ) ⇒ Z ( T − 1 ) ⇒ ∂ L ( T ) ∂ h ( T ) ⋅ ∂ h ( T ) ∂ h ( T − 1 ) ⋅ ∂ h ( T − 1 ) ∂ W h ( T − 1 ) ⇒ Z ( T − 1 ) \begin{cases} \text{Forword : } h^{(\mathcal T)} = (1 -\mathcal Z^{(\mathcal T)}) * h^{(\mathcal T -1)} + \mathcal Z^{(\mathcal T)} * \widetilde{h}^{(\mathcal T)} \\ \quad \\ \text{Backward : }\begin{aligned} \frac{\partial \mathcal L^{(\mathcal T)}}{\partial \mathcal W_{h^{(\mathcal T - 1)} \Rightarrow \mathcal Z^{(\mathcal T - 1)}}} \Rightarrow \frac{\partial \mathcal L^{(\mathcal T)}}{\partial h^{(\mathcal T)}} \cdot \frac{\partial h^{(\mathcal T)}}{\partial h^{(\mathcal T - 1)}} \cdot \frac{\partial h^{(\mathcal T - 1)}}{\partial \mathcal W_{h^{(\mathcal T - 1)} \Rightarrow \mathcal Z^{(\mathcal T - 1)}}} \end{aligned} \end{cases} Forword : h(T)=(1Z(T))h(T1)+Z(T)h (T)Backward : Wh(T1)Z(T1)L(T)h(T)L(T)h(T1)h(T)Wh(T1)Z(T1)h(T1)
  • 第二条:通过 T \mathcal T T时刻 h ( T ) h^{(\mathcal T)} h(T)中的 Z ( T ) \mathcal Z^{(\mathcal T)} Z(T) h ( T − 1 ) h^{(\mathcal T-1)} h(T1)进行传递。
    { Forward :  { h ( T ) = ( 1 − Z ( T ) ) ∗ h ( T − 1 ) + Z ( T ) ∗ h ~ ( T ) Z ( T ) = σ [ W H ⇒ Z ⋅ h ( T − 1 ) + W X ⇒ Z ⋅ x ( T ) + b Z ] Backward :  ∂ L ( T ) ∂ W h ( T − 1 ) ⇒ Z ( T − 1 ) ⇒ ∂ L ( T ) ∂ h ( T ) ⋅ ∂ h ( T ) ∂ Z ( T ) ⋅ ∂ Z ( T ) ∂ h ( T − 1 ) ⋅ ∂ h ( T − 1 ) ∂ W h ( T − 1 ) ⇒ Z ( T − 1 ) \begin{cases} \text{Forward : } \begin{cases} h^{(\mathcal T)} = (1 -\mathcal Z^{(\mathcal T)}) * h^{(\mathcal T -1)} + \mathcal Z^{(\mathcal T)} * \widetilde{h}^{(\mathcal T)} \\ \mathcal Z^{(\mathcal T)} = \sigma \left[\mathcal W_{\mathcal H \Rightarrow \mathcal Z} \cdot h^{(\mathcal T -1)} + \mathcal W_{\mathcal X \Rightarrow \mathcal Z} \cdot x^{(\mathcal T)} + b_{\mathcal Z}\right] \end{cases} \quad \\ \text{Backward : } \begin{aligned} \frac{\partial \mathcal L^{(\mathcal T)}}{\partial \mathcal W_{h^{(\mathcal T - 1)} \Rightarrow \mathcal Z^{(\mathcal T - 1)}}} \Rightarrow \frac{\partial \mathcal L^{(\mathcal T)}}{\partial h^{(\mathcal T)}} \cdot \frac{\partial h^{(\mathcal T)}}{\partial \mathcal Z^{(\mathcal T)}} \cdot \frac{\partial \mathcal Z^{(\mathcal T)}}{\partial h^{(\mathcal T - 1)}} \cdot \frac{\partial h^{(\mathcal T - 1)}}{\partial \mathcal W_{h^{(\mathcal T - 1)} \Rightarrow \mathcal Z^{(\mathcal T - 1)}}} \end{aligned} \end{cases} Forward : {h(T)=(1Z(T))h(T1)+Z(T)h (T)Z(T)=σ[WHZh(T1)+WXZx(T)+bZ]Backward : Wh(T1)Z(T1)L(T)h(T)L(T)Z(T)h(T)h(T1)Z(T)Wh(T1)Z(T1)h(T1)
  • 第三条:通过 T \mathcal T T时刻 h ( T ) h^{(\mathcal T)} h(T)中的 h ~ ( T ) \widetilde{h}^{(\mathcal T)} h (T) h ( T − 1 ) h^{(\mathcal T - 1)} h(T1)进行传递。
    { Forward :  { h ( T ) = ( 1 − Z ( T ) ) ∗ h ( T − 1 ) + Z ( T ) ∗ h ~ ( T ) h ~ ( T ) = Tanh [ W H ⇒ H ~ ⋅ ( r ( T ) ∗ h ( T − 1 ) ) + W X ⇒ H ~ ⋅ x ( T ) + b H ~ ] Backward :  ∂ L ( T ) ∂ W h ( T − 1 ) ⇒ Z ( T − 1 ) ⇒ ∂ L ( T ) ∂ h ( T ) ⋅ ∂ h ( T ) ∂ h ~ ( T ) ⋅ h ~ ( T ) ∂ h ( T − 1 ) ⋅ ∂ h ( T − 1 ) ∂ W h ( T − 1 ) ⇒ Z ( T − 1 ) \begin{cases} \text{Forward : } \begin{cases} h^{(\mathcal T)} = (1 -\mathcal Z^{(\mathcal T)}) * h^{(\mathcal T -1)} + \mathcal Z^{(\mathcal T)} * \widetilde{h}^{(\mathcal T)} \\ \widetilde{h}^{(\mathcal T)} = \text{Tanh} \left[\mathcal W_{\mathcal H \Rightarrow \widetilde{\mathcal H}} \cdot (r^{(\mathcal T)} * h^{(\mathcal T -1)}) + \mathcal W_{\mathcal X \Rightarrow \widetilde{\mathcal H}} \cdot x^{(\mathcal T)} + b_{\widetilde{\mathcal H}}\right] \end{cases}\\ \quad \\ \text{Backward : } \begin{aligned} \frac{\partial \mathcal L^{(\mathcal T)}}{\partial \mathcal W_{h^{(\mathcal T - 1)} \Rightarrow \mathcal Z^{(\mathcal T - 1)}}} \Rightarrow \frac{\partial \mathcal L^{(\mathcal T)}}{\partial h^{(\mathcal T)}} \cdot \frac{\partial h^{(\mathcal T)}}{\partial \widetilde{h}^{(\mathcal T)}} \cdot \frac{\widetilde{h}^{(\mathcal T)}}{\partial h^{(\mathcal T - 1)}} \cdot \frac{\partial h^{(\mathcal T - 1)}}{\partial \mathcal W_{h^{(\mathcal T - 1)} \Rightarrow \mathcal Z^{(\mathcal T - 1)}}} \end{aligned} \end{cases} Forward : {h(T)=(1Z(T))h(T1)+Z(T)h (T)h (T)=Tanh[WHH (r(T)h(T1))+WXH x(T)+bH ]Backward : Wh(T1)Z(T1)L(T)h(T)L(T)h (T)h(T)h(T1)h (T)Wh(T1)Z(T1)h(T1)
  • 第四条:第三条路径类似,只不过从 h ~ ( T ) \widetilde{h}^{(\mathcal T)} h (T)中的 r ( T ) r^{(\mathcal T)} r(T) h ( T − 1 ) h^{(\mathcal T - 1)} h(T1)进行传递。
    { Forward :  { h ( T ) = ( 1 − Z ( T ) ) ∗ h ( T − 1 ) + Z ( T ) ∗ h ~ ( T ) h ~ ( T ) = Tanh [ W H ⇒ H ~ ⋅ ( r ( T ) ∗ h ( T − 1 ) ) + W X ⇒ H ~ ⋅ x ( T ) + b H ~ ] r ~ ( T ) = W H ⇒ r ⋅ h ( T − 1 ) + W X ⇒ r ⋅ x ( T ) + b r Backward :  ∂ L ( T ) ∂ W h ( T − 1 ) ⇒ Z ( T − 1 ) ⇒ ∂ L ( T ) ∂ h ( T ) ⋅ ∂ h ( T ) ∂ h ~ ( T ) ⋅ ∂ h ~ ( T ) ∂ r ( T ) ⋅ ∂ r ( T ) ∂ h ( T − 1 ) ⋅ ∂ h ( T − 1 ) ∂ W h ( T − 1 ) ⇒ Z ( T − 1 ) \begin{cases} \text{Forward : } \begin{cases} h^{(\mathcal T)} = (1 -\mathcal Z^{(\mathcal T)}) * h^{(\mathcal T -1)} + \mathcal Z^{(\mathcal T)} * \widetilde{h}^{(\mathcal T)} \\ \widetilde{h}^{(\mathcal T)} = \text{Tanh} \left[\mathcal W_{\mathcal H \Rightarrow \widetilde{\mathcal H}} \cdot (r^{(\mathcal T)} * h^{(\mathcal T -1)}) + \mathcal W_{\mathcal X \Rightarrow \widetilde{\mathcal H}} \cdot x^{(\mathcal T)} + b_{\widetilde{\mathcal H}}\right] \\ \widetilde{r}^{(\mathcal T)} = \mathcal W_{\mathcal H \Rightarrow r} \cdot h^{(\mathcal T -1)} + \mathcal W_{\mathcal X \Rightarrow r} \cdot x^{(\mathcal T)} + b_{r} \end{cases}\\ \quad \\ \text{Backward : } \begin{aligned} \frac{\partial \mathcal L^{(\mathcal T)}}{\partial \mathcal W_{h^{(\mathcal T - 1)} \Rightarrow \mathcal Z^{(\mathcal T - 1)}}} \Rightarrow \frac{\partial \mathcal L^{(\mathcal T)}}{\partial h^{(\mathcal T)}} \cdot \frac{\partial h^{(\mathcal T)}}{\partial \widetilde{h}^{(\mathcal T)}} \cdot \frac{\partial \widetilde{h}^{(\mathcal T)}}{\partial r^{(\mathcal T)}} \cdot \frac{\partial r^{(\mathcal T)}}{\partial h^{(\mathcal T - 1)}} \cdot \frac{\partial h^{(\mathcal T - 1)}}{\partial \mathcal W_{h^{(\mathcal T - 1)} \Rightarrow \mathcal Z^{(\mathcal T - 1)}}} \end{aligned} \end{cases} Forward :  h(T)=(1Z(T))h(T1)+Z(T)h (T)h (T)=Tanh[WHH (r(T)h(T1))+WXH x(T)+bH ]r (T)=WHrh(T1)+WXrx(T)+brBackward : Wh(T1)Z(T1)L(T)h(T)L(T)h (T)h(T)r(T)h (T)h(T1)r(T)Wh(T1)Z(T1)h(T1)

至此, T ⇒ T − 1 \mathcal T \Rightarrow \mathcal T - 1 TT1时刻的 5 5 5条路径已全部找全。其中:

  • 1 1 1条是 T − 1 \mathcal T - 1 T1时刻自身路径;
  • 剩余 4 4 4条均是 T ⇒ T − 1 \mathcal T \Rightarrow \mathcal T - 1 TT1的传播路径。

T − 2 \mathcal T - 2 T2时刻的反向传播路径

再往下走一步,观察它路径传播数量规律

  • 1 1 1条依然是 L ( T − 2 ) \mathcal L^{(\mathcal T - 2)} L(T2) W h ( T − 2 ) ⇒ Z ( T − 2 ) \mathcal W_{h^{(\mathcal T - 2)} \Rightarrow \mathcal Z^{(\mathcal T - 2)}} Wh(T2)Z(T2)直接传递的梯度:
    ∂ L ( T − 2 ) ∂ W h ( T − 2 ) ⇒ Z ( T − 2 ) = ∂ L ( T − 2 ) ∂ h ( T − 2 ) ⋅ ∂ h ( T − 2 ) ∂ W h ( T − 2 ) ⇒ Z ( T − 2 ) \begin{aligned} \frac{\partial \mathcal L^{(\mathcal T - 2)}}{\partial \mathcal W_{h^{(\mathcal T - 2)} \Rightarrow \mathcal Z^{(\mathcal T - 2)}}} = \frac{\partial \mathcal L^{(\mathcal T - 2)}}{\partial h^{(\mathcal T - 2)}} \cdot \frac{\partial h^{(\mathcal T - 2)}}{\partial \mathcal W_{h^{(\mathcal T - 2)} \Rightarrow \mathcal Z^{(\mathcal T - 2)}}} \end{aligned} Wh(T2)Z(T2)L(T2)=h(T2)L(T2)Wh(T2)Z(T2)h(T2)
  • 存在 4 4 4是从 L ( T − 1 ) \mathcal L^{(\mathcal T - 1)} L(T1)开始,从 T − 1 ⇒ T − 2 \mathcal T - 1 \Rightarrow \mathcal T - 2 T1T2时刻传递的路径:
    ∂ L ( T − 1 ) ∂ W h ( T − 2 ) ⇒ Z ( T − 2 ) = { ∂ L ( T − 1 ) ∂ h ( T − 1 ) ⋅ ∂ h ( T − 1 ) ∂ h ( T − 2 ) ⋅ ∂ h ( T − 2 ) ∂ W h ( T − 2 ) ⇒ Z ( T − 2 ) ∂ L ( T − 1 ) ∂ h ( T − 1 ) ⋅ ∂ h ( T − 1 ) ∂ Z ( T − 1 ) ⋅ ∂ Z ( T − 1 ) ∂ h ( T − 2 ) ⋅ ∂ h ( T − 2 ) ∂ W h ( T − 2 ) ⇒ Z ( T − 2 ) ∂ L ( T − 1 ) ∂ h ( T − 1 ) ⋅ ∂ h ( T − 1 ) ∂ h ~ ( T − 1 ) ⋅ ∂ h ~ ( T − 1 ) ∂ h ( T − 2 ) ⋅ ∂ h ( T − 2 ) ∂ W h ( T − 2 ) ⇒ Z ( T − 2 ) ∂ L ( T − 1 ) ∂ h ( T − 1 ) ⋅ ∂ h ( T − 1 ) ∂ h ~ ( T − 1 ) ⋅ ∂ h ~ ( T − 1 ) ∂ r ( T − 1 ) ⋅ ∂ r ( T − 1 ) ∂ h ( T − 2 ) ⋅ ∂ h ( T − 2 ) ∂ W h ( T − 2 ) ⇒ Z ( T − 2 ) \frac{\partial \mathcal L^{(\mathcal T - 1)}}{\partial \mathcal W_{h^{(\mathcal T - 2)} \Rightarrow \mathcal Z^{(\mathcal T - 2)}}} = \begin{cases} \begin{aligned} & \frac{\partial \mathcal L^{(\mathcal T - 1)}}{\partial h^{(\mathcal T - 1)}} \cdot \frac{\partial h^{(\mathcal T - 1)}}{\partial h^{(\mathcal T - 2)}} \cdot \frac{\partial h^{(\mathcal T - 2)}}{\partial \mathcal W_{h^{(\mathcal T - 2)} \Rightarrow \mathcal Z^{(\mathcal T - 2)}}} \\ & \frac{\partial \mathcal L^{(\mathcal T - 1)}}{\partial h^{(\mathcal T - 1)}} \cdot \frac{\partial h^{(\mathcal T - 1)}}{\partial \mathcal Z^{(\mathcal T - 1)}} \cdot \frac{\partial \mathcal Z^{(\mathcal T - 1)}}{\partial h^{(\mathcal T - 2)}} \cdot \frac{\partial h^{(\mathcal T - 2)}}{\partial \mathcal W_{h^{(\mathcal T - 2)} \Rightarrow \mathcal Z^{(\mathcal T - 2)}}}\\ & \frac{\partial \mathcal L^{(\mathcal T - 1)}}{\partial h^{(\mathcal T - 1)}} \cdot \frac{\partial h^{(\mathcal T - 1)}}{\partial \widetilde{h}^{(\mathcal T - 1)}} \cdot \frac{\partial \widetilde{h}^{(\mathcal T - 1)}}{\partial h^{(\mathcal T - 2)}} \cdot \frac{\partial h^{(\mathcal T - 2)}}{\partial \mathcal W_{h^{(\mathcal T - 2)} \Rightarrow \mathcal Z^{(\mathcal T - 2)}}} \\ & \frac{\partial \mathcal L^{(\mathcal T - 1)}}{\partial h^{(\mathcal T - 1)}} \cdot \frac{\partial h^{(\mathcal T - 1)}}{\partial \widetilde{h}^{(\mathcal T - 1)}} \cdot \frac{\partial \widetilde{h}^{(\mathcal T - 1)}}{\partial r^{(\mathcal T - 1)}} \cdot \frac{\partial r^{(\mathcal T - 1)}}{\partial h^{(\mathcal T - 2)}} \cdot \frac{\partial h^{(\mathcal T - 2)}}{\partial \mathcal W_{h^{(\mathcal T - 2)} \Rightarrow \mathcal Z^{(\mathcal T - 2)}}} \end{aligned} \end{cases} Wh(T2)Z(T2)L(T1)= h(T1)L(T1)h(T2)h(T1)Wh(T2)Z(T2)h(T2)h(T1)L(T1)Z(T1)h(T1)h(T2)Z(T1)Wh(T2)Z(T2)h(T2)h(T1)L(T1)h (T1)h(T1)h(T2)h (T1)Wh(T2)Z(T2)h(T2)h(T1)L(T1)h (T1)h(T1)r(T1)h (T1)h(T2)r(T1)Wh(T2)Z(T2)h(T2)
  • 存在 4 × 4 4 \times 4 4×4是从 L ( T ) \mathcal L^{(\mathcal T)} L(T)开始,从 T ⇒ T − 2 \mathcal T \Rightarrow \mathcal T- 2 TT2时刻传递的路径。
    这个就不写了,太墨迹了。

这仅仅是 T ⇒ T − 2 \mathcal T \Rightarrow \mathcal T - 2 TT2时刻的路径数量, T − 3 \mathcal T - 3 T3时刻关于 L ( T ) \mathcal L^{(\mathcal T)} L(T)相关的梯度路径有 4 × 4 × 4 = 64 4 \times 4 \times 4 = 64 4×4×4=64条,以此类推。

总结

LSTM \text{LSTM} LSTM的反向传播路径相比, LSTM \text{LSTM} LSTM仅仅从 T ⇒ T − 2 \mathcal T \Rightarrow \mathcal T - 2 TT2时刻传递的路径就有 24 24 24,而 GRU \text{GRU} GRU仅有 16 16 16条,相比之下,极大地减小了反向传播路径的数量;
降低了时间、空间复杂度;

其次, GRU \text{GRU} GRU相比 LSTM \text{LSTM} LSTM减少了模型参数的更新数量,降低了过拟合 ( OverFitting ) (\text{OverFitting}) (OverFitting)的风险。

它的抑制梯度消失原理与 LSTM \text{LSTM} LSTM思想相同。首先随着反向传播深度的加深,相关梯度路径依然会呈指数级别增长,但规模明显小于 LSTM \text{LSTM} LSTM;并且其梯度计算过程依然有更新门、重置门自身参与梯度运算,从而调节各梯度分量的配置情况

相关参考:
GRU循环神经网络 —— LSTM的轻量级版本

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.coloradmin.cn/o/597997.html

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈,一经查实,立即删除!

相关文章

事物管理.

目录 引入CURD满足什么属性,能解决上述问题?什么是事务?为什么会出现事务事务的版本支持事务提交方式事务常见操作方式事务隔离级别如何理解隔离性隔离级别查看与设置隔离性读未提交【Read Uncommitted】读提交【Read Committed】可重复读【R…

kaggle新赛:蛋白质功能预测大赛baseline

日前,Kaggle发布了CAFA 5 Protein Function Prediction蛋白质功能预测大赛。这是一个机器学习中的序列预测任务,需要你开发一个基于蛋白质氨基酸序列和其他数据的模型,预测一组蛋白质的功能。 该竞赛评估参与者对蛋白质序列的基因本体论&…

3D元宇宙数字展厅—虚拟智能化办公展厅引领未来办公新风尚

随着数字化技术和虚拟现实的迅猛发展,传统的办公方式正在经历一场革命性的变革。在这个数字化时代,虚拟智能化办公展厅正以其独特的优势和创新的展示方式,引领着未来办公的新风尚。 让我们一同探索虚拟智能化办公展厅的魅力,以及它…

k8s入门(二)之Deployment、DaemonSet、Job、CronJob

一、Deployment使用 状态:Available部署完成,Progressing进行中,Complete已经完成,Failed失败的 失败原因:Quota不足,ReadingnessProbe失败,image pull失败,Limit Ranges范围&#x…

一分钟跑出 AI 图像的生成平台

*Stability AI 最近推出了一个名为 StableStudio 的 AI 图像生成平台,这是一个开源的、基于社区驱动的平台,任何人都可以访问和使用。StableStudio 提供了一系列功能强大的工具和库,包括预训练模型、数据集、模型评估和调试工具等&#xff0c…

NSSCTF之Web篇刷题记录(13)

NSSCTF之Web篇刷题记录[12] [GXYCTF 2019]BabyUpload:[GKCTF 2020]cve版签到:[HCTF 2018]Warmup:[GDOUCTF 2023]泄露的伪装:[羊城杯 2020]easycon:[HNCTF 2022 Week1]Interesting_include: NSSCTF平台&…

还有人不知道,加盟连锁店该怎么做?酒店加盟连锁店如何招商?

还有人不知道,加盟连锁店该怎么做?酒店加盟连锁店如何招商? 想要创业的新人,一进到电商行业,看到繁杂的模式以及激烈的竞争关系,都没到平台亏钱的那一步,自己就先泄气了。一个企业能否发展起来&…

The Category-theoretic Perspective of Statistical Learning for Amateurs

统计学习.范畴论视角 title: The Category-theoretic Perspective of Statistical Learning for Amateurs author: Congwei Song description: A representation in BIMSA The Category-theoretical Perspective of Statistical Learning for Amateurs Congwei Song Email: …

基于SSM的疫苗接种平台

末尾获取源码 开发语言:Java Java开发工具:JDK1.8 后端框架:SSM 前端:Vue 数据库:MySQL5.7和Navicat管理工具结合 服务器:Tomcat8.5 开发软件:IDEA / Eclipse 是否Maven项目:是 目录…

抢先看!文档控件aspose.words 新版本23.05 有哪些亮点?

Aspose.Words是一种高级Word文档处理API,用于执行各种文档管理和操作任务。API支持生成,修改,转换,呈现和打印文档,而无需在跨平台应用程序中直接使用Microsoft Word。 Aspose API支持流行文件格式处理,并…

Flutter-布局(Layout)原理

1、约束、尺寸、位置 overrideWidget build(BuildContext context) {return Scaffold(body: LayoutBuilder(builder: (context, constraints) {print("body约束:" constraints.toString());return Container(color: Colors.black,width: 300,height: 300,child: L…

计算机中丢失vcomp140.dll解决方案,可以使用这个3种方法修复

vcomp140.dll是一个动态连接库文件,它是Microsoft Visual Studio 2015应用程序所必需的运行库文件之一。它在Visual C Redistributable for Visual Studio 2015包中提供,是用于支持Microsoft C/C OpenMP Runtime的库文件。计算机中丢失vcomp140.dll无法打…

LNMP网站框架搭建(编译安装)

目录 一、Nginx的工作原理 工作进程: 二、Nginx编译安装安装 三、mysql的编译安装 四、php的编译安装 验证PHP与nginx的是否连接 验证lnmp的是否搭建成功 五、部署 Discuz!社区论坛 六、fpm参数优化 一、Nginx的工作原理 php-fpm.conf …

Redis数据类型之String——字符串、数值、bitmap

Redis数据类型之String——字符串、数值、bitmap 注意索引位置一般从左到右 0开始,叫正向索引。从右到左-1开始叫反向索引 字符串 字符串有很多操作set、get、append、setrange、getrange等,每个都有自己对应的用处 SET SET key value 设置指定 key …

单元测试系列:一、了解spring boot单元测试

一、java 单元测试框架 java当前主流的测试框架有两个:JUnit、TestNG。 1、两者相同点 使用annotation,且大部分annotation相同。都可以进行单元测试(Unit test)。都是针对Java测试的工具。 2、两者不同点 JUnit只能进行单元…

【Axure教程】大小图动态轮播

大小图动态轮播常用于展示多张图片,其中包含两种不同尺寸的图片。这种类型的轮播通常用于网站首页、产品展示、广告宣传等场景,提供更丰富的展示方式,吸引用户的注意力并提供更多信息。通过切换不同的图片,可以有效地传达多个内容…

采购异常支出怎么造成的?如何控制?

采购管理中的"异常支出 "是指在企业预定的支出规则之外进行的交易。虽然大多数大型采购都是与知名供应商合作,并直接通过采购团队的合同进行,但并不是所有的采购都是这样正式进行的,这可能会导致支出不明的问题。 什么原因造成异常…

15-创建Vue3.0工程

目录 1.使用 vue-cli 创建2.使用 vite 创建 1.使用 vue-cli 创建 官方文档:https://cli.vuejs.org/zh/guide/creating-a-project.html#vue-create ## 查看vue/cli版本,确保vue/cli版本在4.5.0以上 vue --version ## 安装或者升级你的vue/cli npm insta…

创建孔、缩放、复制和粘贴

创建孔 项目概况: 在本项目中,您将学习如何使用孔特征从另一个形状中去除材料。 在Tinkercad上查看整个项目 指示 将蓝色多边形形状拖动到工作平面上,并将其放置在以橙色勾勒的区域。 提示: 您可能需要向下滚动形状列表才能找到…

kendoUI中的Observable详解

kendoUI中的Observable方法 一、前言 Kendo UI是一个基于JavaScript的开源UI框架,它提供了一系列的UI组件和工具,包括表格、图表、表单、对话框等。Kendo UI中的Observable是一个非常重要的概念,它可以帮助我们更好地理解和使用Kendo UI。 …