File size: 746 Bytes
c672573
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
VALID = {"coherent","incoherent"}

def score(predictions, references):
    ref = {r["uid"]: r for r in references}
    total = 0
    correct = 0
    invalid = 0

    for p in predictions:
        uid = p["uid"]
        if uid not in ref:
            continue
        gt = ref[uid]["ground_truth_label"]
        if not gt:
            continue
        total += 1
        pred = str(p.get("model_response","")).strip().lower()
        if pred not in VALID:
            invalid += 1
            continue
        if pred == gt:
            correct += 1

    return {
        "accuracy": correct/total if total else 0,
        "n_scored": total,
        "invalid_rate": invalid/total if total else 0,
        "labels": ["coherent","incoherent"]
    }