ClarusC64 commited on
Commit
cac9452
·
verified ·
1 Parent(s): f22fb98

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_corr = "correlation" in p or "convergence" in p
14
+ has_div = "diversity" in p or "response" in p
15
+ has_trend = "decline" in p or "trend" in p
16
+ has_time = "onset" in p or "year" in p
17
+ has_tip = "tipping" in p or "proximity" in p
18
+
19
+ raw = (
20
+ 0.15 * int(words_ok) +
21
+ 0.25 * int(has_corr) +
22
+ 0.20 * int(has_div) +
23
+ 0.20 * int(has_trend) +
24
+ 0.10 * int(has_time) +
25
+ 0.10 * int(has_tip)
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)}