Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
PaddlePaddle
models
提交
468c8269
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看板
提交
468c8269
编写于
9月 29, 2018
作者:
Y
Yibing Liu
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Adapt dam to py3
上级
d65c9edf
变更
5
隐藏空白更改
内联
并排
Showing
5 changed file
with
34 addition
and
19 deletion
+34
-19
fluid/deep_attention_matching_net/model.py
fluid/deep_attention_matching_net/model.py
+9
-9
fluid/deep_attention_matching_net/test_and_evaluate.py
fluid/deep_attention_matching_net/test_and_evaluate.py
+2
-1
fluid/deep_attention_matching_net/train_and_evaluate.py
fluid/deep_attention_matching_net/train_and_evaluate.py
+14
-7
fluid/deep_attention_matching_net/utils/reader.py
fluid/deep_attention_matching_net/utils/reader.py
+5
-1
fluid/deep_attention_matching_net/utils/util.py
fluid/deep_attention_matching_net/utils/util.py
+4
-1
未找到文件。
fluid/deep_attention_matching_net/model.py
浏览文件 @
468c8269
import
cPickle
as
pickle
import
six
import
numpy
as
np
import
paddle.fluid
as
fluid
import
utils.layers
as
layers
...
...
@@ -22,7 +22,7 @@ class Net(object):
mask_cache
=
dict
()
if
self
.
use_mask_cache
else
None
turns_data
=
[]
for
i
in
xrange
(
self
.
_max_turn_num
):
for
i
in
six
.
moves
.
xrange
(
self
.
_max_turn_num
):
turn
=
fluid
.
layers
.
data
(
name
=
"turn_%d"
%
i
,
shape
=
[
self
.
_max_turn_len
,
1
],
...
...
@@ -30,7 +30,7 @@ class Net(object):
turns_data
.
append
(
turn
)
turns_mask
=
[]
for
i
in
xrange
(
self
.
_max_turn_num
):
for
i
in
six
.
moves
.
xrange
(
self
.
_max_turn_num
):
turn_mask
=
fluid
.
layers
.
data
(
name
=
"turn_mask_%d"
%
i
,
shape
=
[
self
.
_max_turn_len
,
1
],
...
...
@@ -57,7 +57,7 @@ class Net(object):
Hr
=
response_emb
Hr_stack
=
[
Hr
]
for
index
in
range
(
self
.
_stack_num
):
for
index
in
six
.
moves
.
x
range
(
self
.
_stack_num
):
Hr
=
layers
.
block
(
name
=
"response_self_stack"
+
str
(
index
),
query
=
Hr
,
...
...
@@ -71,7 +71,7 @@ class Net(object):
# context part
sim_turns
=
[]
for
t
in
xrange
(
self
.
_max_turn_num
):
for
t
in
six
.
moves
.
xrange
(
self
.
_max_turn_num
):
Hu
=
fluid
.
layers
.
embedding
(
input
=
turns_data
[
t
],
size
=
[
self
.
_vocab_size
+
1
,
self
.
_emb_size
],
...
...
@@ -81,7 +81,7 @@ class Net(object):
initializer
=
fluid
.
initializer
.
Normal
(
scale
=
0.1
)))
Hu_stack
=
[
Hu
]
for
index
in
range
(
self
.
_stack_num
):
for
index
in
six
.
moves
.
range
(
self
.
_stack_num
):
# share parameters
Hu
=
layers
.
block
(
name
=
"turn_self_stack"
+
str
(
index
),
...
...
@@ -97,7 +97,7 @@ class Net(object):
# cross attention
r_a_t_stack
=
[]
t_a_r_stack
=
[]
for
index
in
range
(
self
.
_stack_num
+
1
):
for
index
in
six
.
moves
.
range
(
self
.
_stack_num
+
1
):
t_a_r
=
layers
.
block
(
name
=
"t_attend_r_"
+
str
(
index
),
query
=
Hu_stack
[
index
],
...
...
@@ -127,7 +127,7 @@ class Net(object):
t_a_r
=
fluid
.
layers
.
stack
(
t_a_r_stack
,
axis
=
1
)
r_a_t
=
fluid
.
layers
.
stack
(
r_a_t_stack
,
axis
=
1
)
else
:
for
index
in
xrange
(
len
(
t_a_r_stack
)):
for
index
in
six
.
moves
.
xrange
(
len
(
t_a_r_stack
)):
t_a_r_stack
[
index
]
=
fluid
.
layers
.
unsqueeze
(
input
=
t_a_r_stack
[
index
],
axes
=
[
1
])
r_a_t_stack
[
index
]
=
fluid
.
layers
.
unsqueeze
(
...
...
@@ -144,7 +144,7 @@ class Net(object):
if
self
.
use_stack_op
:
sim
=
fluid
.
layers
.
stack
(
sim_turns
,
axis
=
2
)
else
:
for
index
in
xrange
(
len
(
sim_turns
)):
for
index
in
six
.
moves
.
xrange
(
len
(
sim_turns
)):
sim_turns
[
index
]
=
fluid
.
layers
.
unsqueeze
(
input
=
sim_turns
[
index
],
axes
=
[
2
])
# sim shape: [batch_size, 2*(stack_num+2), max_turn_num, max_turn_len, max_turn_len]
...
...
fluid/deep_attention_matching_net/test_and_evaluate.py
浏览文件 @
468c8269
import
os
import
six
import
numpy
as
np
import
time
import
argparse
...
...
@@ -167,7 +168,7 @@ def test(args):
score_path
=
os
.
path
.
join
(
args
.
save_path
,
'score.txt'
)
score_file
=
open
(
score_path
,
'w'
)
for
it
in
xrange
(
test_batch_num
//
dev_count
):
for
it
in
six
.
moves
.
xrange
(
test_batch_num
//
dev_count
):
feed_list
=
[]
for
dev
in
xrange
(
dev_count
):
index
=
it
*
dev_count
+
dev
...
...
fluid/deep_attention_matching_net/train_and_evaluate.py
浏览文件 @
468c8269
import
os
import
six
import
numpy
as
np
import
time
import
argparse
...
...
@@ -6,9 +7,13 @@ import multiprocessing
import
paddle
import
paddle.fluid
as
fluid
import
utils.reader
as
reader
import
cPickle
as
pickle
from
utils.util
import
print_arguments
try
:
import
cPickle
as
pickle
#python 2
except
ImportError
as
e
:
import
pickle
#python 3
from
model
import
Net
...
...
@@ -172,12 +177,12 @@ def train(args):
print
(
time
.
strftime
(
'%Y-%m-%d %H:%M:%S'
,
time
.
localtime
(
time
.
time
())))
step
=
0
for
epoch
in
xrange
(
args
.
num_scan_data
):
for
epoch
in
six
.
moves
.
xrange
(
args
.
num_scan_data
):
shuffle_train
=
reader
.
unison_shuffle
(
train_data
)
train_batches
=
reader
.
build_batches
(
shuffle_train
,
data_conf
)
ave_cost
=
0.0
for
it
in
xrange
(
batch_num
//
dev_count
):
for
it
in
six
.
moves
.
xrange
(
batch_num
//
dev_count
):
feed_list
=
[]
for
dev
in
xrange
(
dev_count
):
index
=
it
*
dev_count
+
dev
...
...
@@ -200,8 +205,9 @@ def train(args):
if
(
args
.
save_path
is
not
None
)
and
(
step
%
save_step
==
0
):
save_path
=
os
.
path
.
join
(
args
.
save_path
,
"step_"
+
str
(
step
))
print
(
"Save model at step %d ... "
%
step
)
print
(
time
.
strftime
(
'%Y-%m-%d %H:%M:%S'
,
time
.
localtime
(
time
.
time
())))
print
(
time
.
strftime
(
'%Y-%m-%d %H:%M:%S'
,
time
.
localtime
(
time
.
time
())))
fluid
.
io
.
save_persistables
(
exe
,
save_path
)
score_path
=
os
.
path
.
join
(
args
.
save_path
,
'score.'
+
str
(
step
))
...
...
@@ -235,8 +241,9 @@ def train(args):
for
p_at
in
result
:
out_file
.
write
(
str
(
p_at
)
+
'
\n
'
)
print
(
'finish evaluation'
)
print
(
time
.
strftime
(
'%Y-%m-%d %H:%M:%S'
,
time
.
localtime
(
time
.
time
())))
print
(
time
.
strftime
(
'%Y-%m-%d %H:%M:%S'
,
time
.
localtime
(
time
.
time
())))
if
__name__
==
'__main__'
:
...
...
fluid/deep_attention_matching_net/utils/reader.py
浏览文件 @
468c8269
import
cPickle
as
pickle
import
numpy
as
np
try
:
import
cPickle
as
pickle
#python 2
except
ImportError
as
e
:
import
pickle
#python 3
def
unison_shuffle
(
data
,
seed
=
None
):
if
seed
is
not
None
:
...
...
fluid/deep_attention_matching_net/utils/util.py
浏览文件 @
468c8269
import
six
def
print_arguments
(
args
):
print
(
'----------- Configuration Arguments -----------'
)
for
arg
,
value
in
sorted
(
vars
(
args
).
iteritems
(
)):
for
arg
,
value
in
sorted
(
six
.
iteritems
(
vars
(
args
)
)):
print
(
'%s: %s'
%
(
arg
,
value
))
print
(
'------------------------------------------------'
)
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录