ClarusC64 commited on
Commit
c111baf
·
verified ·
1 Parent(s): 6722af2

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
+ @dataclass
5
+ class ScoreResult:
6
+ score: float
7
+ details: Dict[str, Any]
8
+
9
+ def score(sample: Dict[str, Any], prediction: str) -> ScoreResult:
10
+ p = (prediction or "").lower()
11
+ words_ok = len(p.split()) <= 520
12
+
13
+ has_vector = "drift" in p or "fingerprint" in p
14
+ has_axes = "axis" in p or "system" in p
15
+ has_time = "temporal" in p or "onset" in p or "offset" in p
16
+ has_reversible = "reversible" in p or "rebound" in p
17
+ has_coherence = "coherence" in p or "net" in p
18
+
19
+ raw = (
20
+ 0.15 * int(words_ok) +
21
+ 0.25 * int(has_vector) +
22
+ 0.20 * int(has_axes) +
23
+ 0.20 * int(has_time) +
24
+ 0.10 * int(has_reversible) +
25
+ 0.10 * int(has_coherence)
26
+ )
27
+ return ScoreResult(score=min(1.0, raw), details={"id": sample.get("id")})
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)}