ClarusC64 commited on
Commit
c672573
·
verified ·
1 Parent(s): 2b4b58a

Create scorer.py

Browse files
Files changed (1) hide show
  1. scorer.py +29 -0
scorer.py ADDED
@@ -0,0 +1,29 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ VALID = {"coherent","incoherent"}
2
+
3
+ def score(predictions, references):
4
+ ref = {r["uid"]: r for r in references}
5
+ total = 0
6
+ correct = 0
7
+ invalid = 0
8
+
9
+ for p in predictions:
10
+ uid = p["uid"]
11
+ if uid not in ref:
12
+ continue
13
+ gt = ref[uid]["ground_truth_label"]
14
+ if not gt:
15
+ continue
16
+ total += 1
17
+ pred = str(p.get("model_response","")).strip().lower()
18
+ if pred not in VALID:
19
+ invalid += 1
20
+ continue
21
+ if pred == gt:
22
+ correct += 1
23
+
24
+ return {
25
+ "accuracy": correct/total if total else 0,
26
+ "n_scored": total,
27
+ "invalid_rate": invalid/total if total else 0,
28
+ "labels": ["coherent","incoherent"]
29
+ }