ClarusC64 commited on
Commit
de9cc45
·
verified ·
1 Parent(s): 23d711c

Create scorer.py

Browse files
Files changed (1) hide show
  1. scorer.py +32 -0
scorer.py ADDED
@@ -0,0 +1,32 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from dataclasses import dataclass
2
+ from typing import Dict, Any, List
3
+
4
+ REQ = ["baseline", "latency", "gain"]
5
+
6
+ @dataclass
7
+ class ScoreResult:
8
+ score: float
9
+ details: Dict[str, Any]
10
+
11
+ def score(sample: Dict[str, Any], prediction: str) -> ScoreResult:
12
+ p = (prediction or "").lower()
13
+
14
+ words_ok = len(p.split()) <= 800
15
+ hits = sum(1 for k in REQ if k in p)
16
+
17
+ has_variability = "variability" in p or "variance" in p
18
+ has_cycle = "cycle" in p or "lifetime" in p
19
+
20
+ raw = (
21
+ 0.25 * int(words_ok) +
22
+ 0.45 * (hits / len(REQ)) +
23
+ 0.15 * int(has_variability) +
24
+ 0.15 * int(has_cycle)
25
+ )
26
+
27
+ return ScoreResult(score=min(1.0, raw), details={"id": sample.get("id"), "hits": hits})
28
+
29
+ def aggregate(results: List[ScoreResult]) -> Dict[str, Any]:
30
+ if not results:
31
+ return {"mean": 0.0, "n": 0}
32
+ return {"mean": sum(r.score for r in results)/len(results), "n": len(results)}