Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
PaddlePaddle
models
提交
054ba614
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看板
提交
054ba614
编写于
9月 23, 2020
作者:
L
LiuChiaChi
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
correct some args
上级
5a50806e
变更
4
隐藏空白更改
内联
并排
Showing
4 changed file
with
14 addition
and
21 deletion
+14
-21
dygraph/seq2seq/args.py
dygraph/seq2seq/args.py
+0
-6
dygraph/seq2seq/attention_model.py
dygraph/seq2seq/attention_model.py
+1
-3
dygraph/seq2seq/reader.py
dygraph/seq2seq/reader.py
+9
-8
dygraph/seq2seq/run.sh
dygraph/seq2seq/run.sh
+4
-4
未找到文件。
dygraph/seq2seq/args.py
浏览文件 @
054ba614
...
@@ -34,12 +34,6 @@ def parse_args():
...
@@ -34,12 +34,6 @@ def parse_args():
parser
.
add_argument
(
"--src_lang"
,
type
=
str
,
help
=
"source language suffix"
)
parser
.
add_argument
(
"--src_lang"
,
type
=
str
,
help
=
"source language suffix"
)
parser
.
add_argument
(
"--tar_lang"
,
type
=
str
,
help
=
"target language suffix"
)
parser
.
add_argument
(
"--tar_lang"
,
type
=
str
,
help
=
"target language suffix"
)
parser
.
add_argument
(
"--attention"
,
type
=
eval
,
default
=
False
,
help
=
"Whether use attention model"
)
parser
.
add_argument
(
parser
.
add_argument
(
"--optimizer"
,
"--optimizer"
,
type
=
str
,
type
=
str
,
...
...
dygraph/seq2seq/attention_model.py
浏览文件 @
054ba614
...
@@ -28,13 +28,12 @@ class AttentionModel(Layer):
...
@@ -28,13 +28,12 @@ class AttentionModel(Layer):
trg_vocab_size
,
trg_vocab_size
,
num_layers
=
1
,
num_layers
=
1
,
init_scale
=
0.1
,
init_scale
=
0.1
,
padding_idx
=
2
,
padding_idx
=
0
,
dropout
=
None
,
dropout
=
None
,
beam_size
=
1
,
beam_size
=
1
,
beam_start_token
=
1
,
beam_start_token
=
1
,
beam_end_token
=
2
,
beam_end_token
=
2
,
beam_max_step_num
=
100
,
beam_max_step_num
=
100
,
mode
=
'train'
,
dtype
=
"float32"
):
dtype
=
"float32"
):
super
(
AttentionModel
,
self
).
__init__
()
super
(
AttentionModel
,
self
).
__init__
()
self
.
hidden_size
=
hidden_size
self
.
hidden_size
=
hidden_size
...
@@ -47,7 +46,6 @@ class AttentionModel(Layer):
...
@@ -47,7 +46,6 @@ class AttentionModel(Layer):
self
.
beam_start_token
=
beam_start_token
self
.
beam_start_token
=
beam_start_token
self
.
beam_end_token
=
beam_end_token
self
.
beam_end_token
=
beam_end_token
self
.
beam_max_step_num
=
beam_max_step_num
self
.
beam_max_step_num
=
beam_max_step_num
self
.
mode
=
mode
self
.
kinf
=
1e9
self
.
kinf
=
1e9
self
.
encoder
=
Encoder
(
src_vocab_size
,
hidden_size
,
num_layers
,
self
.
encoder
=
Encoder
(
src_vocab_size
,
hidden_size
,
num_layers
,
...
...
dygraph/seq2seq/reader.py
浏览文件 @
054ba614
...
@@ -125,14 +125,14 @@ def raw_data(src_lang,
...
@@ -125,14 +125,14 @@ def raw_data(src_lang,
src_vocab
=
_build_vocab
(
src_vocab_file
)
src_vocab
=
_build_vocab
(
src_vocab_file
)
tar_vocab
=
_build_vocab
(
tar_vocab_file
)
tar_vocab
=
_build_vocab
(
tar_vocab_file
)
train_src
,
train_tar
=
_para_file_to_ids
(
src_train_file
,
tar_train_file
,
\
train_src
,
train_tar
=
_para_file_to_ids
(
src_train_file
,
tar_train_file
,
\
src_vocab
,
tar_vocab
)
src_vocab
,
tar_vocab
)
train_src
,
train_tar
=
filter_len
(
train_src
,
train_tar
=
filter_len
(
train_src
,
train_tar
,
max_sequence_len
=
max_sequence_len
)
train_src
,
train_tar
,
max_sequence_len
=
max_sequence_len
)
eval_src
,
eval_tar
=
_para_file_to_ids
(
src_eval_file
,
tar_eval_file
,
\
eval_src
,
eval_tar
=
_para_file_to_ids
(
src_eval_file
,
tar_eval_file
,
\
src_vocab
,
tar_vocab
)
src_vocab
,
tar_vocab
)
test_src
,
test_tar
=
_para_file_to_ids
(
src_test_file
,
tar_test_file
,
\
test_src
,
test_tar
=
_para_file_to_ids
(
src_test_file
,
tar_test_file
,
\
src_vocab
,
tar_vocab
)
src_vocab
,
tar_vocab
)
return
(
train_src
,
train_tar
),
(
eval_src
,
eval_tar
),
(
test_src
,
test_tar
),
\
return
(
train_src
,
train_tar
),
(
eval_src
,
eval_tar
),
(
test_src
,
test_tar
),
\
...
@@ -143,8 +143,8 @@ def raw_mono_data(vocab_file, file_path):
...
@@ -143,8 +143,8 @@ def raw_mono_data(vocab_file, file_path):
src_vocab
=
_build_vocab
(
vocab_file
)
src_vocab
=
_build_vocab
(
vocab_file
)
test_src
,
test_tar
=
_para_file_to_ids
(
file_path
,
file_path
,
\
test_src
,
test_tar
=
_para_file_to_ids
(
file_path
,
file_path
,
\
src_vocab
,
src_vocab
)
src_vocab
,
src_vocab
)
return
(
test_src
,
test_tar
)
return
(
test_src
,
test_tar
)
...
@@ -160,7 +160,8 @@ class IWSLTDataset(Dataset):
...
@@ -160,7 +160,8 @@ class IWSLTDataset(Dataset):
src_data
,
trg_data
=
raw_data
src_data
,
trg_data
=
raw_data
data_pair
=
[]
data_pair
=
[]
for
src
,
trg
in
zip
(
src_data
,
trg_data
):
for
src
,
trg
in
zip
(
src_data
,
trg_data
):
data_pair
.
append
([
src
,
trg
])
if
len
(
src
)
>
0
:
data_pair
.
append
([
src
,
trg
])
sorted_data_pair
=
sorted
(
data_pair
,
key
=
lambda
k
:
len
(
k
[
0
]))
sorted_data_pair
=
sorted
(
data_pair
,
key
=
lambda
k
:
len
(
k
[
0
]))
src_data
=
[
data_pair
[
0
]
for
data_pair
in
sorted_data_pair
]
src_data
=
[
data_pair
[
0
]
for
data_pair
in
sorted_data_pair
]
...
...
dygraph/seq2seq/run.sh
浏览文件 @
054ba614
...
@@ -3,13 +3,12 @@ export CUDA_VISIBLE_DEVICES=0
...
@@ -3,13 +3,12 @@ export CUDA_VISIBLE_DEVICES=0
python train.py
\
python train.py
\
--src_lang
en
--tar_lang
vi
\
--src_lang
en
--tar_lang
vi
\
--attention
True
\
--num_layers
2
\
--num_layers
2
\
--hidden_size
512
\
--hidden_size
512
\
--src_vocab_size
17191
\
--src_vocab_size
17191
\
--tar_vocab_size
7709
\
--tar_vocab_size
7709
\
--batch_size
128
\
--batch_size
128
\
--dropout
0.
0
\
--dropout
0.
2
\
--init_scale
0.2
\
--init_scale
0.2
\
--max_grad_norm
5.0
\
--max_grad_norm
5.0
\
--train_data_prefix
data/en-vi/train
\
--train_data_prefix
data/en-vi/train
\
...
@@ -20,6 +19,7 @@ python train.py \
...
@@ -20,6 +19,7 @@ python train.py \
--model_path
attention_models
\
--model_path
attention_models
\
--enable_ce
\
--enable_ce
\
--learning_rate
0.002
\
--learning_rate
0.002
\
--dtype
float
64
\
--dtype
float
32
\
--optimizer
adam
\
--optimizer
adam
\
--max_epoch
1
--max_epoch
12
\
--padding_idx
2
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录