ClarusC64 commited on
Commit
30cf57f
·
verified ·
1 Parent(s): 7d192b5

Create scorer.py

Browse files
Files changed (1) hide show
  1. scorer.py +51 -0
scorer.py ADDED
@@ -0,0 +1,51 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from dataclasses import dataclass
2
+ from typing import Dict, Any, List
3
+ import re
4
+
5
+ REQ = [
6
+ "crowded_agent_type",
7
+ "capacity_utilization_score",
8
+ "reversal_risk_score",
9
+ "unwind_trigger_conditions",
10
+ "time_to_capacity_event_hours",
11
+ ]
12
+
13
+ AGENTS = ["cta_trend", "options_hedging", "distressed_seller", "market_maker", "fundamental_growth"]
14
+
15
+ @dataclass
16
+ class ScoreResult:
17
+ score: float
18
+ details: Dict[str, Any]
19
+
20
+ def _has_float_0_1(p: str) -> bool:
21
+ return bool(re.search(r"\b0\.\d+\b", p)) or "1.0" in p
22
+
23
+ def _has_agent(p: str) -> bool:
24
+ return any(a in p for a in AGENTS)
25
+
26
+ def _has_time(p: str) -> bool:
27
+ return "hour" in p or bool(re.search(r"\b\d+\b", p))
28
+
29
+ def score(sample: Dict[str, Any], prediction: str) -> ScoreResult:
30
+ p = (prediction or "").lower()
31
+ words_ok = len(p.split()) <= 900
32
+
33
+ hits = sum(1 for k in REQ if k in p)
34
+ has_nums = _has_float_0_1(p)
35
+ has_agent = _has_agent(p)
36
+ has_time = _has_time(p)
37
+
38
+ raw = (
39
+ 0.20 * int(words_ok) +
40
+ 0.60 * (hits / len(REQ)) +
41
+ 0.10 * int(has_nums) +
42
+ 0.05 * int(has_agent) +
43
+ 0.05 * int(has_time)
44
+ )
45
+
46
+ return ScoreResult(score=min(1.0, raw), details={"id": sample.get("id"), "hits": hits})
47
+
48
+ def aggregate(results: List[ScoreResult]) -> Dict[str, Any]:
49
+ if not results:
50
+ return {"mean": 0.0, "n": 0}
51
+ return {"mean": sum(r.score for r in results)/len(results), "n": len(results)}