Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
Crayon鑫
Paddle
提交
f1df9dba
P
Paddle
项目概览
Crayon鑫
/
Paddle
与 Fork 源项目一致
Fork自
PaddlePaddle / Paddle
通知
1
Star
1
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
1
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
P
Paddle
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
1
Issue
1
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
未验证
提交
f1df9dba
编写于
2月 20, 2019
作者:
J
Jiabin Yang
提交者:
GitHub
2月 20, 2019
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
test=develop, update fluid.layers to LaryerHelper (#15797)
上级
f2e8409f
变更
1
隐藏空白更改
内联
并排
Showing
1 changed file
with
19 addition
and
12 deletion
+19
-12
python/paddle/fluid/tests/unittests/test_imperative_ptb_rnn.py
...n/paddle/fluid/tests/unittests/test_imperative_ptb_rnn.py
+19
-12
未找到文件。
python/paddle/fluid/tests/unittests/test_imperative_ptb_rnn.py
浏览文件 @
f1df9dba
...
@@ -40,6 +40,8 @@ class SimpleLSTMRNN(fluid.imperative.Layer):
...
@@ -40,6 +40,8 @@ class SimpleLSTMRNN(fluid.imperative.Layer):
self
.
_dropout
=
dropout
self
.
_dropout
=
dropout
self
.
_input
=
None
self
.
_input
=
None
self
.
_num_steps
=
num_steps
self
.
_num_steps
=
num_steps
from
paddle.fluid.layer_helper
import
LayerHelper
self
.
_helper
=
LayerHelper
(
'SimpleLSTMRNN'
,
act
=
"tanh"
)
def
_build_once
(
self
,
input_embedding
,
init_hidden
=
None
,
init_cell
=
None
):
def
_build_once
(
self
,
input_embedding
,
init_hidden
=
None
,
init_cell
=
None
):
self
.
weight_1_arr
=
[]
self
.
weight_1_arr
=
[]
...
@@ -50,17 +52,21 @@ class SimpleLSTMRNN(fluid.imperative.Layer):
...
@@ -50,17 +52,21 @@ class SimpleLSTMRNN(fluid.imperative.Layer):
self
.
mask_array
=
[]
self
.
mask_array
=
[]
for
i
in
range
(
self
.
_num_layers
):
for
i
in
range
(
self
.
_num_layers
):
weight_1
=
fluid
.
layers
.
create_parameter
(
weight_1
=
self
.
_helper
.
create_parameter
(
attr
=
fluid
.
ParamAttr
(
initializer
=
fluid
.
initializer
.
UniformInitializer
(
low
=-
self
.
_init_scale
,
high
=
self
.
_init_scale
)),
shape
=
[
self
.
_hidden_size
*
2
,
self
.
_hidden_size
*
4
],
shape
=
[
self
.
_hidden_size
*
2
,
self
.
_hidden_size
*
4
],
dtype
=
"float32"
,
dtype
=
"float32"
,
name
=
"fc_weight1_"
+
str
(
i
),
default_initializer
=
fluid
.
initializer
.
UniformInitializer
(
default_initializer
=
fluid
.
initializer
.
UniformInitializer
(
low
=-
self
.
_init_scale
,
high
=
self
.
_init_scale
))
low
=-
self
.
_init_scale
,
high
=
self
.
_init_scale
))
self
.
weight_1_arr
.
append
(
weight_1
)
self
.
weight_1_arr
.
append
(
weight_1
)
bias_1
=
fluid
.
layers
.
create_parameter
(
bias_1
=
self
.
_helper
.
create_parameter
(
[
self
.
_hidden_size
*
4
],
attr
=
fluid
.
ParamAttr
(
initializer
=
fluid
.
initializer
.
UniformInitializer
(
low
=-
self
.
_init_scale
,
high
=
self
.
_init_scale
)),
shape
=
[
self
.
_hidden_size
*
4
],
dtype
=
"float32"
,
dtype
=
"float32"
,
name
=
"fc_bias1_"
+
str
(
i
),
default_initializer
=
fluid
.
initializer
.
Constant
(
0.0
))
default_initializer
=
fluid
.
initializer
.
Constant
(
0.0
))
self
.
bias_arr
.
append
(
bias_1
)
self
.
bias_arr
.
append
(
bias_1
)
...
@@ -137,6 +143,8 @@ class PtbModel(fluid.imperative.Layer):
...
@@ -137,6 +143,8 @@ class PtbModel(fluid.imperative.Layer):
self
.
num_layers
=
num_layers
self
.
num_layers
=
num_layers
self
.
num_steps
=
num_steps
self
.
num_steps
=
num_steps
self
.
dropout
=
dropout
self
.
dropout
=
dropout
from
paddle.fluid.layer_helper
import
LayerHelper
self
.
_helper
=
LayerHelper
(
'PtbModel'
,
act
=
"tanh"
)
self
.
simple_lstm_rnn
=
SimpleLSTMRNN
(
self
.
simple_lstm_rnn
=
SimpleLSTMRNN
(
hidden_size
,
hidden_size
,
num_steps
,
num_steps
,
...
@@ -151,16 +159,16 @@ class PtbModel(fluid.imperative.Layer):
...
@@ -151,16 +159,16 @@ class PtbModel(fluid.imperative.Layer):
name
=
'embedding_para'
,
name
=
'embedding_para'
,
initializer
=
fluid
.
initializer
.
UniformInitializer
(
initializer
=
fluid
.
initializer
.
UniformInitializer
(
low
=-
init_scale
,
high
=
init_scale
)))
low
=-
init_scale
,
high
=
init_scale
)))
self
.
softmax_weight
=
fluid
.
layers
.
create_parameter
(
self
.
softmax_weight
=
self
.
_helper
.
create_parameter
(
[
self
.
hidden_size
,
self
.
vocab_size
],
attr
=
fluid
.
ParamAttr
(),
shape
=
[
self
.
hidden_size
,
self
.
vocab_size
],
dtype
=
"float32"
,
dtype
=
"float32"
,
name
=
"softmax_weight"
,
default_initializer
=
fluid
.
initializer
.
UniformInitializer
(
default_initializer
=
fluid
.
initializer
.
UniformInitializer
(
low
=-
self
.
init_scale
,
high
=
self
.
init_scale
))
low
=-
self
.
init_scale
,
high
=
self
.
init_scale
))
self
.
softmax_bias
=
fluid
.
layers
.
create_parameter
(
self
.
softmax_bias
=
self
.
_helper
.
create_parameter
(
[
self
.
vocab_size
],
attr
=
fluid
.
ParamAttr
(),
shape
=
[
self
.
vocab_size
],
dtype
=
"float32"
,
dtype
=
"float32"
,
name
=
'softmax_bias'
,
default_initializer
=
fluid
.
initializer
.
UniformInitializer
(
default_initializer
=
fluid
.
initializer
.
UniformInitializer
(
low
=-
self
.
init_scale
,
high
=
self
.
init_scale
))
low
=-
self
.
init_scale
,
high
=
self
.
init_scale
))
...
@@ -256,7 +264,6 @@ class TestImperativePtbRnn(unittest.TestCase):
...
@@ -256,7 +264,6 @@ class TestImperativePtbRnn(unittest.TestCase):
with
new_program_scope
():
with
new_program_scope
():
fluid
.
default_startup_program
().
random_seed
=
seed
fluid
.
default_startup_program
().
random_seed
=
seed
fluid
.
default_main_program
().
random_seed
=
seed
fluid
.
default_main_program
().
random_seed
=
seed
# TODO: marsyang1993 Change seed to
ptb_model
=
PtbModel
(
ptb_model
=
PtbModel
(
hidden_size
=
hidden_size
,
hidden_size
=
hidden_size
,
vocab_size
=
vocab_size
,
vocab_size
=
vocab_size
,
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录