ClarusC64 commited on
Commit
efbe7c5
·
verified ·
1 Parent(s): 62df956

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()) <= 700
12
+
13
+ has_index = "coherence" in p or "index" in p
14
+ has_lag = "lag" in p or "delay" in p
15
+ has_scales = "scale" in p or "local" in p
16
+ has_time = "onset" in p or "year"
17
+ has_conf = "confidence" in p or "warning"
18
+
19
+ raw = (
20
+ 0.15 * int(words_ok) +
21
+ 0.25 * int(has_index) +
22
+ 0.20 * int(has_lag) +
23
+ 0.15 * int(has_scales) +
24
+ 0.15 * int(has_time) +
25
+ 0.10 * int(has_conf)
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)}