-
Notifications
You must be signed in to change notification settings - Fork 4
/
comp_acc.py
29 lines (26 loc) · 913 Bytes
/
comp_acc.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
import csv
import sys
import numpy as np
method_type = sys.argv[1]
suffixes = [".dev.ctx_eval_long.csv", ".dev.ctx_eval_short.csv", ".train.ctx_eval_long.csv"]
total_cnt = 0
total_correct = 0
for suffix in suffixes:
fname = f"./output/{method_type}" + suffix
this_cnt = 0
this_correct = 0
with open(fname, "r") as f:
reader = csv.DictReader(f)
for row in reader:
total_cnt += 1
this_cnt += 1
if 'map-answer' in row:
if row['map-answer'] == row['gold']:
total_correct += 1
this_correct += 1
else:
if row['answer'] == row['gold']:
total_correct += 1
this_correct += 1
print(f"File: {fname}, accuracy: {np.round(this_correct / this_cnt, 3)*100}")
print(f"Total accuracy: {np.round(total_correct / total_cnt, 3)*100}")