Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
PaddlePaddle
models
提交
f3c92f11
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看板
提交
f3c92f11
编写于
7月 17, 2019
作者:
G
guoshengCS
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Fix text decoding in Transformer under python3.
上级
03dbae4c
变更
6
显示空白变更内容
内联
并排
Showing
6 changed file
with
36 addition
and
44 deletion
+36
-44
PaddleNLP/neural_machine_translation/transformer/infer.py
PaddleNLP/neural_machine_translation/transformer/infer.py
+4
-4
PaddleNLP/neural_machine_translation/transformer/reader.py
PaddleNLP/neural_machine_translation/transformer/reader.py
+10
-14
PaddleNLP/neural_machine_translation/transformer/train.py
PaddleNLP/neural_machine_translation/transformer/train.py
+4
-4
PaddleNLP/unarchived/neural_machine_translation/transformer/infer.py
...narchived/neural_machine_translation/transformer/infer.py
+4
-4
PaddleNLP/unarchived/neural_machine_translation/transformer/reader.py
...archived/neural_machine_translation/transformer/reader.py
+10
-14
PaddleNLP/unarchived/neural_machine_translation/transformer/train.py
...narchived/neural_machine_translation/transformer/train.py
+4
-4
未找到文件。
PaddleNLP/neural_machine_translation/transformer/infer.py
浏览文件 @
f3c92f11
...
@@ -48,14 +48,14 @@ def parse_args():
...
@@ -48,14 +48,14 @@ def parse_args():
help
=
"The buffer size to pool data."
)
help
=
"The buffer size to pool data."
)
parser
.
add_argument
(
parser
.
add_argument
(
"--special_token"
,
"--special_token"
,
type
=
str
,
type
=
lambda
x
:
x
.
encode
()
,
default
=
[
"<s>"
,
"<e>"
,
"<unk>"
],
default
=
[
b
"<s>"
,
b
"<e>"
,
b
"<unk>"
],
nargs
=
3
,
nargs
=
3
,
help
=
"The <bos>, <eos> and <unk> tokens in the dictionary."
)
help
=
"The <bos>, <eos> and <unk> tokens in the dictionary."
)
parser
.
add_argument
(
parser
.
add_argument
(
"--token_delimiter"
,
"--token_delimiter"
,
type
=
lambda
x
:
str
(
x
.
encode
().
decode
(
"unicode-escape"
)
),
type
=
lambda
x
:
x
.
encode
(
),
default
=
" "
,
default
=
b
" "
,
help
=
"The delimiter used to split tokens in source or target sentences. "
help
=
"The delimiter used to split tokens in source or target sentences. "
"For EN-DE BPE data we provided, use spaces as token delimiter. "
)
"For EN-DE BPE data we provided, use spaces as token delimiter. "
)
parser
.
add_argument
(
parser
.
add_argument
(
...
...
PaddleNLP/neural_machine_translation/transformer/reader.py
浏览文件 @
f3c92f11
...
@@ -183,11 +183,11 @@ class DataReader(object):
...
@@ -183,11 +183,11 @@ class DataReader(object):
shuffle_seed
=
None
,
shuffle_seed
=
None
,
shuffle_batch
=
False
,
shuffle_batch
=
False
,
use_token_batch
=
False
,
use_token_batch
=
False
,
field_delimiter
=
"
\t
"
,
field_delimiter
=
b
"
\t
"
,
token_delimiter
=
" "
,
token_delimiter
=
b
" "
,
start_mark
=
"<s>"
,
start_mark
=
b
"<s>"
,
end_mark
=
"<e>"
,
end_mark
=
b
"<e>"
,
unk_mark
=
"<unk>"
,
unk_mark
=
b
"<unk>"
,
seed
=
0
):
seed
=
0
):
self
.
_src_vocab
=
self
.
load_dict
(
src_vocab_fpath
)
self
.
_src_vocab
=
self
.
load_dict
(
src_vocab_fpath
)
self
.
_only_src
=
True
self
.
_only_src
=
True
...
@@ -254,9 +254,9 @@ class DataReader(object):
...
@@ -254,9 +254,9 @@ class DataReader(object):
if
tar_fname
is
None
:
if
tar_fname
is
None
:
raise
Exception
(
"If tar file provided, please set tar_fname."
)
raise
Exception
(
"If tar file provided, please set tar_fname."
)
f
=
tarfile
.
open
(
fpaths
[
0
],
"r"
)
f
=
tarfile
.
open
(
fpaths
[
0
],
"r
b
"
)
for
line
in
f
.
extractfile
(
tar_fname
):
for
line
in
f
.
extractfile
(
tar_fname
):
fields
=
line
.
strip
(
"
\n
"
).
split
(
self
.
_field_delimiter
)
fields
=
line
.
strip
(
b
"
\n
"
).
split
(
self
.
_field_delimiter
)
if
(
not
self
.
_only_src
and
len
(
fields
)
==
2
)
or
(
if
(
not
self
.
_only_src
and
len
(
fields
)
==
2
)
or
(
self
.
_only_src
and
len
(
fields
)
==
1
):
self
.
_only_src
and
len
(
fields
)
==
1
):
yield
fields
yield
fields
...
@@ -267,9 +267,7 @@ class DataReader(object):
...
@@ -267,9 +267,7 @@ class DataReader(object):
with
open
(
fpath
,
"rb"
)
as
f
:
with
open
(
fpath
,
"rb"
)
as
f
:
for
line
in
f
:
for
line
in
f
:
if
six
.
PY3
:
fields
=
line
.
strip
(
b
"
\n
"
).
split
(
self
.
_field_delimiter
)
line
=
line
.
decode
(
"utf8"
,
errors
=
"ignore"
)
fields
=
line
.
strip
(
"
\n
"
).
split
(
self
.
_field_delimiter
)
if
(
not
self
.
_only_src
and
len
(
fields
)
==
2
)
or
(
if
(
not
self
.
_only_src
and
len
(
fields
)
==
2
)
or
(
self
.
_only_src
and
len
(
fields
)
==
1
):
self
.
_only_src
and
len
(
fields
)
==
1
):
yield
fields
yield
fields
...
@@ -279,12 +277,10 @@ class DataReader(object):
...
@@ -279,12 +277,10 @@ class DataReader(object):
word_dict
=
{}
word_dict
=
{}
with
open
(
dict_path
,
"rb"
)
as
fdict
:
with
open
(
dict_path
,
"rb"
)
as
fdict
:
for
idx
,
line
in
enumerate
(
fdict
):
for
idx
,
line
in
enumerate
(
fdict
):
if
six
.
PY3
:
line
=
line
.
decode
(
"utf8"
,
errors
=
"ignore"
)
if
reverse
:
if
reverse
:
word_dict
[
idx
]
=
line
.
strip
(
"
\n
"
)
word_dict
[
idx
]
=
line
.
strip
(
b
"
\n
"
)
else
:
else
:
word_dict
[
line
.
strip
(
"
\n
"
)]
=
idx
word_dict
[
line
.
strip
(
b
"
\n
"
)]
=
idx
return
word_dict
return
word_dict
def
batch_generator
(
self
):
def
batch_generator
(
self
):
...
...
PaddleNLP/neural_machine_translation/transformer/train.py
浏览文件 @
f3c92f11
...
@@ -86,14 +86,14 @@ def parse_args():
...
@@ -86,14 +86,14 @@ def parse_args():
help
=
"The flag indicating whether to shuffle the data batches."
)
help
=
"The flag indicating whether to shuffle the data batches."
)
parser
.
add_argument
(
parser
.
add_argument
(
"--special_token"
,
"--special_token"
,
type
=
str
,
type
=
lambda
x
:
x
.
encode
()
,
default
=
[
"<s>"
,
"<e>"
,
"<unk>"
],
default
=
[
b
"<s>"
,
b
"<e>"
,
b
"<unk>"
],
nargs
=
3
,
nargs
=
3
,
help
=
"The <bos>, <eos> and <unk> tokens in the dictionary."
)
help
=
"The <bos>, <eos> and <unk> tokens in the dictionary."
)
parser
.
add_argument
(
parser
.
add_argument
(
"--token_delimiter"
,
"--token_delimiter"
,
type
=
lambda
x
:
str
(
x
.
encode
().
decode
(
"unicode-escape"
)
),
type
=
lambda
x
:
x
.
encode
(
),
default
=
" "
,
default
=
b
" "
,
help
=
"The delimiter used to split tokens in source or target sentences. "
help
=
"The delimiter used to split tokens in source or target sentences. "
"For EN-DE BPE data we provided, use spaces as token delimiter. "
)
"For EN-DE BPE data we provided, use spaces as token delimiter. "
)
parser
.
add_argument
(
parser
.
add_argument
(
...
...
PaddleNLP/unarchived/neural_machine_translation/transformer/infer.py
浏览文件 @
f3c92f11
...
@@ -46,14 +46,14 @@ def parse_args():
...
@@ -46,14 +46,14 @@ def parse_args():
help
=
"The buffer size to pool data."
)
help
=
"The buffer size to pool data."
)
parser
.
add_argument
(
parser
.
add_argument
(
"--special_token"
,
"--special_token"
,
type
=
str
,
type
=
lambda
x
:
x
.
encode
()
,
default
=
[
"<s>"
,
"<e>"
,
"<unk>"
],
default
=
[
b
"<s>"
,
b
"<e>"
,
b
"<unk>"
],
nargs
=
3
,
nargs
=
3
,
help
=
"The <bos>, <eos> and <unk> tokens in the dictionary."
)
help
=
"The <bos>, <eos> and <unk> tokens in the dictionary."
)
parser
.
add_argument
(
parser
.
add_argument
(
"--token_delimiter"
,
"--token_delimiter"
,
type
=
lambda
x
:
str
(
x
.
encode
().
decode
(
"unicode-escape"
)
),
type
=
lambda
x
:
x
.
encode
(
),
default
=
" "
,
default
=
b
" "
,
help
=
"The delimiter used to split tokens in source or target sentences. "
help
=
"The delimiter used to split tokens in source or target sentences. "
"For EN-DE BPE data we provided, use spaces as token delimiter. "
)
"For EN-DE BPE data we provided, use spaces as token delimiter. "
)
parser
.
add_argument
(
parser
.
add_argument
(
...
...
PaddleNLP/unarchived/neural_machine_translation/transformer/reader.py
浏览文件 @
f3c92f11
...
@@ -182,11 +182,11 @@ class DataReader(object):
...
@@ -182,11 +182,11 @@ class DataReader(object):
shuffle
=
True
,
shuffle
=
True
,
shuffle_batch
=
False
,
shuffle_batch
=
False
,
use_token_batch
=
False
,
use_token_batch
=
False
,
field_delimiter
=
"
\t
"
,
field_delimiter
=
b
"
\t
"
,
token_delimiter
=
" "
,
token_delimiter
=
b
" "
,
start_mark
=
"<s>"
,
start_mark
=
b
"<s>"
,
end_mark
=
"<e>"
,
end_mark
=
b
"<e>"
,
unk_mark
=
"<unk>"
,
unk_mark
=
b
"<unk>"
,
seed
=
0
):
seed
=
0
):
self
.
_src_vocab
=
self
.
load_dict
(
src_vocab_fpath
)
self
.
_src_vocab
=
self
.
load_dict
(
src_vocab_fpath
)
self
.
_only_src
=
True
self
.
_only_src
=
True
...
@@ -252,9 +252,9 @@ class DataReader(object):
...
@@ -252,9 +252,9 @@ class DataReader(object):
if
tar_fname
is
None
:
if
tar_fname
is
None
:
raise
Exception
(
"If tar file provided, please set tar_fname."
)
raise
Exception
(
"If tar file provided, please set tar_fname."
)
f
=
tarfile
.
open
(
fpaths
[
0
],
"r"
)
f
=
tarfile
.
open
(
fpaths
[
0
],
"r
b
"
)
for
line
in
f
.
extractfile
(
tar_fname
):
for
line
in
f
.
extractfile
(
tar_fname
):
fields
=
line
.
strip
(
"
\n
"
).
split
(
self
.
_field_delimiter
)
fields
=
line
.
strip
(
b
"
\n
"
).
split
(
self
.
_field_delimiter
)
if
(
not
self
.
_only_src
and
len
(
fields
)
==
2
)
or
(
if
(
not
self
.
_only_src
and
len
(
fields
)
==
2
)
or
(
self
.
_only_src
and
len
(
fields
)
==
1
):
self
.
_only_src
and
len
(
fields
)
==
1
):
yield
fields
yield
fields
...
@@ -265,9 +265,7 @@ class DataReader(object):
...
@@ -265,9 +265,7 @@ class DataReader(object):
with
open
(
fpath
,
"rb"
)
as
f
:
with
open
(
fpath
,
"rb"
)
as
f
:
for
line
in
f
:
for
line
in
f
:
if
six
.
PY3
:
fields
=
line
.
strip
(
b
"
\n
"
).
split
(
self
.
_field_delimiter
)
line
=
line
.
decode
(
"utf8"
,
errors
=
"ignore"
)
fields
=
line
.
strip
(
"
\n
"
).
split
(
self
.
_field_delimiter
)
if
(
not
self
.
_only_src
and
len
(
fields
)
==
2
)
or
(
if
(
not
self
.
_only_src
and
len
(
fields
)
==
2
)
or
(
self
.
_only_src
and
len
(
fields
)
==
1
):
self
.
_only_src
and
len
(
fields
)
==
1
):
yield
fields
yield
fields
...
@@ -277,12 +275,10 @@ class DataReader(object):
...
@@ -277,12 +275,10 @@ class DataReader(object):
word_dict
=
{}
word_dict
=
{}
with
open
(
dict_path
,
"rb"
)
as
fdict
:
with
open
(
dict_path
,
"rb"
)
as
fdict
:
for
idx
,
line
in
enumerate
(
fdict
):
for
idx
,
line
in
enumerate
(
fdict
):
if
six
.
PY3
:
line
=
line
.
decode
(
"utf8"
,
errors
=
"ignore"
)
if
reverse
:
if
reverse
:
word_dict
[
idx
]
=
line
.
strip
(
"
\n
"
)
word_dict
[
idx
]
=
line
.
strip
(
b
"
\n
"
)
else
:
else
:
word_dict
[
line
.
strip
(
"
\n
"
)]
=
idx
word_dict
[
line
.
strip
(
b
"
\n
"
)]
=
idx
return
word_dict
return
word_dict
def
batch_generator
(
self
):
def
batch_generator
(
self
):
...
...
PaddleNLP/unarchived/neural_machine_translation/transformer/train.py
浏览文件 @
f3c92f11
...
@@ -74,14 +74,14 @@ def parse_args():
...
@@ -74,14 +74,14 @@ def parse_args():
help
=
"The flag indicating whether to shuffle the data batches."
)
help
=
"The flag indicating whether to shuffle the data batches."
)
parser
.
add_argument
(
parser
.
add_argument
(
"--special_token"
,
"--special_token"
,
type
=
str
,
type
=
lambda
x
:
x
.
encode
()
,
default
=
[
"<s>"
,
"<e>"
,
"<unk>"
],
default
=
[
b
"<s>"
,
b
"<e>"
,
b
"<unk>"
],
nargs
=
3
,
nargs
=
3
,
help
=
"The <bos>, <eos> and <unk> tokens in the dictionary."
)
help
=
"The <bos>, <eos> and <unk> tokens in the dictionary."
)
parser
.
add_argument
(
parser
.
add_argument
(
"--token_delimiter"
,
"--token_delimiter"
,
type
=
lambda
x
:
str
(
x
.
encode
().
decode
(
"unicode-escape"
)
),
type
=
lambda
x
:
x
.
encode
(
),
default
=
" "
,
default
=
b
" "
,
help
=
"The delimiter used to split tokens in source or target sentences. "
help
=
"The delimiter used to split tokens in source or target sentences. "
"For EN-DE BPE data we provided, use spaces as token delimiter. "
)
"For EN-DE BPE data we provided, use spaces as token delimiter. "
)
parser
.
add_argument
(
parser
.
add_argument
(
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录