-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathBLEU_sentence.py
30 lines (21 loc) · 878 Bytes
/
BLEU_sentence.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
from nltk.translate.bleu_score import sentence_bleu
import argparse
def argparser():
Argparser = argparse.ArgumentParser()
Argparser.add_argument('--reference', type=str, default='summaries.txt', help='Reference File')
Argparser.add_argument('--candidate', type=str, default='candidates.txt', help='Candidate file')
args = Argparser.parse_args()
return args
args = argparser()
reference = open(args.reference, 'r').readlines()
candidate = open(args.candidate, 'r').readlines()
print(reference)
print(len(reference))
print(len(candidate))
#if len(reference) != len(candidate):
# raise ValueError('The number of sentences in both files do not match.')
score = 0.
for i in range(len(reference)):
score += sentence_bleu([reference[i].strip().split()], candidate[i].strip().split())
score /= len(reference)
print("The bleu score is: "+str(score))