Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
PaddlePaddle
models
提交
1853d687
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看板
提交
1853d687
编写于
1月 14, 2020
作者:
X
Xing Wu
提交者:
Guo Sheng
1月 14, 2020
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
dygraph_seq2seq_fix_infer (#4191)
上级
9ab3fa06
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
9 addition
and
12 deletion
+9
-12
dygraph/seq2seq/attention_model.py
dygraph/seq2seq/attention_model.py
+3
-4
dygraph/seq2seq/base_model.py
dygraph/seq2seq/base_model.py
+3
-3
dygraph/seq2seq/infer.py
dygraph/seq2seq/infer.py
+3
-5
未找到文件。
dygraph/seq2seq/attention_model.py
浏览文件 @
1853d687
...
...
@@ -269,9 +269,8 @@ class AttentionModel(fluid.dygraph.Layer):
enc_outputs
=
self
.
tile_beam_merge_with_batch
(
enc_outputs
)
enc_padding_mask
=
self
.
tile_beam_merge_with_batch
(
enc_padding_mask
)
batch_beam_shape
=
(
self
.
batch_size
,
self
.
beam_size
)
batch_beam_shape_1
=
(
self
.
batch_size
,
self
.
beam_size
,
1
)
vocab_size_tensor
=
to_variable
(
np
.
full
((
1
),
self
.
tar_vocab_size
))
start_token_tensor
=
to_variable
(
np
.
full
(
batch_beam_shape
_1
,
self
.
beam_start_token
,
dtype
=
'int64'
))
# remove last dim 1 in v1.7
start_token_tensor
=
to_variable
(
np
.
full
(
batch_beam_shape
,
self
.
beam_start_token
,
dtype
=
'int64'
))
end_token_tensor
=
to_variable
(
np
.
full
(
batch_beam_shape
,
self
.
beam_end_token
,
dtype
=
'int64'
))
step_input
=
self
.
tar_embeder
(
start_token_tensor
)
input_feed
=
to_variable
(
np
.
zeros
((
self
.
batch_size
,
self
.
hidden_size
),
dtype
=
'float32'
))
...
...
@@ -348,7 +347,7 @@ class AttentionModel(fluid.dygraph.Layer):
dec_hidden
,
dec_cell
=
new_dec_hidden
,
new_dec_cell
beam_finished
=
next_finished
beam_state_log_probs
=
next_log_probs
step_input
=
self
.
tar_embeder
(
fluid
.
layers
.
unsqueeze
(
token_indices
,
2
))
# remove unsqueeze in v1.7
step_input
=
self
.
tar_embeder
(
token_indices
)
predicted_ids
.
append
(
token_indices
)
parent_ids
.
append
(
beam_indices
)
...
...
@@ -359,4 +358,4 @@ class AttentionModel(fluid.dygraph.Layer):
return
predicted_ids
else
:
print
(
"not support mode "
,
self
.
mode
)
raise
Exception
(
"not support mode: "
+
self
.
mode
)
\ No newline at end of file
raise
Exception
(
"not support mode: "
+
self
.
mode
)
dygraph/seq2seq/base_model.py
浏览文件 @
1853d687
...
...
@@ -202,7 +202,7 @@ class BaseModel(fluid.dygraph.Layer):
batch_beam_shape
=
(
self
.
batch_size
,
self
.
beam_size
)
#batch_beam_shape_1 = (self.batch_size, self.beam_size, 1)
vocab_size_tensor
=
to_variable
(
np
.
full
((
1
),
self
.
tar_vocab_size
))
start_token_tensor
=
to_variable
(
np
.
full
(
batch_beam_shape
,
self
.
beam_start_token
,
dtype
=
'int64'
))
# remove last dim 1 in v1.7
start_token_tensor
=
to_variable
(
np
.
full
(
batch_beam_shape
,
self
.
beam_start_token
,
dtype
=
'int64'
))
end_token_tensor
=
to_variable
(
np
.
full
(
batch_beam_shape
,
self
.
beam_end_token
,
dtype
=
'int64'
))
step_input
=
self
.
tar_embeder
(
start_token_tensor
)
beam_finished
=
to_variable
(
np
.
full
(
batch_beam_shape
,
0
,
dtype
=
'float32'
))
...
...
@@ -271,7 +271,7 @@ class BaseModel(fluid.dygraph.Layer):
dec_hidden
,
dec_cell
=
new_dec_hidden
,
new_dec_cell
beam_finished
=
next_finished
beam_state_log_probs
=
next_log_probs
step_input
=
self
.
tar_embeder
(
fluid
.
layers
.
unsqueeze
(
token_indices
,
2
)
)
# remove unsqueeze in v1.7
step_input
=
self
.
tar_embeder
(
token_indices
)
# remove unsqueeze in v1.7
predicted_ids
.
append
(
token_indices
)
parent_ids
.
append
(
beam_indices
)
...
...
@@ -282,4 +282,4 @@ class BaseModel(fluid.dygraph.Layer):
return
predicted_ids
else
:
print
(
"not support mode "
,
self
.
mode
)
raise
Exception
(
"not support mode: "
+
self
.
mode
)
\ No newline at end of file
raise
Exception
(
"not support mode: "
+
self
.
mode
)
dygraph/seq2seq/infer.py
浏览文件 @
1853d687
...
...
@@ -70,7 +70,6 @@ def infer():
# So we can set dropout to 0
if
args
.
attention
:
model
=
AttentionModel
(
"attention_model"
,
hidden_size
,
src_vocab_size
,
tar_vocab_size
,
...
...
@@ -82,7 +81,6 @@ def infer():
mode
=
'beam_search'
)
else
:
model
=
BaseModel
(
"base_model"
,
hidden_size
,
src_vocab_size
,
tar_vocab_size
,
...
...
@@ -134,11 +132,11 @@ def infer():
for
batch_id
,
batch
in
enumerate
(
train_data_iter
):
input_data_feed
,
word_num
=
prepare_input
(
batch
,
epoch_id
=
0
)
# import ipdb; ipdb.set_trace()
outputs
=
model
(
input_data_feed
)
for
i
in
range
(
outputs
.
shape
[
0
]):
ins
=
fluid
.
Variable
.
numpy
(
outputs
[
i
]
)
res
=
[
tar_id2vocab
[
e
]
for
e
in
ins
[:,
0
].
reshape
(
-
1
)]
ins
=
outputs
[
i
].
numpy
(
)
res
=
[
tar_id2vocab
[
int
(
e
)
]
for
e
in
ins
[:,
0
].
reshape
(
-
1
)]
new_res
=
[]
for
ele
in
res
:
if
ele
==
"</s>"
:
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录