This repository has been archived by the owner on Jan 24, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Doc 3 #721
Open
JesseyXujin
wants to merge
19
commits into
PaddlePaddle:develop
Choose a base branch
from
JesseyXujin:doc_3
base: develop
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Doc 3 #721
Changes from all commits
Commits
Show all changes
19 commits
Select commit
Hold shift + click to select a range
7d31dd4
modify understand_sentiment doc
50790c7
modify link of understand_sentiment doc
0f8771c
modify png of understand_sentiment
2960953
Update README.cn.md
JesseyXujin 2b899b6
Delete formula_rnn_2.png
JesseyXujin 5e6ce7a
Add files via upload
JesseyXujin 2946d4a
Delete formula_lstm_2.png
JesseyXujin 9962118
Add files via upload
JesseyXujin 0c563b3
Update README.cn.md
JesseyXujin 5cc9d3f
Update README.cn.md
JesseyXujin 6f06f11
Update README.cn.md
JesseyXujin 6a6fe1e
Update README.cn.md
JesseyXujin 365e054
Delete formula_lstm_1.png
JesseyXujin f172eeb
Delete formula_lstm_2.png
JesseyXujin bb1bc55
Add files via upload
JesseyXujin f9f77c1
Delete formula_rnn_2.png
JesseyXujin 7105cc7
Update README.cn.md
JesseyXujin 39260a6
Update README.cn.md
JesseyXujin 88c3edd
Update README.cn.md
JesseyXujin File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -21,6 +21,10 @@ | |
|
||
本章我们所要介绍的深度学习模型克服了BOW表示的上述缺陷,它在考虑词顺序的基础上把文本映射到低维度的语义空间,并且以端对端(end to end)的方式进行文本表示及分类,其性能相对于传统方法有显著的提升\[[1](#参考文献)\]。 | ||
|
||
## 硬件环境的要求 | ||
本文档支持CPU和GPU训练,如果您使用了本文配套的docker镜像,请注意:该镜像对GPU的支持仅限于CUDA 8,cuDNN 5。 | ||
|
||
|
||
## 模型概览 | ||
本章所使用的文本表示模型为卷积神经网络(Convolutional Neural Networks)和循环神经网络(Recurrent Neural Networks)及其扩展。下面依次介绍这几个模型。 | ||
|
||
|
@@ -48,7 +52,9 @@ | |
|
||
循环神经网络按时间展开后如图2所示:在第$t$时刻,网络读入第$t$个输入$x_t$(向量表示)及前一时刻隐层的状态值$h_{t-1}$(向量表示,$h_0$一般初始化为$0$向量),计算得出本时刻隐层的状态值$h_t$,重复这一步骤直至读完所有输入。如果将循环神经网络所表示的函数记为$f$,则其公式可表示为: | ||
|
||
$$h_t=f(x_t,h_{t-1})=\sigma(W_{xh}x_t+W_{hh}h_{t-1}+b_h)$$ | ||
<p align="center"> | ||
<img src="https://github.com/JesseyXujin/book/blob/doc_3/06.understand_sentiment/image/formula_rnn.png?raw=true" width = "65%" align="center"/><br/> | ||
</p> | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 链接最好可以用book 仓库下的图片链接,虽然无法预览,但是等pr merge之后就可以了 |
||
|
||
其中$W_{xh}$是输入到隐层的矩阵参数,$W_{hh}$是隐层到隐层的矩阵参数,$b_h$为隐层的偏置向量(bias)参数,$\sigma$为$sigmoid$函数。 | ||
|
||
|
@@ -60,14 +66,17 @@ $$h_t=f(x_t,h_{t-1})=\sigma(W_{xh}x_t+W_{hh}h_{t-1}+b_h)$$ | |
|
||
相比于简单的循环神经网络,LSTM增加了记忆单元$c$、输入门$i$、遗忘门$f$及输出门$o$。这些门及记忆单元组合起来大大提升了循环神经网络处理长序列数据的能力。若将基于LSTM的循环神经网络表示的函数记为$F$,则其公式为: | ||
|
||
$$ h_t=F(x_t,h_{t-1})$$ | ||
<p align="center"> | ||
<img src="https://github.com/JesseyXujin/book/blob/doc_3/06.understand_sentiment/image/formula_lstm.png?raw=true" width = "30%" align="center"/><br/> | ||
</p> | ||
|
||
|
||
$F$由下列公式组合而成\[[7](#参考文献)\]: | ||
$$ i_t = \sigma{(W_{xi}x_t+W_{hi}h_{t-1}+W_{ci}c_{t-1}+b_i)} $$ | ||
$$ f_t = \sigma(W_{xf}x_t+W_{hf}h_{t-1}+W_{cf}c_{t-1}+b_f) $$ | ||
$$ c_t = f_t\odot c_{t-1}+i_t\odot tanh(W_{xc}x_t+W_{hc}h_{t-1}+b_c) $$ | ||
$$ o_t = \sigma(W_{xo}x_t+W_{ho}h_{t-1}+W_{co}c_{t}+b_o) $$ | ||
$$ h_t = o_t\odot tanh(c_t) $$ | ||
|
||
<p align="center"> | ||
<img src="https://github.com/JesseyXujin/book/blob/doc_3/06.understand_sentiment/image/formula_lstm_more.png?raw=true" width = "65%" align="center"/><br/> | ||
</p> | ||
|
||
其中,$i_t, f_t, c_t, o_t$分别表示输入门,遗忘门,记忆单元及输出门的向量值,带角标的$W$及$b$为模型参数,$tanh$为双曲正切函数,$\odot$表示逐元素(elementwise)的乘法操作。输入门控制着新输入进入记忆单元$c$的强度,遗忘门控制着记忆单元维持上一时刻值的强度,输出门控制着输出记忆单元的强度。三种门的计算方式类似,但有着完全不同的参数,它们各自以不同的方式控制着记忆单元$c$,如图3所示: | ||
|
||
<p align="center"> | ||
|
@@ -77,7 +86,9 @@ $$ h_t = o_t\odot tanh(c_t) $$ | |
|
||
LSTM通过给简单的循环神经网络增加记忆及控制门的方式,增强了其处理远距离依赖问题的能力。类似原理的改进还有Gated Recurrent Unit (GRU)\[[8](#参考文献)\],其设计更为简洁一些。**这些改进虽然各有不同,但是它们的宏观描述却与简单的循环神经网络一样(如图2所示),即隐状态依据当前输入及前一时刻的隐状态来改变,不断地循环这一过程直至输入处理完毕:** | ||
|
||
$$ h_t=Recrurent(x_t,h_{t-1})$$ | ||
<p align="center"> | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 公式地址请留官方repo的地址 |
||
<img src="https://github.com/JesseyXujin/book/blob/doc_3/06.understand_sentiment/image/formula_recrurent.png?raw=true" width = "50%" align="center"/><br/> | ||
</p> | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 这张公式图片有一个阴影,方便的话替换一张吧 |
||
|
||
其中,$Recrurent$可以表示简单的循环神经网络、GRU或LSTM。 | ||
|
||
|
@@ -242,6 +253,10 @@ use_cuda = False #在cpu上进行训练 | |
place = fluid.CUDAPlace(0) if use_cuda else fluid.CPUPlace() | ||
``` | ||
|
||
|
||
请注意:为使本文更加易读易用,我们拆分、调整了train.py的代码并放入本文。本文中代码与train.py的运行结果一致,如希望直接看到训练脚本输出效果,可运行train.py。 | ||
|
||
|
||
### 定义数据提供器 | ||
|
||
下一步是为训练和测试定义数据提供器。提供器读入一个大小为 BATCH_SIZE的数据。paddle.dataset.imdb.word_dict 每次会在乱序化后提供一个大小为BATCH_SIZE的数据,乱序化的大小为缓存大小buf_size。 | ||
|
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.