ClarusC64 commited on
Commit
02cd4be
·
verified ·
1 Parent(s): d642a64

Update scorer.py

Browse files
Files changed (1) hide show
  1. scorer.py +36 -0
scorer.py CHANGED
@@ -0,0 +1,36 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from dataclasses import dataclass
2
+ from typing import Dict, Any, List
3
+
4
+ GRADIENTS = {"flat", "shallow", "moderate", "moderate_to_steep", "steep", "flat_to_positive"}
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()) <= 800
14
+
15
+ has_traj = "trajectory" in p or "stressed" in p or "decoupling" in p or "collapse" in p
16
+ has_gradient = any(g in p for g in GRADIENTS) or "gradient" in p
17
+ has_levers = ">" in p or "rank" in p or "leverage" in p
18
+ has_gain = "coherence" in p and ("gain" in p or "medium" in p or "high" in p or "low" in p)
19
+ has_tradeoffs = "tradeoff" in p or "cost" in p or "risk" in p
20
+ has_monitor = "monitor" in p or "indicator" in p or "metric" in p
21
+
22
+ raw = (
23
+ 0.15 * int(words_ok) +
24
+ 0.20 * int(has_traj) +
25
+ 0.20 * int(has_gradient) +
26
+ 0.20 * int(has_levers) +
27
+ 0.10 * int(has_gain) +
28
+ 0.10 * int(has_tradeoffs) +
29
+ 0.05 * int(has_monitor)
30
+ )
31
+ return ScoreResult(score=min(1.0, raw), details={"id": sample.get("id")})
32
+
33
+ def aggregate(results: List[ScoreResult]) -> Dict[str, Any]:
34
+ if not results:
35
+ return {"mean": 0.0, "n": 0}
36
+ return {"mean": sum(r.score for r in results) / len(results), "n": len(results)}