File size: 2,590 Bytes
901f964
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
"""probe_tables.py TABLES [--limit 200] - retrieval-only check of engram tables on the AA-Omniscience dev sample (10-20,
PLAN-verticals): for each item, retrieve over TABLES (comma list) and over wiki alone; per domain, the share of items whose
gold answer string appears in the top 3 / top 10 passages (a proxy: AA answers are short, exact strings). Same hash-ordered,
domain round-robin sample as engram_eval.py --limit. Run before any LLM time; a table that does not raise answer@10 for its
domain is not worth an eval. Env as engram.py (THREADS, NPROBE, NCAND)."""
import sys, os, csv, hashlib, collections, argparse, time
sys.path.insert(0, os.path.dirname(os.path.abspath(__file__)))
from engram import Engram
E = os.environ.get("ENGRAM_ROOT", ".")
ap = argparse.ArgumentParser(); ap.add_argument("tables"); ap.add_argument("--limit", type=int, default=200)
ap.add_argument("--domain", default="", help="10-27: only dev items whose domain starts with this (per-domain gate screens)"); A = ap.parse_args()
items = [{"id": r["question_id"], "q": r["question"], "gold": r["answer"], "domain": r["domain"]} for r in csv.DictReader(open(f"{E}/qa/AA-Omniscience_dataset_public.csv"))]
rr = sorted(items, key=lambda it: hashlib.sha1(f"aa:{it['id']}".encode()).hexdigest()); by = {}
for it in rr:
    by.setdefault(it["domain"], []).append(it)
items = [it for grp in zip(*by.values()) for it in grp][:A.limit]
items = [it for it in items if it["domain"].startswith(A.domain)]
ts = A.tables.split(","); eg = Engram(tables=sorted(set(ts) | {"wiki"})); res = collections.defaultdict(lambda: collections.Counter()); t0 = time.time()
for it in items:
    g = it["gold"].lower(); r = res[it["domain"]]; r["n"] += 1
    for name, tabs in (("wiki", ["wiki"]), ("new", ts)):
        hits = eg.retrieve(it["q"], k=10, tables=tabs)
        r[f"{name}@3"] += any(g in h["text"].lower() for h in hits[:3]); r[f"{name}@10"] += any(g in h["text"].lower() for h in hits)
        if name == "new":
            for h in hits[:3]:
                r["from:" + h["table"]] += 1
tot = collections.Counter()
for d, r in sorted(res.items()):
    tot.update(r); n = r["n"]
    print(f"{d[:36]:36s} n={n:3d} wiki @3 {r['wiki@3'] / n:.2f} @10 {r['wiki@10'] / n:.2f} | {A.tables} @3 {r['new@3'] / n:.2f} @10 {r['new@10'] / n:.2f} | "
          + " ".join(f"{k[5:]} {v}" for k, v in r.items() if k.startswith("from:")))
n = tot["n"]; print(f"{'all':36s} n={n:3d} wiki @3 {tot['wiki@3'] / n:.2f} @10 {tot['wiki@10'] / n:.2f} | {A.tables} @3 {tot['new@3'] / n:.2f} @10 {tot['new@10'] / n:.2f}  ({time.time() - t0:.0f} s)")