ClarusC64 commited on
Commit
3ea581b
·
verified ·
1 Parent(s): 7c4df3a

Create scorer.py

Browse files
Files changed (1) hide show
  1. scorer.py +30 -0
scorer.py ADDED
@@ -0,0 +1,30 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from dataclasses import dataclass
2
+ from typing import Dict, Any, List
3
+
4
+ REQ = ["coherence", "stability", "horizon", "structure", "stabil"]
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
+ words_ok = len(p.split()) <= 900
14
+
15
+ hits = sum(1 for k in REQ if k in p)
16
+ has_numeric = any(c.isdigit() for c in p)
17
+
18
+ raw = (
19
+ 0.25 * int(words_ok) +
20
+ 0.45 * (hits / len(REQ)) +
21
+ 0.20 * int(has_numeric) +
22
+ 0.10 * int("hour" in p or "horizon" in p)
23
+ )
24
+
25
+ return ScoreResult(score=min(1.0, raw), details={"id": sample.get("id"), "hits": hits})
26
+
27
+ def aggregate(results: List[ScoreResult]) -> Dict[str, Any]:
28
+ if not results:
29
+ return {"mean": 0.0, "n": 0}
30
+ return {"mean": sum(r.score for r in results)/len(results), "n": len(results)}