-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcalc_acc2.py
More file actions
34 lines (26 loc) · 1.06 KB
/
Copy pathcalc_acc2.py
File metadata and controls
34 lines (26 loc) · 1.06 KB
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
import json
import glob
with open("annotation/annotations.json") as f:
annotations = json.load(f)
q_dict = {q["sample_id"]: q for q in annotations if q.get("task_type") == "yes_no"}
for result_file in glob.glob("results/*_hf_results.json"):
with open(result_file) as f:
results = json.load(f)
r_dict = {r["sample_id"]: r["model_answer"] for r in results}
correct = 0
total = 0
for sid, q in q_dict.items():
if sid in r_dict:
total += 1
gt = q["answer"].strip().lower()
pred = r_dict[sid].strip().lower()
if "yes" in pred and "no" not in pred:
parsed_pred = "yes"
elif "no" in pred and "yes" not in pred:
parsed_pred = "no"
else:
parsed_pred = pred
if gt == parsed_pred:
correct += 1
model_name = result_file.split("/")[-1].replace("_results.json", "")
print(f"{model_name:>20} Yes/No Accuracy: {correct}/{total} = {correct/total if total else 0:.4f}")