ClarusC64 commited on
Commit
a31c4da
·
verified ·
1 Parent(s): ceba95b

Create scorer.py

Browse files
Files changed (1) hide show
  1. scorer.py +49 -0
scorer.py ADDED
@@ -0,0 +1,49 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from dataclasses import dataclass
2
+ from typing import Dict, Any, List
3
+ import re
4
+
5
+ REQ = [
6
+ "combination_coherence_score",
7
+ "dominant_response_basin",
8
+ "cross_system_alignment_vector",
9
+ "early_incoherence_flags",
10
+ "net_functional_shift",
11
+ ]
12
+
13
+ @dataclass
14
+ class ScoreResult:
15
+ score: float
16
+ details: Dict[str, Any]
17
+
18
+ def _f(p: str, key: str):
19
+ m = re.search(rf"{key}\s*[:=]\s*(0\.\d+|1\.0)\b", p)
20
+ return float(m.group(1)) if m else None
21
+
22
+ def score(sample: Dict[str, Any], prediction: str) -> ScoreResult:
23
+ p = (prediction or "").lower()
24
+ words_ok = len(p.split()) <= 950
25
+ hits = sum(1 for k in REQ if k in p)
26
+
27
+ coh = _f(p, "combination_coherence_score")
28
+ num_ok = int(coh is not None and 0 <= coh <= 1)
29
+
30
+ basin_ok = int("dominant_response_basin" in p)
31
+ vec_ok = int("cross_system_alignment_vector" in p and ":" in p)
32
+ flags_ok = int("early_incoherence_flags" in p)
33
+ shift_ok = int("net_functional_shift" in p)
34
+
35
+ raw = (
36
+ 0.18 * int(words_ok) +
37
+ 0.42 * (hits / len(REQ)) +
38
+ 0.18 * num_ok +
39
+ 0.08 * basin_ok +
40
+ 0.07 * vec_ok +
41
+ 0.03 * flags_ok +
42
+ 0.04 * shift_ok
43
+ )
44
+ return ScoreResult(score=min(1.0, raw), details={"id": sample.get("id"), "hits": hits})
45
+
46
+ def aggregate(results: List[ScoreResult]) -> Dict[str, Any]:
47
+ if not results:
48
+ return {"mean": 0.0, "n": 0}
49
+ return {"mean": sum(r.score for r in results) / len(results), "n": len(results)}