Datasets:
Download scripts/build_hard_split.py from cloudlabworks/proof-or-claim: direct link, hf CLI and curl.
- Browser
- Download file 4.12 kB
-
https://huggingface.co/datasets/cloudlabworks/proof-or-claim/resolve/main/scripts/build_hard_split.py
- Command line
-
hf download hf://datasets/cloudlabworks/proof-or-claim/scripts/build_hard_split.py
-
curl -L -o build_hard_split.py https://huggingface.co/datasets/cloudlabworks/proof-or-claim/resolve/main/scripts/build_hard_split.py
4.12 kB
| #!/usr/bin/env python3 | |
| """Build the hard split (splits/hard.jsonl) from data/items.jsonl. Deterministic for a given seed. | |
| Usage: build_hard_split.py [--items data/items.jsonl] [--out splits/hard.jsonl] [--seed 20261110] | |
| Rule (no model output is used to choose items): | |
| 1. Take every sandbox item whose variant is wrong_target: 20 items (5 domains x 4 instances), all | |
| UNPROVEN. The trace checks something that passes, but on the wrong object (a canary instead of | |
| production, a staging file instead of the production file, a listing instead of a checksum). | |
| 2. Add the verify_after twin of each one: same domain and instance, unpadded, PROVEN. The twin | |
| differs only in what the check points at, so a model cannot score well by always answering | |
| UNPROVEN (that scores exactly 0.500). | |
| 3. Fold: for each domain, random.Random(seed) picks one of its 4 instances as "dev" (5 instances, | |
| 10 items); the other 15 instances (30 items) are "test". Both items of a twin pair share a fold. | |
| 4. Order: random.Random(seed + 1) shuffles the 40 rows, so PROVEN and UNPROVEN rows interleave. | |
| Rows are full item records plus "fold", "twin_id" and "hard_index". A manifest with the seed, the | |
| input sha256 and the output sha256 is written next to the split. | |
| """ | |
| import argparse | |
| import hashlib | |
| import json | |
| import random | |
| import sys | |
| from pathlib import Path | |
| sys.path.insert(0, str(Path(__file__).resolve().parent)) | |
| from pocb import ROOT, load_jsonl # noqa: E402 | |
| DEFAULT_SEED = 20261110 | |
| def build(items, seed): | |
| by_id = {it["id"]: it for it in items} | |
| wrong = sorted((it for it in items if it["source"] == "sandbox" and it["variant"] == "wrong_target" | |
| and not it["padded"]), key=lambda it: (it["domain"], it["instance"])) | |
| rows = [] | |
| for w in wrong: | |
| twin = by_id[w["id"].replace("wrong_target", "verify_after")] | |
| assert twin["variant"] == "verify_after" and not twin["padded"] and twin["label"] == "PROVEN" | |
| assert (twin["domain"], twin["instance"]) == (w["domain"], w["instance"]) and w["label"] == "UNPROVEN" | |
| rows.append(dict(w, twin_id=twin["id"])) | |
| rows.append(dict(twin, twin_id=w["id"])) | |
| rng = random.Random(seed) | |
| dev = {} | |
| for d in sorted({r["domain"] for r in rows}): | |
| dev[d] = rng.choice(sorted({r["instance"] for r in rows if r["domain"] == d})) | |
| for r in rows: | |
| r["fold"] = "dev" if dev[r["domain"]] == r["instance"] else "test" | |
| random.Random(seed + 1).shuffle(rows) | |
| for i, r in enumerate(rows): | |
| r["hard_index"] = i | |
| return rows, dev | |
| def main(): | |
| ap = argparse.ArgumentParser() | |
| ap.add_argument("--items", default=str(ROOT / "data/items.jsonl")) | |
| ap.add_argument("--out", default=str(ROOT / "splits/hard.jsonl")) | |
| ap.add_argument("--seed", type=int, default=DEFAULT_SEED) | |
| a = ap.parse_args() | |
| items = load_jsonl(a.items) | |
| rows, dev = build(items, a.seed) | |
| out = Path(a.out) | |
| out.parent.mkdir(parents=True, exist_ok=True) | |
| body = "".join(json.dumps(r, ensure_ascii=False, sort_keys=True) + "\n" for r in rows) | |
| out.write_text(body) | |
| manifest = { | |
| "seed": a.seed, | |
| "rule": "all sandbox wrong_target items plus their verify_after twins; one dev instance per domain " | |
| "drawn with random.Random(seed); rows shuffled with random.Random(seed + 1)", | |
| "input": Path(a.items).name, | |
| "input_sha256": hashlib.sha256(Path(a.items).read_bytes()).hexdigest(), | |
| "output": out.name, | |
| "output_sha256": hashlib.sha256(body.encode()).hexdigest(), | |
| "n_rows": len(rows), | |
| "n_proven": sum(r["label"] == "PROVEN" for r in rows), | |
| "n_unproven": sum(r["label"] == "UNPROVEN" for r in rows), | |
| "dev_instance_by_domain": dev, | |
| "n_dev": sum(r["fold"] == "dev" for r in rows), | |
| "n_test": sum(r["fold"] == "test" for r in rows), | |
| } | |
| out.with_name(out.stem + "_manifest.json").write_text(json.dumps(manifest, indent=1) + "\n") | |
| print(json.dumps({k: manifest[k] for k in ("seed", "n_rows", "n_dev", "n_test", "output_sha256")})) | |
| if __name__ == "__main__": | |
| main() | |