Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
OpenDAS
Fairseq
Commits
ff2e8cf2
Commit
ff2e8cf2
authored
Oct 17, 2017
by
Myle Ott
Browse files
Fix handling of continuation tokens that precede <unk> in generate.py
parent
8943fc78
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
3 additions
and
3 deletions
+3
-3
generate.py
generate.py
+3
-3
No files found.
generate.py
View file @
ff2e8cf2
...
...
@@ -122,12 +122,12 @@ def main():
display_hypotheses
(
None
,
tokens
,
line
,
None
,
hypos
[:
min
(
len
(
hypos
),
args
.
nbest
)])
else
:
def
maybe_remove_bpe
(
tokens
):
def
maybe_remove_bpe
(
tokens
,
escape_unk
=
False
):
"""Helper for removing BPE symbols from a hypothesis."""
if
args
.
remove_bpe
is
None
:
return
tokens
assert
(
tokens
==
dataset
.
dst_dict
.
pad
()).
sum
()
==
0
hypo_minus_bpe
=
dataset
.
dst_dict
.
string
(
tokens
,
args
.
remove_bpe
)
hypo_minus_bpe
=
dataset
.
dst_dict
.
string
(
tokens
,
args
.
remove_bpe
,
escape_unk
)
return
tokenizer
.
Tokenizer
.
tokenize
(
hypo_minus_bpe
,
dataset
.
dst_dict
,
add_if_not_exist
=
True
)
# Generate and compute BLEU score
...
...
@@ -145,7 +145,7 @@ def main():
for
id
,
src
,
ref
,
hypos
in
translations
:
ref
=
ref
.
int
().
cpu
()
top_hypo
=
hypos
[
0
][
'tokens'
].
int
().
cpu
()
scorer
.
add
(
maybe_remove_bpe
(
ref
),
maybe_remove_bpe
(
top_hypo
))
scorer
.
add
(
maybe_remove_bpe
(
ref
,
escape_unk
=
True
),
maybe_remove_bpe
(
top_hypo
))
display_hypotheses
(
id
,
src
,
None
,
ref
,
hypos
[:
min
(
len
(
hypos
),
args
.
nbest
)])
wps_meter
.
update
(
src
.
size
(
0
))
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment