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
19a3865d
Commit
19a3865d
authored
Oct 23, 2017
by
Myle Ott
Browse files
Only consider EOS in beam search if it's among top-k candidates
parent
f6ac1aec
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
6 additions
and
5 deletions
+6
-5
README.md
README.md
+3
-3
fairseq/sequence_generator.py
fairseq/sequence_generator.py
+3
-2
No files found.
README.md
View file @
19a3865d
...
@@ -152,14 +152,14 @@ $ python generate.py data-bin/wmt14.en-fr.newstest2014 \
...
@@ -152,14 +152,14 @@ $ python generate.py data-bin/wmt14.en-fr.newstest2014 \
--path data-bin/wmt14.en-fr.fconv-py/model.pt \
--path data-bin/wmt14.en-fr.fconv-py/model.pt \
--beam 5 --batch-size 128 --remove-bpe | tee /tmp/gen.out
--beam 5 --batch-size 128 --remove-bpe | tee /tmp/gen.out
...
...
| Translated 3003 sentences (95451 tokens) in 9
4.5
s (10
09.60
tokens/s)
| Translated 3003 sentences (95451 tokens) in 9
3.8
s (10
18.09
tokens/s)
| Generate test with beam=5: BLEU4 = 40.7
0
, 67.7/46.
8
/34.2/25.
4
(BP=1.000, ratio=
1.000
, syslen=81
190
, reflen=81194)
| Generate test with beam=5: BLEU4 = 40.
6
7, 67.7/46.
7
/34.2/25.
3
(BP=1.000, ratio=
0.998
, syslen=81
377
, reflen=81194)
# Scoring with score.py:
# Scoring with score.py:
$ grep ^H /tmp/gen.out | cut -f3- > /tmp/gen.out.sys
$ grep ^H /tmp/gen.out | cut -f3- > /tmp/gen.out.sys
$ grep ^T /tmp/gen.out | cut -f2- > /tmp/gen.out.ref
$ grep ^T /tmp/gen.out | cut -f2- > /tmp/gen.out.ref
$ python score.py --sys /tmp/gen.out.sys --ref /tmp/gen.out.ref
$ python score.py --sys /tmp/gen.out.sys --ref /tmp/gen.out.ref
BLEU4 = 40.7
0
, 67.7/46.
8
/34.2/25.
4
(BP=1.000, ratio=
1.000
, syslen=81
190
, reflen=81194)
BLEU4 = 40.
6
7, 67.7/46.
7
/34.2/25.
3
(BP=1.000, ratio=
0.998
, syslen=81
377
, reflen=81194)
```
```
# Join the fairseq community
# Join the fairseq community
...
...
fairseq/sequence_generator.py
View file @
19a3865d
...
@@ -250,10 +250,11 @@ class SequenceGenerator(object):
...
@@ -250,10 +250,11 @@ class SequenceGenerator(object):
eos_mask
=
cand_indices
.
eq
(
self
.
eos
)
eos_mask
=
cand_indices
.
eq
(
self
.
eos
)
if
step
>=
self
.
minlen
:
if
step
>=
self
.
minlen
:
eos_bbsz_idx
=
buffer
(
'eos_bbsz_idx'
)
eos_bbsz_idx
=
buffer
(
'eos_bbsz_idx'
)
cand_bbsz_idx
.
masked_select
(
eos_mask
,
out
=
eos_bbsz_idx
)
# only consider eos when it's among the top beam_size indices
cand_bbsz_idx
[:,
:
beam_size
].
masked_select
(
eos_mask
[:,
:
beam_size
],
out
=
eos_bbsz_idx
)
if
eos_bbsz_idx
.
numel
()
>
0
:
if
eos_bbsz_idx
.
numel
()
>
0
:
eos_scores
=
buffer
(
'eos_scores'
,
type_of
=
scores
)
eos_scores
=
buffer
(
'eos_scores'
,
type_of
=
scores
)
cand_scores
.
masked_select
(
eos_mask
,
out
=
eos_scores
)
cand_scores
[:,
:
beam_size
]
.
masked_select
(
eos_mask
[:,
:
beam_size
]
,
out
=
eos_scores
)
num_remaining_sent
-=
finalize_hypos
(
step
,
eos_bbsz_idx
,
eos_scores
)
num_remaining_sent
-=
finalize_hypos
(
step
,
eos_bbsz_idx
,
eos_scores
)
assert
num_remaining_sent
>=
0
assert
num_remaining_sent
>=
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