"""E1.1 — Jev sur le banc de reference, compare aux baselines sans IA.""" import os, sys from collections import defaultdict sys.path.insert(0, os.path.dirname(os.path.dirname(os.path.abspath(__file__)))) sys.path.insert(0, os.path.dirname(os.path.abspath(__file__))) from common import Jev, run_parallel, load, outfile, med, pct_ci from bench.reference_set import build, CRITERIA REPS = 2 def build_trials(): items = build() tr = [] for it in items: for r in range(REPS): tr.append({"tid": f"{it['id']}_{r}", "state": it["text"], "meta": {"id": it["id"], "truth": it["truth"], "diff": it["diff"], "leurre": it["leurre"], "tpl": it["tpl"], "rep": r}, "questions": {"cat": {"type": "choice", "instructions": "Dans quelle categorie classer ce message ?", "criteria": CRITERIA}}}) return tr def analyze(path): obs = load(path) print(f"\n{'='*86}\nE1.1 — JEV SUR LE BANC DE REFERENCE\n{'='*86}") print(f"{len(obs)} appels, {len(set(o['meta']['id'] for o in obs))} items distincts\n") par = defaultdict(lambda: [0, 0]) conf_ok, conf_ko = [], [] for o in obs: m = o["meta"]; a = o["answers"]["cat"] juste = a["choice"] == m["truth"] par[m["diff"]][1] += 1; par["GLOBAL"][1] += 1 if juste: par[m["diff"]][0] += 1; par["GLOBAL"][0] += 1; conf_ok.append(a["confidence"]) else: conf_ko.append(a["confidence"]) print(f"{'difficulte':14s} {'justesse':>24s}") for d in ("explicite", "implicite", "piege", "GLOBAL"): k, n = par[d] print(f"{d:14s} {pct_ci(k, n):>24s}") print(f"\nconfiance si juste : {med(conf_ok):.3f} (n={len(conf_ok)})") print(f"confiance si faux : {med(conf_ko):.3f} (n={len(conf_ko)})" if conf_ko else "aucune erreur") # piege : tombe-t-il sur le leurre ? leurres = defaultdict(lambda: [0, 0]) for o in obs: m = o["meta"] if m["diff"] != "piege": continue c = o["answers"]["cat"]["choice"] leurres["total"][1] += 1 if c != m["truth"]: leurres["total"][0] += 1 if c == m["leurre"]: leurres["sur_leurre"][0] += 1 if leurres["total"][1]: e, n = leurres["total"][0], leurres["total"][1] print(f"\npieges : {e} erreurs sur {n}, dont {leurres['sur_leurre'][0]} " f"exactement sur le leurre") # stabilite entre repetitions par_id = defaultdict(list) for o in obs: par_id[o["meta"]["id"]].append(o["answers"]["cat"]["choice"]) instables = [i for i, v in par_id.items() if len(set(v)) > 1] print(f"items dont la reponse change entre les 2 passages : {len(instables)}/{len(par_id)}") # comparaison finale print(f"\n{'='*86}\nECHELLE DE LECTURE\n{'='*86}") sys.path.insert(0, os.path.dirname(os.path.dirname(os.path.abspath(__file__)))) from baselines.no_ai import main as bl import io, contextlib buf = io.StringIO() with contextlib.redirect_stdout(buf): res = bl() k, n = par["GLOBAL"] lignes = [("Jev (zero exemple)", k, n, {d: tuple(par[d]) for d in ("explicite", "implicite", "piege")})] + \ [(nom, kk, nn, pd_) for nom, kk, nn, pd_ in res if "naif" not in nom] print(f"{'methode':32s} {'global':>13s} {'explicite':>13s} {'implicite':>13s} {'piege':>13s}") print("-" * 86) for nom, kk, nn, pd_ in lignes: row = f"{nom:32s} {kk/nn*100:11.1f} % " for d in ("explicite", "implicite", "piege"): a, b = pd_.get(d, (0, 1)) row += f"{a/b*100:11.1f} % " print(row) if __name__ == "__main__": if len(sys.argv) > 1 and sys.argv[1] == "analyze": analyze(sys.argv[2]); sys.exit() j = Jev(); tr = build_trials() print(f"E1.1 : {len(tr)} appels (400 items x {REPS})") p = run_parallel(j, tr, outfile("t6_banc"), workers=8, label="banc ") analyze(p)