Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
PaddlePaddle
Paddle
提交
044fb0fb
P
Paddle
项目概览
PaddlePaddle
/
Paddle
大约 1 年 前同步成功
通知
2298
Star
20931
Fork
5422
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
1423
列表
看板
标记
里程碑
合并请求
543
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
P
Paddle
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
1,423
Issue
1,423
列表
看板
标记
里程碑
合并请求
543
合并请求
543
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
未验证
提交
044fb0fb
编写于
2月 24, 2018
作者:
Y
Yu Yang
提交者:
GitHub
2月 24, 2018
浏览文件
操作
浏览文件
下载
差异文件
Merge pull request #8511 from reyoung/feature/understand_sentimental_dynrnn
Test Parallel.Do and DynRNN
上级
d4dabe3e
7d247ca5
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
59 addition
and
1 deletion
+59
-1
python/paddle/v2/fluid/layers/control_flow.py
python/paddle/v2/fluid/layers/control_flow.py
+2
-1
python/paddle/v2/fluid/tests/book/test_understand_sentiment.py
...n/paddle/v2/fluid/tests/book/test_understand_sentiment.py
+57
-0
未找到文件。
python/paddle/v2/fluid/layers/control_flow.py
浏览文件 @
044fb0fb
...
...
@@ -652,7 +652,8 @@ class While(object):
parent_block
.
append_op
(
type
=
'while'
,
inputs
=
{
'X'
:
[
parent_block
.
var
(
x_name
)
for
x_name
in
x_name_list
],
'X'
:
[
parent_block
.
var_recursive
(
x_name
)
for
x_name
in
x_name_list
],
'Condition'
:
[
self
.
cond_var
]
},
outputs
=
{
'Out'
:
out_vars
,
...
...
python/paddle/v2/fluid/tests/book/test_understand_sentiment.py
浏览文件 @
044fb0fb
...
...
@@ -47,6 +47,46 @@ def convolution_net(data, label, input_dim, class_dim=2, emb_dim=32,
return
avg_cost
,
accuracy
,
prediction
def
dyn_rnn_lstm
(
data
,
label
,
input_dim
,
class_dim
=
2
,
emb_dim
=
32
,
lstm_size
=
128
):
emb
=
fluid
.
layers
.
embedding
(
input
=
data
,
size
=
[
input_dim
,
emb_dim
],
is_sparse
=
True
)
sentence
=
fluid
.
layers
.
fc
(
input
=
emb
,
size
=
lstm_size
,
act
=
'tanh'
)
rnn
=
fluid
.
layers
.
DynamicRNN
()
with
rnn
.
block
():
word
=
rnn
.
step_input
(
sentence
)
prev_hidden
=
rnn
.
memory
(
value
=
0.0
,
shape
=
[
lstm_size
])
prev_cell
=
rnn
.
memory
(
value
=
0.0
,
shape
=
[
lstm_size
])
def
gate_common
(
ipt
,
hidden
,
size
):
gate0
=
fluid
.
layers
.
fc
(
input
=
ipt
,
size
=
size
,
bias_attr
=
True
)
gate1
=
fluid
.
layers
.
fc
(
input
=
hidden
,
size
=
size
,
bias_attr
=
False
)
return
gate0
+
gate1
forget_gate
=
fluid
.
layers
.
sigmoid
(
x
=
gate_common
(
word
,
prev_hidden
,
lstm_size
))
input_gate
=
fluid
.
layers
.
sigmoid
(
x
=
gate_common
(
word
,
prev_hidden
,
lstm_size
))
output_gate
=
fluid
.
layers
.
sigmoid
(
x
=
gate_common
(
word
,
prev_hidden
,
lstm_size
))
cell_gate
=
fluid
.
layers
.
sigmoid
(
x
=
gate_common
(
word
,
prev_hidden
,
lstm_size
))
cell
=
forget_gate
*
prev_cell
+
input_gate
*
cell_gate
hidden
=
output_gate
*
fluid
.
layers
.
tanh
(
x
=
cell
)
rnn
.
update_memory
(
prev_cell
,
cell
)
rnn
.
update_memory
(
prev_hidden
,
hidden
)
rnn
.
output
(
hidden
)
last
=
fluid
.
layers
.
sequence_last_step
(
rnn
())
prediction
=
fluid
.
layers
.
fc
(
input
=
last
,
size
=
class_dim
,
act
=
"softmax"
)
cost
=
fluid
.
layers
.
cross_entropy
(
input
=
prediction
,
label
=
label
)
avg_cost
=
fluid
.
layers
.
mean
(
x
=
cost
)
accuracy
=
fluid
.
layers
.
accuracy
(
input
=
prediction
,
label
=
label
)
return
avg_cost
,
accuracy
,
prediction
def
stacked_lstm_net
(
data
,
label
,
input_dim
,
...
...
@@ -270,6 +310,23 @@ class TestUnderstandSentiment(unittest.TestCase):
use_cuda
=
True
,
parallel
=
True
)
@
unittest
.
skip
(
reason
=
'make CI faster'
)
def
test_dynrnn_lstm_gpu
(
self
):
with
self
.
new_program_scope
():
main
(
self
.
word_dict
,
net_method
=
dyn_rnn_lstm
,
use_cuda
=
True
,
parallel
=
False
)
def
test_dynrnn_lstm_gpu_parallel
(
self
):
with
self
.
new_program_scope
():
main
(
self
.
word_dict
,
net_method
=
dyn_rnn_lstm
,
use_cuda
=
True
,
parallel
=
True
)
if
__name__
==
'__main__'
:
unittest
.
main
()
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录