Skip to content
This repository has been archived by the owner on Dec 29, 2022. It is now read-only.

Use a specified filename to store downloaded bleu script. #182

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 8 additions & 3 deletions seq2seq/metrics/bleu.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,14 +30,16 @@
import tensorflow as tf


def moses_multi_bleu(hypotheses, references, lowercase=False):
def moses_multi_bleu(hypotheses, references, lowercase=False,
multi_bleu_path=None):
"""Calculate the bleu score for hypotheses and references
using the MOSES ulti-bleu.perl script.

Args:
hypotheses: A numpy array of strings where each string is a single example.
references: A numpy array of strings where each string is a single example.
lowercase: If true, pass the "-lc" flag to the multi-bleu script
multi_bleu_path: The path to store bleu script. Default to <tempdir>/multi-bleu.perl

Returns:
The BLEU score as a float32 value.
Expand All @@ -48,9 +50,12 @@ def moses_multi_bleu(hypotheses, references, lowercase=False):

# Get MOSES multi-bleu script
try:
multi_bleu_path, _ = urllib.request.urlretrieve(
if multi_bleu_path == None:
multi_bleu_path = os.path.join(tempfile.gettempdir(), "multi-bleu.perl")
urllib.request.urlretrieve(
"https://raw.githubusercontent.com/moses-smt/mosesdecoder/"
"master/scripts/generic/multi-bleu.perl")
"master/scripts/generic/multi-bleu.perl",
multi_bleu_path)
os.chmod(multi_bleu_path, 0o755)
except: #pylint: disable=W0702
tf.logging.info("Unable to fetch multi-bleu.perl script, using local.")
Expand Down