Datasets:
Download scripts/verify_release.py from thomeboi/MAGAR-Bench: direct link, hf CLI and curl.
- Browser
- Download file 3.77 kB
-
https://huggingface.co/datasets/thomeboi/MAGAR-Bench/resolve/main/scripts/verify_release.py
- Command line
-
hf download hf://datasets/thomeboi/MAGAR-Bench/scripts/verify_release.py
-
curl -L -o verify_release.py https://huggingface.co/datasets/thomeboi/MAGAR-Bench/resolve/main/scripts/verify_release.py
3.77 kB
| """Verify the public MAGAR-Bench files without reading Test gold labels.""" | |
| from __future__ import annotations | |
| import argparse | |
| import hashlib | |
| import json | |
| from collections import Counter | |
| from pathlib import Path | |
| EXPECTED_TASKS = { | |
| "train": {"assembly_decision": 736, "atomic_action": 1764, "minimal_rework": 500}, | |
| "test": {"assembly_decision": 238, "atomic_action": 662, "minimal_rework": 100}, | |
| } | |
| def read_jsonl(path: Path) -> list[dict]: | |
| return [json.loads(line) for line in path.read_text(encoding="utf-8").splitlines() if line.strip()] | |
| def file_hash(path: Path) -> str: | |
| digest = hashlib.sha256() | |
| with path.open("rb") as stream: | |
| for chunk in iter(lambda: stream.read(1024 * 1024), b""): | |
| digest.update(chunk) | |
| return digest.hexdigest() | |
| def main() -> int: | |
| parser = argparse.ArgumentParser() | |
| parser.add_argument("--release-root", type=Path, default=Path(__file__).resolve().parents[1]) | |
| root = parser.parse_args().release_root.resolve() | |
| train = read_jsonl(root / "data" / "train.jsonl") | |
| test = read_jsonl(root / "data" / "test_inputs.jsonl") | |
| errors: list[str] = [] | |
| if len(train) != 3000 or len(test) != 1000: | |
| errors.append(f"row counts are train={len(train)}, test={len(test)}") | |
| for split, rows in (("train", train), ("test", test)): | |
| counts = Counter(row["metadata"]["task_family"] for row in rows) | |
| if counts != Counter(EXPECTED_TASKS[split]): | |
| errors.append(f"{split} task counts are {dict(counts)}") | |
| train_ids = {row["id"] for row in train} | |
| test_ids = {row["id"] for row in test} | |
| if len(train_ids) != len(train) or len(test_ids) != len(test): | |
| errors.append("duplicate sample ids") | |
| if train_ids & test_ids: | |
| errors.append("train/test id overlap") | |
| train_families = {row["metadata"]["assembly_id"] for row in train} | |
| test_families = {row["metadata"]["assembly_id"] for row in test} | |
| if len(train_families) != 20 or len(test_families) != 6: | |
| errors.append(f"family counts are train={len(train_families)}, test={len(test_families)}") | |
| if train_families & test_families: | |
| errors.append("train/test family overlap") | |
| train_images = {image for row in train for image in row.get("images", [])} | |
| test_images = {image for row in test for image in row.get("images", [])} | |
| if train_images & test_images: | |
| errors.append("train/test image overlap") | |
| missing = [image for image in train_images | test_images if not (root / image).exists()] | |
| if missing: | |
| errors.append(f"missing image references: {len(missing)}") | |
| if any(any(message.get("role") == "assistant" for message in row["messages"]) for row in test): | |
| errors.append("test inputs contain assistant answers") | |
| if any(any(key in row for key in ("target", "gold", "answer")) for row in test): | |
| errors.append("test inputs contain target/gold/answer fields") | |
| manifest = root / "MANIFEST.sha256" | |
| if not manifest.exists(): | |
| errors.append("MANIFEST.sha256 is missing") | |
| else: | |
| for line in manifest.read_text(encoding="utf-8").splitlines(): | |
| if not line.strip(): | |
| continue | |
| expected, relative = line.split(" ", 1) | |
| target = root / relative | |
| if not target.exists() or file_hash(target) != expected: | |
| errors.append(f"manifest mismatch: {relative}") | |
| result = { | |
| "train_rows": len(train), | |
| "test_rows": len(test), | |
| "train_unique_images": len(train_images), | |
| "test_unique_images": len(test_images), | |
| "errors": errors, | |
| } | |
| print(json.dumps(result, ensure_ascii=False, indent=2)) | |
| return 1 if errors else 0 | |
| if __name__ == "__main__": | |
| raise SystemExit(main()) | |