提交 b16b4aa0 编写于 作者: W wizardforcel

2020-09-01 14:21:37

上级 78430a56
# 六、循环神经网络
In this chapter, we will present a number of recipes covering the following topics:
在本章中,我们将介绍一些涵盖以下主题的食谱:
* 神经机器翻译-训练 seq2seq RNN
* 神经机器翻译-推理 seq2seq RNN
......@@ -17,13 +17,13 @@ In this chapter, we will present a number of recipes covering the following topi
![](img/428ab6dd-b328-4f89-a675-24eabccb2988.png)
An example of prediction with "The quick brown fox" sentence
`The quick brown fox`句子进行预测的例子
一个简单的变体是存储多个预测,因此创建一棵可能的扩展树,如下图所示:
![](img/3d541407-363a-401e-b3eb-60dbbc994440.png)
An example of tree prediction with "The quick brown fox" sentence
`The quick brown fox`句子的预测树的示例
但是,基于序列的模型可以在大量其他域中使用。 在音乐中,乐曲中的下一个音符肯定取决于前一个音符,而在视频中,电影中的下一个帧必定与前一帧有关。 此外,在某些情况下,当前的视频帧,单词,字符或音符不仅取决于前一个,而且还取决于后一个。
......@@ -33,13 +33,13 @@ An example of tree prediction with "The quick brown fox" sentence
![](img/fbffb7f6-46df-4186-964b-d01cac81ae8b.png)
An example of feeding back
反馈示例
循环关系可以方便地通过*展开*网络来表示,如下图所示:
![](img/05b91901-88c4-44e6-bea5-d929c70dd2d2.png)
An example of unfolding a recurrent cell
展开循环单元的例子
最简单的 RNN 单元由简单的 *tanh* 函数(双曲正切函数)组成,如下图所示:
......@@ -47,7 +47,7 @@ An example of unfolding a recurrent cell
![](img/efb66350-20dc-4688-97f8-f7c661deb76a.png)
An example of simple tanh cell
个简单的 tanh 单元的例子
# 消失和梯度爆炸
......@@ -55,13 +55,13 @@ An example of simple tanh cell
![](img/1e10fcdf-8db6-4e52-8f7f-d1398c54c634.png)
Examples of gradient
梯度示例
**梯度裁剪**包括对梯度施加最大值,以使其无法无限增长。 下图所示的简单解决方案为**梯度爆炸问题提供了简单的解决方案**
![](img/1ddb8b2f-e13b-479f-9568-488a01b4c539.png)
An example of gradient clipping
梯度裁剪的例子
解决梯度消失的问题需要一种更复杂的内存模型,该模型可以选择性地忘记先前的状态,只记住真正重要的状态。 考虑下图,输入以`[0,1]`中的概率`p`写入存储器`M`中,并乘以加权输入。
......@@ -69,7 +69,7 @@ An example of gradient clipping
![](img/7b32ca16-e98a-4ab0-b732-215739cc11fc.png)
An example of memory cell
存储单元的一个例子
# 长短期记忆(LSTM)
......@@ -77,7 +77,7 @@ LSTM 网络可以控制何时让输入进入神经元,何时记住在上一个
![](img/930273d1-d536-42bd-99ab-d02986f6705d.png)
An example of an LSTM cell
LSTM 单元的一个例子
首先,我们需要一个逻辑函数σ(请参见第 2 章,“回归”)来计算介于 0 和 1 之间的值,并控制哪些信息流过 *LSTM 门*。 请记住,逻辑函数是可微的,因此允许反向传播。 然后,我们需要一个运算符`⊗`,它采用两个相同维的矩阵并生成另一个矩阵,其中每个元素`ij`是原始两个矩阵的元素`ij`的乘积。 同样,我们需要一个运算符`⊕`,它采用两个相同维度的矩阵并生成另一个矩阵,其中每个元素`ij`是原始两个矩阵的元素`ij`之和。 使用这些基本块,我们考虑时间`i`处的输入`X[i]`,并将其与上一步中的输出`Y[i-1]`并置。
......@@ -101,7 +101,7 @@ An example of an LSTM cell
![](img/01d98910-b7d4-4512-8ebf-c0cb3ea7dc25.png)
Examples of Standard LSTM, PeepHole LSTM, and GRU
标准 LSTM,PeepHole LSTM 和 GRU 的示例
# 对向量序列进行运算
......@@ -109,7 +109,7 @@ Examples of Standard LSTM, PeepHole LSTM, and GRU
![](img/fdee6d5f-b2cf-40d2-aa69-ac5b11e6826f.png)
An example of RNN sequences as seen in http://karpathy.github.io/2015/05/21/rnn-effectiveness/
[RNN 序列的一个例子](http://karpathy.github.io/2015/05/21/rnn-effectiveness/)
机器翻译是输入和输出中不同步序列的一个示例:网络将输入文本作为序列读取,在读取全文之后,*会输出目标语言*
......@@ -121,7 +121,7 @@ An example of RNN sequences as seen in http://karpathy.github.io/2015/05/21/rnn-
![](img/bc72f98e-d71c-4703-8fa7-5195a6fc65af.jpg)
An example of text generated with RNNs
用 RNN 生成的文本示例
# 神经机器翻译-训练 seq2seq RNN
......@@ -131,7 +131,7 @@ An example of text generated with RNNs
![](img/7af9de06-f5cd-4edc-a793-76ad408c579b.png)
An example of encoder-decoder as seen in https://github.com/lmthang/thesis/blob/master/thesis.pdf
[编解码器的示例](https://github.com/lmthang/thesis/blob/master/thesis.pdf)
让我们看一个 RNN 的示例,该语句将`She loves cute cats`翻译成`Elle Aime les chat Mignons`
......@@ -139,7 +139,7 @@ An example of encoder-decoder as seen in https://github.com/lmthang/thesis/blob/
![](img/8e9fd11b-d547-4740-9010-ca4e1ebb30f9.png)
An example of sequence models for NMT as seen in https://github.com/lmthang/thesis/blob/master/thesis.pdf
[NMT 序列模型的示例](https://github.com/lmthang/thesis/blob/master/thesis.pdf)
现在,我们可以拥有许多 RNN 变体。 让我们看看其中的一些:
......@@ -152,7 +152,7 @@ An example of sequence models for NMT as seen in https://github.com/lmthang/thes
![](img/45216119-cbfa-47f0-9080-b6256eefb995.png)
An example of Neural machine translation as seen in https://github.com/lmthang/thesis/blob/master/thesis.pdf
[神经机器翻译的例子](https://github.com/lmthang/thesis/blob/master/thesis.pdf)
在本食谱中,我们使用 NMT(神经机器翻译),这是一个可在 TensorFlow 顶部在线获得的翻译演示包。
......@@ -303,7 +303,7 @@ An example of BLEU metric in Tensorboard
![](img/7c5d2780-428a-40ef-9016-4487daf95aa4.jpg)
An example of sequence models for NMT with probabilities as seen in https://github.com/lmthang/thesis/blob/master/thesis.pdf
[具有概率的 NM 序列模型的示例](https://github.com/lmthang/thesis/blob/master/thesis.pdf)
使用解码器的输出有多种策略:
......@@ -356,7 +356,7 @@ python -m nmt.nmt \
![](img/536457c9-7581-40ca-b61c-f38683038302.jpg)
An example of attention model for NMT as seen in https://github.com/lmthang/thesis/blob/master/thesis.pdf
[NMT 注意模型的示例](https://github.com/lmthang/thesis/blob/master/thesis.pdf)
需要考虑三个方面:
......@@ -431,7 +431,7 @@ nmt: But what do you know ?
![](img/8b84792d-9bbf-4e22-8b53-157adf67f539.png)
An example of BLEU metrics with attention in Tensorboard
Tensorboard 中注意力的 BLEU 指标示例
# 还有更多...
......@@ -444,7 +444,7 @@ An example of BLEU metrics with attention in Tensorboard
![](img/355f941e-bfc0-4eff-8bab-e6f3fb2b6826.png)
An example of SyntaxNet as seen in https://research.googleblog.com/2016/05/announcing-syntaxnet-worlds-most.html
[SyntaxNet 的一个例子](https://research.googleblog.com/2016/05/announcing-syntaxnet-worlds-most.html)
# 通过 RNN 学习写作莎士比亚
......@@ -849,7 +849,7 @@ tensorboard --logdir=/tmp/bitcoin_logs
![](img/9a09fe95-a97b-4532-89a5-186fef8159af.png)
An example of code for Bitcoin value prediction as seen in Tensorboard
Tensorboard 中的比特币价值预测代码示例
6. 现在让我们将损失函数定义为具有正则化的 L2 损失,以避免过度拟合并获得更好的泛化。 选择的优化器是 RMSprop,其值为`learning_rate`,衰减和动量,如步骤 3 所定义:
......@@ -952,7 +952,7 @@ for j in range(nb_predictions):
![](img/473d111d-0d23-4ca4-ae73-97d7888e023b.png)
An example of bitcoin value prediction
比特币价值预测的一个例子
# 这个怎么运作...
......@@ -972,7 +972,7 @@ An example of bitcoin value prediction
![](img/e8627950-7ec7-4141-b6c5-9a51d80a7dca.jpg)
An example of RNN sequences as seen in http://karpathy.github.io/2015/05/21/rnn-effectiveness/
[RNN 序列的一个例子](http://karpathy.github.io/2015/05/21/rnn-effectiveness/)
# 怎么做...
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册