ClarusC64 commited on
Commit
95c835d
·
verified ·
1 Parent(s): 30e546a

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 = ["polarity", "vector", "speed", "depth", "risk", "driver"]
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()) <= 950
14
+ hits = sum(1 for k in REQ if k in p)
15
+
16
+ has_signed = "+" in p or "-" in p or "0." in p
17
+ has_future = "next" in p or "5" in p or "minutes" in p
18
+
19
+ raw = (
20
+ 0.20 * int(words_ok) +
21
+ 0.55 * (hits / len(REQ)) +
22
+ 0.15 * int(has_signed) +
23
+ 0.10 * int(has_future)
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)}