Skip to content

Commit

Permalink
Update SacreBLEU to 1.5.0 (#775)
Browse files Browse the repository at this point in the history
  • Loading branch information
guillaumekln committed Jan 21, 2021
1 parent 2b95edb commit 717e8b7
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 11 deletions.
26 changes: 16 additions & 10 deletions opennmt/utils/scorers.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,14 @@ def higher_is_better(self):
register_scorer = _SCORERS_REGISTRY.register


def _get_lines(path):
lines = []
with tf.io.gfile.GFile(path) as f:
for line in f:
lines.append(line.rstrip())
return lines


@register_scorer(name="rouge")
class ROUGEScorer(Scorer):
"""ROUGE scorer based on https://github.com/pltrdy/rouge."""
Expand All @@ -79,11 +87,10 @@ def __init__(self):
super().__init__("bleu")

def __call__(self, ref_path, hyp_path):
with tf.io.gfile.GFile(ref_path) as ref_stream, tf.io.gfile.GFile(
hyp_path
) as sys_stream:
bleu = sacrebleu.corpus_bleu(sys_stream, [ref_stream], force=True)
return bleu.score
sys_stream = _get_lines(hyp_path)
ref_stream = _get_lines(ref_path)
bleu = sacrebleu.corpus_bleu(sys_stream, [ref_stream], force=True)
return bleu.score


@register_scorer(name="wer")
Expand All @@ -109,11 +116,10 @@ def __init__(self):
super().__init__("ter")

def __call__(self, ref_path, hyp_path):
with tf.io.gfile.GFile(ref_path) as ref_stream, tf.io.gfile.GFile(
hyp_path
) as sys_stream:
ter = sacrebleu.corpus_ter(sys_stream, [ref_stream])
return ter.score
sys_stream = _get_lines(hyp_path)
ref_stream = _get_lines(ref_path)
ter = sacrebleu.corpus_ter(sys_stream, [ref_stream])
return ter.score

def lower_is_better(self):
return True
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ def get_long_description():
"pyonmttok>=1.23.0,<2;platform_system=='Linux' or platform_system=='Darwin'",
"pyyaml>=5.3,<5.4",
"rouge>=1.0,<2",
"sacrebleu>=1.4.14,<2",
"sacrebleu>=1.5.0,<1.6",
"tensorflow>=2.3,<2.5",
"tensorflow-addons>=0.12,<0.13",
],
Expand Down

0 comments on commit 717e8b7

Please sign in to comment.