Created
March 5, 2019 17:36
-
-
Save allenanie/a348679e1c5178565db7d238222ec380 to your computer and use it in GitHub Desktop.
Calls OpenNMT's multi-bleu.perl script (from Moses) to evaluate
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import argparse | |
""" | |
python report_bleu.py --target_file /mnt/fs5/anie/OpenNMT-py/data/twitter/twitter-seq2seq-2019mar3-clean-tgt-test.txt \ | |
--generated_file /mnt/fs5/anie/OpenNMT-py/save/twitter_transformer_clean_char/twitter_test_mar4_step50000_greedy_word_level.txt \ | |
--base_dir /home/anie/OpenNMT-py | |
""" | |
parser = argparse.ArgumentParser(description='Clean Seq2Seq data') | |
parser.add_argument('--target_file', type=str, help="target evaluation file") | |
parser.add_argument('--generated_file', type=str, help="file generated by the system") | |
parser.add_argument('--base_dir', type=str, help="OpenNMT base directory") | |
args = parser.parse_args() | |
def report_bleu(tgt_path): | |
import subprocess | |
# Rollback pointer to the beginning. | |
with open(args.generated_file) as out_file: | |
out_file.seek(0) | |
print() | |
res = subprocess.check_output( | |
"perl %s/tools/multi-bleu.perl %s" % (args.base_dir, tgt_path), | |
stdin=out_file, shell=True | |
).decode("utf-8") | |
msg = ">> " + res.strip() | |
print(msg) | |
if __name__ == '__main__': | |
report_bleu(args.target_file) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment