Datasets:
Download code/build_natural_prompts.py from spatial-evidence-bench/SpatialEvidenceBench: direct link, hf CLI and curl.
- Browser
- Download file 1.95 kB
-
https://huggingface.co/datasets/spatial-evidence-bench/SpatialEvidenceBench/resolve/main/code/build_natural_prompts.py
- Command line
-
hf download hf://datasets/spatial-evidence-bench/SpatialEvidenceBench/code/build_natural_prompts.py
-
curl -L -o build_natural_prompts.py https://huggingface.co/datasets/spatial-evidence-bench/SpatialEvidenceBench/resolve/main/code/build_natural_prompts.py
1.95 kB
| import argparse | |
| import hashlib | |
| import json | |
| import re | |
| import sys | |
| from pathlib import Path | |
| sys.path.insert(0, str(Path(__file__).resolve().parent)) | |
| from run_real import MANIFESTS, build_prompt, clean_question | |
| CONDITIONS = ("T0", "Tpos", "Tneg", "Tabs", "Tunk") | |
| def main(): | |
| ap = argparse.ArgumentParser() | |
| ap.add_argument("--root", default="/mnt/f70f6709-366e-49a0-861f-497645d98975/lyz/GraphEvolve") | |
| ap.add_argument("--collection", required=True, choices=sorted(MANIFESTS)) | |
| ap.add_argument("--out", required=True) | |
| args = ap.parse_args() | |
| root = Path(args.root) | |
| rows = [json.loads(line) for line in (root / MANIFESTS[args.collection]).open(encoding="utf-8")] | |
| out = Path(args.out) | |
| out.parent.mkdir(parents=True, exist_ok=True) | |
| written = 0 | |
| with out.open("w", encoding="utf-8") as fh: | |
| for rec in rows: | |
| image_path = rec["image_path"] | |
| if not image_path.startswith("/"): | |
| image_path = str(root / image_path) | |
| question = clean_question(rec["question"]) | |
| subject = rec["object_a"] | |
| obj = rec["object_b"] | |
| predicate = rec["predicate"] | |
| for condition in CONDITIONS: | |
| prompt = build_prompt(question, condition, subject, obj, predicate) | |
| row = { | |
| "scene_id": rec["annotation_id"], | |
| "state": "a", | |
| "image": image_path, | |
| "question": question, | |
| "truth": rec["gold"], | |
| "declared_truth": rec["gold"], | |
| "condition": condition, | |
| "prompt": prompt, | |
| "prompt_sha256": hashlib.sha256(prompt.encode()).hexdigest(), | |
| } | |
| fh.write(json.dumps(row, ensure_ascii=False) + "\n") | |
| written += 1 | |
| print(json.dumps({"out": str(out), "rows": written})) | |
| if __name__ == "__main__": | |
| main() | |