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
dbe96371
Commit
dbe96371
authored
Jul 20, 2018
by
Alexei Baevski
Committed by
Myle Ott
Jul 25, 2018
Browse files
option to print language model words and their log probs during evaluation
parent
e7b494f8
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
18 additions
and
0 deletions
+18
-0
eval_lm.py
eval_lm.py
+16
-0
fairseq/options.py
fairseq/options.py
+2
-0
No files found.
eval_lm.py
View file @
dbe96371
...
@@ -60,8 +60,10 @@ def main(args):
...
@@ -60,8 +60,10 @@ def main(args):
if
args
.
remove_bpe
is
not
None
:
if
args
.
remove_bpe
is
not
None
:
bpe_cont
=
args
.
remove_bpe
.
rstrip
()
bpe_cont
=
args
.
remove_bpe
.
rstrip
()
bpe_toks
=
set
(
i
for
i
in
range
(
len
(
task
.
dictionary
))
if
task
.
dictionary
[
i
].
endswith
(
bpe_cont
))
bpe_toks
=
set
(
i
for
i
in
range
(
len
(
task
.
dictionary
))
if
task
.
dictionary
[
i
].
endswith
(
bpe_cont
))
bpe_len
=
len
(
bpe_cont
)
else
:
else
:
bpe_toks
=
None
bpe_toks
=
None
bpe_len
=
0
with
progress_bar
.
build_progress_bar
(
args
,
itr
)
as
t
:
with
progress_bar
.
build_progress_bar
(
args
,
itr
)
as
t
:
results
=
scorer
.
score_batched_itr
(
t
,
cuda
=
use_cuda
,
timer
=
gen_timer
)
results
=
scorer
.
score_batched_itr
(
t
,
cuda
=
use_cuda
,
timer
=
gen_timer
)
...
@@ -85,6 +87,20 @@ def main(args):
...
@@ -85,6 +87,20 @@ def main(args):
pos_scores
=
pos_scores
[(
~
inf_scores
).
nonzero
()]
pos_scores
=
pos_scores
[(
~
inf_scores
).
nonzero
()]
score_sum
+=
pos_scores
.
sum
()
score_sum
+=
pos_scores
.
sum
()
count
+=
pos_scores
.
numel
()
-
skipped_toks
count
+=
pos_scores
.
numel
()
-
skipped_toks
if
args
.
output_word_probs
:
w
=
''
word_prob
=
[]
for
i
in
range
(
len
(
hypo
[
'tokens'
])):
w_ind
=
hypo
[
'tokens'
][
i
].
item
()
w
+=
task
.
dictionary
[
w_ind
]
if
bpe_toks
is
not
None
and
w_ind
in
bpe_toks
:
w
=
w
[:
-
bpe_len
]
else
:
word_prob
.
append
((
w
,
pos_scores
[
i
].
item
()))
w
=
''
print
(
'
\t
'
.
join
(
'{} [{:2f}]'
.
format
(
x
[
0
],
x
[
1
])
for
x
in
word_prob
))
wps_meter
.
update
(
src_tokens
.
size
(
0
))
wps_meter
.
update
(
src_tokens
.
size
(
0
))
t
.
log
({
'wps'
:
round
(
wps_meter
.
avg
)})
t
.
log
({
'wps'
:
round
(
wps_meter
.
avg
)})
...
...
fairseq/options.py
View file @
dbe96371
...
@@ -249,6 +249,8 @@ def add_common_eval_args(group):
...
@@ -249,6 +249,8 @@ def add_common_eval_args(group):
def
add_eval_lm_args
(
parser
):
def
add_eval_lm_args
(
parser
):
group
=
parser
.
add_argument_group
(
'LM Evaluation'
)
group
=
parser
.
add_argument_group
(
'LM Evaluation'
)
add_common_eval_args
(
group
)
add_common_eval_args
(
group
)
group
.
add_argument
(
'--output-word-probs'
,
action
=
'store_true'
,
help
=
'if set, outputs words and their predicted log probabilities to standard output'
)
def
add_generation_args
(
parser
):
def
add_generation_args
(
parser
):
...
...
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