-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmetric.py
40 lines (36 loc) · 1.37 KB
/
metric.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
import json
def compute_metric_multiple_choice(output_filename):
with open(output_filename, 'r') as f:
run_results = json.load(f)
total_acc = 0
total_num = 0
for task in run_results:
acc = 0
pred_answers = run_results[task]['pred_answers']
gold_answers = run_results[task]['gold_answers']
for pred, gold in zip(pred_answers, gold_answers):
if pred == gold: acc += 1
print("ACC-%s: %.4f" % (task, acc/len(gold_answers)))
total_acc += acc
total_num += len(gold_answers)
print("ACC-all: %.4f" % (total_acc/total_num))
def compute_metric_bbh(output_filename):
with open(output_filename, 'r') as f:
run_results = json.load(f)
total_acc = 0
total_num = 0
for task in run_results:
acc = 0
pred_answers = run_results[task]['pred_answers']
gold_answers = run_results[task]['gold_answers']
for pred, gold in zip(pred_answers, gold_answers):
if gold.lower() in pred.lower(): acc += 1
print("ACC-%s: %.4f" % (task, acc/len(gold_answers)))
total_acc += acc
total_num += len(gold_answers)
print("ACC-all: %.4f" % (total_acc/total_num))
def compute_metric(benchmark, output_filename):
if benchmark == "bbh":
compute_metric_bbh(output_filename)
else:
compute_metric_multiple_choice(output_filename)