Download examples/read_retrieval.py from evovim/EvoViM-Memory-Traces: direct link, hf CLI and curl.
- Browser
- Download file 2.05 kB
-
https://huggingface.co/datasets/evovim/EvoViM-Memory-Traces/resolve/main/examples/read_retrieval.py
- Command line
-
hf download hf://datasets/evovim/EvoViM-Memory-Traces/examples/read_retrieval.py
-
curl -L -o read_retrieval.py https://huggingface.co/datasets/evovim/EvoViM-Memory-Traces/resolve/main/examples/read_retrieval.py
2.05 kB
| """Show an observed search for a DMV-Hard question and the evidence the agent actually saw.""" | |
| import argparse | |
| from pathlib import Path | |
| import pyarrow.parquet as pq | |
| def read(table, filters): | |
| folder = Path(__file__).resolve().parents[1] / "data" / table | |
| return pq.read_table(folder / "dmv-hard.parquet", filters=filters or None).to_pylist() | |
| def show(seed=None, step=None): | |
| questions = read("dmv_questions", [("question_type", "=", "pattern")] if step is None else []) | |
| if seed is not None: | |
| questions = [row for row in questions if row["seed"] == seed] | |
| if step is not None: | |
| questions = [row for row in questions if row["step"] == step] | |
| for question in sorted(questions, key=lambda r: (r["seed"], r["step"])): | |
| filters = [(k, "=", question[k]) for k in ("cell_id", "seed", "step")] | |
| searches = read("dmv_searches", filters) | |
| candidates = read("dmv_candidates", filters) | |
| for search in sorted(searches, key=lambda r: (r["phase"], r["call"])): | |
| shown = sorted( | |
| [r for r in candidates if (r["phase"], r["call"]) == (search["phase"], search["call"])], | |
| key=lambda r: r["rank"], | |
| ) | |
| if not shown: | |
| continue | |
| print(f"Seed {question['seed']}, step {question['step']}, {question['question_type']}") | |
| print(f"Search ({search['phase']}, call {search['call']}): {search['query']}") | |
| for item in shown[:3]: | |
| print(f" {item['rank']}. Page {item['product_key']} | {item['retrieval_score']:g} | {item['shown_swatch_text']}") | |
| print(f"Agent answered page {question['executed_product_key']}. Correct: {question['answered_correctly']}.") | |
| return | |
| raise SystemExit("No matching question with an observed ranked response.") | |
| if __name__ == "__main__": | |
| cli = argparse.ArgumentParser(description=__doc__) | |
| cli.add_argument("--seed", type=int) | |
| cli.add_argument("--step", type=int) | |
| args = cli.parse_args() | |
| show(args.seed, args.step) | |