# 1.11 双向循环神经网络（Bidirectional RNN）

双向**RNN**模型在序列的某点处不仅可以获取之前的信息，还可以获取未来的信息

用只有4个单词的句子，$$x^{<1>}$$到$$x^{<4>}$$。这个网络有一个前向的循环单元$$a^{\rightarrow <1>}$$，$$a^{\rightarrow <2>}$$，$$a^{\rightarrow <3>}$$，$$a^{\rightarrow <4>}$$，这四个循环单元都有一个当前输入$$x$$输入进去，得到预测的$$\hat y^{<1>}$$，$$\hat y^{<2>}$$，$$\hat y^{<3>}$$和$$\hat y^{<4>}$$

再增加一个反向循环层：$$a^{\leftarrow <1>}$$，$$a^{\leftarrow <2>}$$，$$a^{\leftarrow <3>}$$，$$a^{\leftarrow <4>}$$

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

给定一个输入序列$$x^{<1>}$$到$$x^{<4>}$$，这个序列先后计算前向的$$a^{\rightarrow <1>}$$，$$a^{\rightarrow <2>}$$，$$a^{\rightarrow <3>}$$，$$a^{\rightarrow <4>}$$，而反向序列从$$a^{\leftarrow <4>}$$开始，计算完了反向的$$a^{\leftarrow <4>}$$，可以用这些激活值计算反向$$a^{\leftarrow <3>},a^{\leftarrow <2>},a^{\leftarrow <1>}$$

值得注意的是计算的是网络激活值，这不是反向传播而是前向的传播，图中前向传播一部分计算是从左到右，一部分计算是从右到左。把所有激活值都计算完了就可以计算预测结果

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

预测结果：

$$
\hat y^{} =g(W\_{g}\left\lbrack a^{\rightarrow <t>},a^{\leftarrow <t>} \right\rbrack +b\_{y})
$$

这些基本单元不仅仅是标准**RNN**单元，也可以是**GRU**单元或者**LSTM**单元

双向**RNN**网络模型的缺点是需要完整的数据的序列才能预测任意位置。比如要构建一个语音识别系统，双向**RNN**模型需要等待整个语音说完，获取整个语音表达才能处理这段语音，并进一步做语音识别


---

# 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/111-shuang-xiang-xun-huan-shenjing-wang-luo-ff08-bidirectional-rnn.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.
