Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
PaddlePaddle
models
提交
5dcaf543
M
models
项目概览
PaddlePaddle
/
models
大约 1 年 前同步成功
通知
222
Star
6828
Fork
2962
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
602
列表
看板
标记
里程碑
合并请求
255
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
M
models
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
602
Issue
602
列表
看板
标记
里程碑
合并请求
255
合并请求
255
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
提交
5dcaf543
编写于
11月 08, 2019
作者:
xujinanne
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
change networks in lstm, modify parameters
上级
59132ca3
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
9 addition
and
15 deletion
+9
-15
dygraph/sentiment/main.py
dygraph/sentiment/main.py
+2
-4
dygraph/sentiment/nets.py
dygraph/sentiment/nets.py
+7
-11
未找到文件。
dygraph/sentiment/main.py
浏览文件 @
5dcaf543
...
@@ -147,10 +147,8 @@ def train():
...
@@ -147,10 +147,8 @@ def train():
total_cost
,
total_acc
,
total_num_seqs
=
[],
[],
[]
total_cost
,
total_acc
,
total_num_seqs
=
[],
[],
[]
last_hidden
=
None
last_hidden
=
None
last_cell
=
None
last_cell
=
None
init_hidden_data
=
np
.
zeros
(
init_hidden_data
=
np
.
zeros
((
1
,
args
.
batch_size
,
128
),
dtype
=
'float32'
)
(
1
,
args
.
batch_size
,
128
*
4
),
dtype
=
'float32'
)
init_cell_data
=
np
.
zeros
((
1
,
args
.
batch_size
,
128
),
dtype
=
'float32'
)
init_cell_data
=
np
.
zeros
(
(
1
,
args
.
batch_size
,
128
*
4
),
dtype
=
'float32'
)
for
eop
in
range
(
args
.
epoch
):
for
eop
in
range
(
args
.
epoch
):
time_begin
=
time
.
time
()
time_begin
=
time
.
time
()
for
batch_id
,
data
in
enumerate
(
train_data_generator
()):
for
batch_id
,
data
in
enumerate
(
train_data_generator
()):
...
...
dygraph/sentiment/nets.py
浏览文件 @
5dcaf543
...
@@ -246,7 +246,7 @@ class LSTM(fluid.dygraph.Layer):
...
@@ -246,7 +246,7 @@ class LSTM(fluid.dygraph.Layer):
self
.
hid_dim
=
128
self
.
hid_dim
=
128
self
.
fc_hid_dim
=
96
self
.
fc_hid_dim
=
96
self
.
class_dim
=
2
self
.
class_dim
=
2
self
.
lstm_num_steps
=
1
self
.
lstm_num_steps
=
60
self
.
lstm_num_layers
=
1
self
.
lstm_num_layers
=
1
self
.
batch_size
=
batch_size
self
.
batch_size
=
batch_size
self
.
seq_len
=
seq_len
self
.
seq_len
=
seq_len
...
@@ -256,16 +256,14 @@ class LSTM(fluid.dygraph.Layer):
...
@@ -256,16 +256,14 @@ class LSTM(fluid.dygraph.Layer):
dtype
=
'float32'
,
dtype
=
'float32'
,
param_attr
=
fluid
.
ParamAttr
(
learning_rate
=
30
),
param_attr
=
fluid
.
ParamAttr
(
learning_rate
=
30
),
is_sparse
=
False
)
is_sparse
=
False
)
self
.
_fc1
=
FC
(
self
.
full_name
(),
self
.
_fc1
=
FC
(
self
.
full_name
(),
size
=
self
.
hid_dim
,
num_flatten_dims
=
2
)
size
=
self
.
hid_dim
*
4
,
num_flatten_dims
=
2
)
self
.
_fc2
=
FC
(
self
.
full_name
(),
size
=
self
.
fc_hid_dim
,
act
=
"tanh"
)
self
.
_fc2
=
FC
(
self
.
full_name
(),
size
=
self
.
fc_hid_dim
,
act
=
"tanh"
)
self
.
_fc_prediction
=
FC
(
self
.
full_name
(),
self
.
_fc_prediction
=
FC
(
self
.
full_name
(),
size
=
self
.
class_dim
,
size
=
self
.
class_dim
,
act
=
"softmax"
)
act
=
"softmax"
)
self
.
simple_lstm_rnn
=
SimpleLSTMRNN
(
self
.
simple_lstm_rnn
=
SimpleLSTMRNN
(
self
.
full_name
(),
self
.
full_name
(),
self
.
hid_dim
*
4
,
self
.
hid_dim
,
num_steps
=
self
.
lstm_num_steps
,
num_steps
=
self
.
lstm_num_steps
,
num_layers
=
self
.
lstm_num_layers
,
num_layers
=
self
.
lstm_num_layers
,
init_scale
=
0.1
,
init_scale
=
0.1
,
...
@@ -277,18 +275,16 @@ class LSTM(fluid.dygraph.Layer):
...
@@ -277,18 +275,16 @@ class LSTM(fluid.dygraph.Layer):
mask_emb
=
fluid
.
layers
.
expand
(
mask_emb
=
fluid
.
layers
.
expand
(
to_variable
(
o_np_mask
),
[
1
,
self
.
hid_dim
])
to_variable
(
o_np_mask
),
[
1
,
self
.
hid_dim
])
emb
=
emb
*
mask_emb
emb
=
emb
*
mask_emb
emb
=
fluid
.
layers
.
reshape
(
emb
=
fluid
.
layers
.
reshape
(
emb
,
shape
=
[
-
1
,
self
.
seq_len
,
self
.
hid_dim
])
emb
,
shape
=
[
-
1
,
1
,
self
.
seq_len
,
self
.
hid_dim
])
emb
=
fluid
.
layers
.
reduce_max
(
emb
,
dim
=
1
)
fc_1
=
self
.
_fc1
(
emb
)
fc_1
=
self
.
_fc1
(
emb
)
init_h
=
fluid
.
layers
.
reshape
(
init_h
=
fluid
.
layers
.
reshape
(
init_hidden
,
shape
=
[
self
.
lstm_num_layers
,
-
1
,
self
.
hid_dim
*
4
])
init_hidden
,
shape
=
[
self
.
lstm_num_layers
,
-
1
,
self
.
hid_dim
])
init_c
=
fluid
.
layers
.
reshape
(
init_c
=
fluid
.
layers
.
reshape
(
init_cell
,
shape
=
[
self
.
lstm_num_layers
,
-
1
,
self
.
hid_dim
*
4
])
init_cell
,
shape
=
[
self
.
lstm_num_layers
,
-
1
,
self
.
hid_dim
])
real_res
,
last_hidden
,
last_cell
=
self
.
simple_lstm_rnn
(
fc_1
,
init_h
,
real_res
,
last_hidden
,
last_cell
=
self
.
simple_lstm_rnn
(
fc_1
,
init_h
,
init_c
)
init_c
)
last_hidden
=
fluid
.
layers
.
reshape
(
last_hidden
=
fluid
.
layers
.
reshape
(
last_hidden
,
shape
=
[
-
1
,
self
.
hid_dim
*
4
])
last_hidden
,
shape
=
[
-
1
,
self
.
hid_dim
])
tanh_1
=
fluid
.
layers
.
tanh
(
last_hidden
)
tanh_1
=
fluid
.
layers
.
tanh
(
last_hidden
)
fc_2
=
self
.
_fc2
(
tanh_1
)
fc_2
=
self
.
_fc2
(
tanh_1
)
prediction
=
self
.
_fc_prediction
(
fc_2
)
prediction
=
self
.
_fc_prediction
(
fc_2
)
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录