ClarusC64 commited on
Commit
e4ac0ca
·
verified ·
1 Parent(s): 6ecf59e

Create scorer.py

Browse files
Files changed (1) hide show
  1. scorer.py +43 -0
scorer.py ADDED
@@ -0,0 +1,43 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from dataclasses import dataclass
2
+ from typing import Dict, Any, List
3
+ import re
4
+
5
+ REQ = [
6
+ "current_regime_basin",
7
+ "adjacent_regime_targets",
8
+ "trigger_condition_set",
9
+ "transition_probability_24h",
10
+ "transition_probability_72h",
11
+ "projected_post_shift_structure",
12
+ ]
13
+
14
+ @dataclass
15
+ class ScoreResult:
16
+ score: float
17
+ details: Dict[str, Any]
18
+
19
+ def _has_float(p: str) -> bool:
20
+ return bool(re.search(r"\b0\.\d+\b", p)) or "1.0" in p
21
+
22
+ def score(sample: Dict[str, Any], prediction: str) -> ScoreResult:
23
+ p = (prediction or "").lower()
24
+ words_ok = len(p.split()) <= 900
25
+
26
+ hits = sum(1 for k in REQ if k.lower() in p)
27
+
28
+ has_numbers = _has_float(p)
29
+ has_prob = "24h" in p or "72h" in p
30
+
31
+ raw = (
32
+ 0.20 * int(words_ok) +
33
+ 0.55 * (hits / len(REQ)) +
34
+ 0.15 * int(has_numbers) +
35
+ 0.10 * int(has_prob)
36
+ )
37
+
38
+ return ScoreResult(score=min(1.0, raw), details={"id": sample.get("id"), "hits": hits})
39
+
40
+ def aggregate(results: List[ScoreResult]) -> Dict[str, Any]:
41
+ if not results:
42
+ return {"mean": 0.0, "n": 0}
43
+ return {"mean": sum(r.score for r in results)/len(results), "n": len(results)}