File size: 1,760 Bytes
da34da8
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
2dd8f71
da34da8
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
# -*- coding: utf-8 -*-
"""Eval za bh-reasoning-pilot-v01. CPU-only, stdlib + pandas.
Ucitava zakljucani test split, baseline = referentni odgovori (oracle),
exact_match na answer (NFC + lowercase + strip), po subjectu.
Pise reports/eval-report.json."""
import json, re, unicodedata
from pathlib import Path
import pandas as pd

BASE = Path(__file__).resolve().parent.parent
DATA = BASE / "data"
REP = BASE / "reports"

def normalize(s: str) -> str:
    s = unicodedata.normalize("NFC", s).lower()
    return re.sub(r"\s+", " ", s).strip()

test = pd.read_json(DATA / "test.jsonl", lines=True)
assert (test["eval_metric"] == "exact_match").all(), "all items must be exact_match"

# baseline: predikcija = referentni odgovor (oracle) — mjereno, ne pretpostavljeno
test["pred"] = test["answer"]
test["ok"] = [normalize(p) == normalize(a) for p, a in zip(test["pred"], test["answer"])]

n = len(test)
n_ok = int(test["ok"].sum())
acc = round(n_ok / n, 4) if n else 0.0
by_subject = {s: {"n": int(g.shape[0]), "correct": int(g["ok"].sum()),
    "accuracy": round(float(g["ok"].mean()), 4)} for s, g in test.groupby("subject")}

report = {"dataset": "bh-reasoning-pilot", "version": "v03", "split": "test (LOCKED held-out)",
    "baseline": "reference-oracle (prediction = referentni odgovor)",
    "normalization": "NFC + lowercase + strip (dijakritika se cuva)",
    "n_test_total": int(n), "n_scored_exact_match": n,
    "n_correct": n_ok, "accuracy_exact_match": acc,
    "by_subject": by_subject,
    "gate": "PASS" if (n > 0 and acc == 1.0) else "REVIEW"}
REP.mkdir(parents=True, exist_ok=True)
(REP / "eval-report.json").write_text(json.dumps(report, ensure_ascii=False, indent=2), encoding="utf-8")
print(json.dumps(report, ensure_ascii=False, indent=2))