-
Notifications
You must be signed in to change notification settings - Fork 23
/
compute_bleu.py
31 lines (28 loc) · 899 Bytes
/
compute_bleu.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
import re
import argparse
import configurations
from subprocess import Popen, PIPE
parser = argparse.ArgumentParser()
parser.add_argument(
"--proto", default="normal_adagrad",
help="Prototype config to use for config")
args = parser.parse_args()
def main(config):
compbleu_cmd = [config['bleu_script_1'],
config['val_set_target'],
config['val_output_orig']]
bleu_subproc = Popen(compbleu_cmd, stdout=PIPE)
while True:
line = bleu_subproc.stdout.readline()
if line != '':
if 'BLEU' in line:
stdout = line
else:
break
bleu_subproc.terminate()
out_parse = re.match(r'BLEU = [-.0-9]+', stdout)
bleu_score = float(out_parse.group()[6:])
print bleu_score
if __name__ == '__main__':
config = getattr(configurations, args.proto)()
main(config)