Commit c86d70cc authored by Bao-Yu's avatar Bao-Yu Committed by Facebook Github Bot
Browse files

Update generate.py (#831)

Summary:
Repeated use of 'i' in evaluate may cause some problems.
Pull Request resolved: https://github.com/pytorch/fairseq/pull/831

Differential Revision: D15980227

Pulled By: myleott

fbshipit-source-id: 7b6b54a6b54938ad63ed1720d930505b56e5c84b
parent c246df42
...@@ -135,7 +135,7 @@ def main(args): ...@@ -135,7 +135,7 @@ def main(args):
print('T-{}\t{}'.format(sample_id, target_str)) print('T-{}\t{}'.format(sample_id, target_str))
# Process top predictions # Process top predictions
for i, hypo in enumerate(hypos[i][:min(len(hypos), args.nbest)]): for j, hypo in enumerate(hypos[i][:min(len(hypos), args.nbest)]):
hypo_tokens, hypo_str, alignment = utils.post_process_prediction( hypo_tokens, hypo_str, alignment = utils.post_process_prediction(
hypo_tokens=hypo['tokens'].int().cpu(), hypo_tokens=hypo['tokens'].int().cpu(),
src_str=src_str, src_str=src_str,
...@@ -162,7 +162,7 @@ def main(args): ...@@ -162,7 +162,7 @@ def main(args):
)) ))
# Score only the top hypothesis # Score only the top hypothesis
if has_target and i == 0: if has_target and j == 0:
if align_dict is not None or args.remove_bpe is not None: if align_dict is not None or args.remove_bpe is not None:
# Convert back to tokens for evaluation with unk replacement and/or without BPE # Convert back to tokens for evaluation with unk replacement and/or without BPE
target_tokens = tgt_dict.encode_line(target_str, add_if_not_exist=True) target_tokens = tgt_dict.encode_line(target_str, add_if_not_exist=True)
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment