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

本文详细介绍了GRU循环神经网络的前馈计算与反向传播过程,重点讨论了T时刻的反向传播路径,包括从T到T-1时刻的梯度传播。GRU相比于LSTM,减少了反向传播路径的数量和参数更新,降低了过拟合风险,同时利用更新门和重置门来缓解梯度消失问题。
摘要由CSDN通过智能技术生成

引言

上一节介绍了门控循环单元 ( 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[
  • 2
    点赞
  • 9
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

静静的喝酒

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值