# 3.7 注意力模型直观理解（Attention Model Intuition）

给定一个很长的法语句子，在神经网络中，绿色的编码器要做的就是读整个句子，然后记忆整个句子，再在感知机中传递。紫色的神经网络，即解码网络（**the decoder network**）将生成英文翻译

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

对于短句子效果非常好，会有一个相对高的**Bleu**分（**Bleu score**），但是对于长句子而言，比如说大于30或者40词的句子，它的表现就会变差。**Bleu**评分随着单词数量变化，短的句子会难以翻译，因为很难得到所有词。对于长的句子，效果也不好，因为在神经网络中，记忆非常长句子是非常困难的。

而注意力模型翻译得很像人类，一次翻译句子的一部分。且机器翻译系统只会翻译句子的一部分，不会有一个巨大的下倾（**huge dip**），这个下倾衡量了神经网络记忆一个长句子的能力

对于句子里的每五个单词，使用双向的**RNN**（**a bidirectional RNN**），使用另一个**RNN**生成英文翻译：

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

$$S^{<t>}$$由原语句附近单元共同决定，**注意力权重（attention weights）**$$\alpha^{< t,t'>}$$ 表示尝试生成第$$t$$个英文词时应该花多少注意力在第$$t'$$个法语词上面。直到最终生成$$< EOS>$$。离得越近，**注意力权重**越大，相当于当前的注意力区域有个滑动窗。$$c$$表示编码器激活函数在注意力权重加权后的结果，将$$c$$输入到解码器用来生成翻译语句， 同时上一个时间步输出的翻译结果也加入


---

# 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/di-san-zhou-xu-lie-mo-xing-he-zhu-yi-li-ji-zhi-ff08-sequence-models-and-attention-mechanism/37-zhu-yi-li-mo-xing-zhi-guan-li-jie-ff08-attention-model-intuition.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.
