-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathget_opus15_mean.py
54 lines (43 loc) · 1.71 KB
/
get_opus15_mean.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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
import argparse
HIGH = list({'eu', 'pt', 'bg', 'sk', 'zh', 'sl', 'de', 'hr'})
LOW = list({'nb', 'ga', 'rw', 'as'})
VERY_LOW= list({'fy', 'mr', 'se'})
ALL = HIGH+LOW+VERY_LOW
def get_m15_mean(args):
all_bleu_scores = []
high_bleu_scores = []
low_bleu_scores = []
very_low_bleu_scores = []
for lang in ALL:
try:
if args.engtgt:
src, tgt = lang, "en"
bleu_file = f"/predict.{tgt}-{src}.{tgt}.bleu"
else:
src, tgt = "en", lang
bleu_file = f"/predict.{src}-{tgt}.{tgt}.bleu"
## BLEU
with open(args.input + bleu_file) as f:
l = f.readlines()
bleu = float(l[0].split("=")[1].split(" ")[1])
all_bleu_scores.append(bleu)
if lang in LOW:
low_bleu_scores.append(bleu)
if lang in VERY_LOW:
very_low_bleu_scores.append(bleu)
elif lang in HIGH:
high_bleu_scores.append(bleu)
except:
print("No results for the language {}".format(lang))
def get_mean(scores):
return round(sum(scores)/len(scores) ,2)
print(f"Avg of all BLEU is {get_mean(all_bleu_scores)}")
print(f"Avg of high resource BLEU is {get_mean(high_bleu_scores)}")
print(f"Avg of low resource BLEU is {get_mean(low_bleu_scores)}")
print(f"Avg of very low resource is {get_mean(very_low_bleu_scores)}")
if __name__ == "__main__":
parser = argparse.ArgumentParser()
parser.add_argument('--input', type=str, required=True, help='input folder')
parser.add_argument('--engtgt', type=int, default=0, help='eng is tgt')
args = parser.parse_args()
get_m15_mean(args)