# 1.3 循环神经网络模型（Recurrent Neural Network Model）

序列模型从左到右，依次传递，此例中，$$T\_x=T\_y$$。$$x^{<t>}$$到$$\hat y^{<t>}$$之间是隐藏神经元。$$a^{<t>}$$会传入到第$$t+1$$元素中，作为输入。其中，$$a^{<0>}$$一般为零向量

![](https://2314428465-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-Le0cHhI0S0DK8pwlrmD%2F-Le0cKOp1vaxoORIi4ak%2F-Le0cf-QOFRntjo5TUwX%2F11112import.png?generation=1556953093472156\&alt=media)

循环神经网络是从左向右扫描数据，同时每个时间步的参数也是共享的，用$$W\_{\text{ax}}$$来表示管理着从$$x^{<1>}$$到隐藏层的连接的一系列参数，每个时间步使用的都是相同的参数$$W\_{\text{ax}}$$。而激活值是由参数$$W\_{aa}$$决定，同时每一个时间步都使用相同的参数$$W\_{aa}$$，同样的输出结果由$$W\_{\text{ya}}$$决定：

![](https://2314428465-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-Le0cHhI0S0DK8pwlrmD%2F-Le0cKOp1vaxoORIi4ak%2F-Le0cf-SA5Ko5_TUwPd6%2F11113import.png?generation=1556953127944691\&alt=media)

预测$${\hat{y}}^{< 3 >}$$时，不仅要使用$$x^{<3>}$$的信息，还要使用来自$$x^{<1>}$$和$$x^{<2>}$$的信息，而这个循环神经网络的一个缺点是只使用了这个序列中之前的信息来做出预测，因为如果给定了这个句子，“**Teddy Roosevelt was a great President.**”，为了判断**Teddy**是否是人名的一部分，仅仅知道句中前两个词是完全不够的，还需要知道句中后部分的信息，因为句子也可能是这样的，“**Teddy bears are on sale!**”。因此如果只给定前三个单词，是不可能确切地知道**Teddy**是否是人名的一部分，第一个例子是人名，第二个例子就不是，所以不可能只看前三个单词就能分辨出其中的区别

所以这样特定的神经网络结构的一个限制是它在某一时刻的预测仅使用了从序列之前的输入信息，并没有使用序列中后部分的信息

RNN的正向传播（Forward Propagation）过程为：

$$
a^{<t>}=g(W\_{aa}\cdot a^{<t-1>}+W\_{ax}\cdot x^{<t>}+b\_a)
$$

$$
\hat y^{<t>}=g(W\_{ya}\cdot a^{<t>}+b\_y)
$$

![](https://2314428465-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-Le0cHhI0S0DK8pwlrmD%2F-Le0cKOp1vaxoORIi4ak%2F-Le0cf-U8bPsQTTMYxTf%2F19cbb2d356a2a6e0f35aa2a946b23a2a.png?generation=1556953094175361\&alt=media)

为了简化表达式，可以对$$a^{<t>}$$项进行整合：

$$
W\_{aa}\cdot a^{<t-1>}+W\_{ax}\cdot x^{<t>}=\[W\_{aa}\ \ W\_{ax}]\left\[
\begin{matrix}
a^{<t-1>} \\
x^{<t>}
\end{matrix}
\right]\rightarrow W\_a\[a^{<t-1>},x^{<t>}]
$$

则正向传播可表示为：

$$
a^{<t>}=g(W\_a\[a^{<t-1>},x^{<t>}]+b\_a)
$$

$$
\hat y^{<t>}=g(W\_{y}\cdot a^{<t>}+b\_y)
$$

![](https://2314428465-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-Le0cHhI0S0DK8pwlrmD%2F-Le0cKOp1vaxoORIi4ak%2F-Le0cf-WIpWCW6tu2ICK%2F27afdd27f45ad8ddf78677af2a3eeaf8.png?generation=1556953106499206\&alt=media)

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

![](https://2314428465-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-Le0cHhI0S0DK8pwlrmD%2F-Le0cKOp1vaxoORIi4ak%2F-Le0cf-YvXst11Kf9Kdn%2Frnn-f.png?generation=1556953094595791\&alt=media)


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET 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/13-xun-huan-shen-jing-wang-luo-mo-xing-ff08-recurrent-neural-network-model.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
