Download scorer.py from ClarusC64/materials-passivation-layer-breakdown-mapping-v0.1: direct link, hf CLI and curl.
- Browser
- Download file 899 Bytes
-
https://huggingface.co/datasets/ClarusC64/materials-passivation-layer-breakdown-mapping-v0.1/resolve/main/scorer.py
- Command line
-
hf download hf://datasets/ClarusC64/materials-passivation-layer-breakdown-mapping-v0.1/scorer.py
-
curl -L -o scorer.py https://huggingface.co/datasets/ClarusC64/materials-passivation-layer-breakdown-mapping-v0.1/resolve/main/scorer.py
899 Bytes
| from dataclasses import dataclass | |
| from typing import Dict, Any, List | |
| REQ = ["coherence", "risk", "pitting", "surface", "protect"] | |
| 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()) <= 900 | |
| hits = sum(1 for k in REQ if k in p) | |
| has_numeric = any(c.isdigit() for c in p) | |
| raw = ( | |
| 0.25 * int(words_ok) + | |
| 0.45 * (hits / len(REQ)) + | |
| 0.20 * int(has_numeric) + | |
| 0.10 * int("time" in p or "horizon" in p) | |
| ) | |
| return ScoreResult(score=min(1.0, raw), details={"id": sample.get("id"), "hits": hits}) | |
| 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)} | |