File size: 2,836 Bytes
510314e
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
"""Caricamento dei risultati della corsa principale (solo lettura dei file copiati da PC4070TI)."""
import json
from pathlib import Path

ROOT = Path(__file__).resolve().parents[1]          # out/main-run-confirm
RUNS = ROOT / "runs"
PREFIX = "main-clar-"   # corsa di conferma
MAIN_RUNS = ROOT.parent / "main-run" / "runs"   # corsa principale (confronto)
LENGTHS = ["64k", "128k"]
POLS = ["A", "D", "B", "T"]
DEV_QID = "38_i13_j22_a_0031"
DATA = ROOT.parents[1] / "alb-bench-v2" / "alb" / "data" / "benchmark" / "kf-c"


def qtype_short(qt):
    return "CF" if qt.startswith("Count Frequency") else ("FD" if qt.startswith("Find Duplicates") else qt)


def load_results(runs=None, prefix=None):
    """Una riga per (lunghezza, politica, qid), dai result.json (non da results.jsonl)."""
    runs = runs or RUNS
    prefix = prefix or PREFIX
    rows = []
    for L in LENGTHS:
        for pol in POLS:
            for d in sorted((runs / (prefix + L) / pol / "kf-c" / L).iterdir()):
                r = json.loads((d / "result.json").read_text())
                rows.append({
                    "L": L, "pol": pol, "qid": r["qid"], "dir": str(d),
                    "sample_id": int(r["qid"].split("_")[0]),
                    "qt": qtype_short(r["question_type"]),
                    "status": r["status"],
                    "off": float(r["score_official"] or 0), "norm": float(r["score_format_norm"] or 0),
                    "full": int(r["fully_correct"] or 0),
                    "empty": bool(r["answer_empty"]), "trunc": bool(r["answer_truncated"]),
                    "resid": bool(r["answer_residual_calls"]), "invalid": bool(r["answer_invalid_format"]),
                    "error": bool(r["answer_error"]),
                    "wall_s": r["wall_s"], "window": r["window"], "gold": r["gold"],
                    "pred": r.get("pred_answer"), "raw": r.get("raw_response"),
                    "finish": r.get("finish_reason"),
                    "engine": r.get("engine") or {}, "final_call": r.get("final_call") or {},
                    "margin_viol": (r.get("engine") or {}).get("margin_violations"),
                })
    return rows


def load_engine_calls(d):
    return [json.loads(l) for l in open(Path(d) / "engine_calls.jsonl")]


def load_resources(d):
    out = []
    for l in open(Path(d) / "resources.jsonl"):
        try:
            out.append(json.loads(l))
        except ValueError:
            pass
    return out


def samples(L, qt):
    f = DATA / L / "tool_response" / ("count_frequency_tool.jsonl" if qt == "CF" else "find_duplicates_tool.jsonl")
    out = {}
    for l in open(f):
        x = json.loads(l)
        out[x["id"]] = x
    return out


def load_main():
    """Corsa principale (domanda ambigua), per il confronto affiancato."""
    return load_results(MAIN_RUNS, "main-")