Datasets:
Download code/natural_report.py from spatial-evidence-bench/SpatialEvidenceBench: direct link, hf CLI and curl.
- Browser
- Download file 2.24 kB
-
https://huggingface.co/datasets/spatial-evidence-bench/SpatialEvidenceBench/resolve/main/code/natural_report.py
- Command line
-
hf download hf://datasets/spatial-evidence-bench/SpatialEvidenceBench/code/natural_report.py
-
curl -L -o natural_report.py https://huggingface.co/datasets/spatial-evidence-bench/SpatialEvidenceBench/resolve/main/code/natural_report.py
2.24 kB
| import argparse | |
| import glob | |
| import json | |
| from collections import defaultdict | |
| from pathlib import Path | |
| ROOT = Path("/mnt/f70f6709-366e-49a0-861f-497645d98975/lyz/GraphEvolve") | |
| CONDITIONS = ["T0", "Tpos", "Tneg", "Tabs", "Tunk"] | |
| def load(path): | |
| with open(path, encoding="utf-8") as fh: | |
| for line in fh: | |
| line = line.strip() | |
| if line: | |
| yield json.loads(line) | |
| def gold_map(collection): | |
| path = { | |
| "spatialsense": ROOT / "runs/n_evidence_v1/gate0/source_manifest.jsonl", | |
| "vsr": ROOT / "runs/n_evidence_v1/gate3/manifest_vsr.jsonl", | |
| }[collection] | |
| return {row["annotation_id"]: row["gold"] for row in load(path)} | |
| def report(model, collection): | |
| gold = gold_map(collection) | |
| stats = defaultdict(lambda: {"n": 0, "correct": 0, "yes": 0}) | |
| pattern = ROOT / f"n_full_v1/predictions/natural/{collection}_{model}_shard*.jsonl" | |
| rows = 0 | |
| for path in sorted(glob.glob(str(pattern))): | |
| for row in load(path): | |
| rows += 1 | |
| truth = gold.get(row["annotation_id"]) | |
| if truth is None: | |
| continue | |
| cell = stats[row["condition"]] | |
| cell["n"] += 1 | |
| cell["correct"] += int(row["answer"] == truth) | |
| cell["yes"] += int(row["answer"] == "yes") | |
| out = {} | |
| for condition in CONDITIONS: | |
| cell = stats.get(condition) | |
| if not cell or not cell["n"]: | |
| raise RuntimeError(f"missing condition {condition} for {model}/{collection}") | |
| out[condition] = { | |
| "n": cell["n"], | |
| "acc": cell["correct"] / cell["n"], | |
| "yes_rate": cell["yes"] / cell["n"], | |
| } | |
| out["rows"] = rows | |
| return out | |
| def main(): | |
| parser = argparse.ArgumentParser() | |
| parser.add_argument("--model", required=True) | |
| args = parser.parse_args() | |
| for collection in ("spatialsense", "vsr"): | |
| data = report(args.model, collection) | |
| path = ROOT / f"n_full_v1/analysis/natural_{args.model}_{collection}.json" | |
| path.write_text(json.dumps(data, ensure_ascii=False, indent=2), encoding="utf-8") | |
| print(collection, {c: round(data[c]["acc"], 4) for c in CONDITIONS}) | |
| if __name__ == "__main__": | |
| main() | |