# -*- coding: utf-8 -*- """Eval za bh-questions-pilot-v01. CPU-only, stdlib + pandas. Ucitava zakljucani test split, baseline = referentni odgovori (oracle), normalizovano poredjenje za exact_match (MC/kratki/matematika/jezik), human_judgement stavke se ne boduju automatski. 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() s = re.sub(r"[^\w\s]", " ", s, flags=re.UNICODE) # skini puntuaciju, cuvaj slova/brojeve (i dijakritiku) return re.sub(r"\s+", " ", s).strip() test = pd.read_json(DATA / "test.jsonl", lines=True) scored = test[test["eval_metric"] == "exact_match"].copy() hj = test[test["eval_metric"] == "human_judgement"] # baseline: predikcija = referentni odgovor (oracle) — mjereno, ne pretpostavljeno scored["pred"] = scored["answer"] scored["ok"] = [normalize(p) == normalize(a) for p, a in zip(scored["pred"], scored["answer"])] n = len(scored) n_ok = int(scored["ok"].sum()) acc = round(n_ok / n, 4) if n else 0.0 by_qtype = {qt: {"n": int(g.shape[0]), "correct": int(g["ok"].sum()), "accuracy": round(float(g["ok"].mean()), 4)} for qt, g in scored.groupby("qtype")} report = {"dataset": "bh-questions-pilot", "version": "v03", "split": "test (LOCKED held-out)", "baseline": "reference-oracle (prediction = referentni odgovor)", "normalization": "NFC + lowercase + strip punctuation + collapse whitespace", "n_test_total": int(len(test)), "n_scored_exact_match": n, "n_correct": n_ok, "accuracy_exact_match": acc, "by_qtype": by_qtype, "n_human_judgement_not_auto_scored": int(len(hj)), "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))