> For the complete documentation index, see [llms.txt](https://baozoulin.gitbook.io/neural-networks-and-deep-learning/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://baozoulin.gitbook.io/neural-networks-and-deep-learning/di-wu-men-ke-xu-lie-mo-xing-sequence-models/di-wu-men-kexulie-mo-578b28-sequence-models/recurrent-neural-networks/14-tong-guo-shi-jian-de-fan-xiang-chuan-bo-ff08-backpropagation-through-time.md).

# 1.4 通过时间的反向传播（Backpropagation through time）

反向传播计算方向与前向传播基本上是相反：

[![](https://github.com/fengdu78/deeplearning_ai_books/raw/master/images/998c7af4f90cd0de0c88f138b61f0168.png)](https://github.com/fengdu78/deeplearning_ai_books/blob/master/images/998c7af4f90cd0de0c88f138b61f0168.png)

识别人名的例子，经过RNN正向传播，单个元素的Loss function为：

$$
L^{<t>}(\hat y^{<t>},y^{<t>})=-y^{<t>}log\ \hat y^{<t>}-(1-y^{<t>})log\ (1-\hat y^{<t>})
$$

> 这是 binary classification 的 Loss Function，注意与1.6 的softmax Loss Function区别

该样本所有元素的Loss function为：

$$
L(\hat y,y)=\sum\_{t=1}^{T\_y}L^{<t>}(\hat y^{<t>},y^{<t>})
$$

反向传播（Backpropagation）过程就是从右到左分别计算$$L(\hat y,y)$$对参数$$W\_{a}$$，$$W\_{y}$$，$$b\_a$$，$$b\_y$$的偏导数，这种从右到左的求导过程被称为Backpropagation through time

**RNN**反向传播示意图：

[![nn\_cell\_backpro](https://github.com/fengdu78/deeplearning_ai_books/raw/master/images/rnn_cell_backprop.png)](https://github.com/fengdu78/deeplearning_ai_books/blob/master/images/rnn_cell_backprop.png)
