Tablinum-2: the Lite-Beam engram, release 2 (card, code, recipes, 9 released tables)
901f964 verified Download code/probe_tables.py from tablinum/tablinum-2: direct link, hf CLI and curl.
- Browser
- Download file 2.59 kB
-
https://huggingface.co/datasets/tablinum/tablinum-2/resolve/main/code/probe_tables.py
- Command line
-
hf download hf://datasets/tablinum/tablinum-2/code/probe_tables.py
-
curl -L -o probe_tables.py https://huggingface.co/datasets/tablinum/tablinum-2/resolve/main/code/probe_tables.py
2.59 kB
| """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)") | |