ClarusC64's picture
Create scorer.py
c111baf verified
Raw History Blame Contribute Delete
1.05 kB
from dataclasses import dataclass
from typing import Dict, Any, List
@dataclass
class ScoreResult:
score: float
details: Dict[str, Any]
def score(sample: Dict[str, Any], prediction: str) -> ScoreResult:
p = (prediction or "").lower()
words_ok = len(p.split()) <= 520
has_vector = "drift" in p or "fingerprint" in p
has_axes = "axis" in p or "system" in p
has_time = "temporal" in p or "onset" in p or "offset" in p
has_reversible = "reversible" in p or "rebound" in p
has_coherence = "coherence" in p or "net" in p
raw = (
0.15 * int(words_ok) +
0.25 * int(has_vector) +
0.20 * int(has_axes) +
0.20 * int(has_time) +
0.10 * int(has_reversible) +
0.10 * int(has_coherence)
)
return ScoreResult(score=min(1.0, raw), details={"id": sample.get("id")})
def aggregate(results: List[ScoreResult]) -> Dict[str, Any]:
if not results:
return {"mean": 0.0, "n": 0}
return {"mean": sum(r.score for r in results) / len(results), "n": len(results)}