Download verification_kit/leak_check.py from S3RL4/binary-reasoning-v1: direct link, hf CLI and curl.
- Browser
- Download file 2.29 kB
-
https://huggingface.co/datasets/S3RL4/binary-reasoning-v1/resolve/main/verification_kit/leak_check.py
- Command line
-
hf download hf://datasets/S3RL4/binary-reasoning-v1/verification_kit/leak_check.py
-
curl -L -o leak_check.py https://huggingface.co/datasets/S3RL4/binary-reasoning-v1/resolve/main/verification_kit/leak_check.py
2.29 kB
| #!/usr/bin/env python3 | |
| """Answer-leak audit: hidden answer labels/tokens should not appear in the model-facing input.""" | |
| import json | |
| import re | |
| import sys | |
| from pathlib import Path | |
| ROOT = Path(__file__).resolve().parents[1] | |
| def resolve_path(): | |
| if len(sys.argv) > 1: | |
| return Path(sys.argv[1]) | |
| for p in (ROOT / "sample_free.jsonl", ROOT / "environment/src/binary_reasoning_v1/items.jsonl"): | |
| if p.exists(): | |
| return p | |
| raise SystemExit("no sample JSONL found; pass one as argv[1]") | |
| def load_rows(path): | |
| rows = [] | |
| for line in path.read_text(encoding="utf-8").splitlines(): | |
| if line.strip(): | |
| rows.append(json.loads(line)) | |
| return rows | |
| def candidate_names(row): | |
| ans = row.get("answer") | |
| names = [] | |
| if isinstance(ans, dict): | |
| if isinstance(ans.get("symbol"), str): | |
| names.append(ans["symbol"]) | |
| if isinstance(ans.get("correct"), str): | |
| names.append(ans["correct"]) | |
| for alias in ans.get("aliases", []): | |
| if isinstance(alias, str): | |
| names.append(alias) | |
| for s in ans.get("toolchain_strings", []): | |
| if isinstance(s, str): | |
| names.append(s) | |
| elif isinstance(ans, str) and re.fullmatch(r"[A-Za-z_][A-Za-z0-9_.]{4,}", ans): | |
| # Exact-symbol / flag-style answers. Prose and JSON answers are handled by rubric/judge paths. | |
| names.append(ans) | |
| return [n for n in names if len(n) >= 4] | |
| def main(): | |
| path = resolve_path() | |
| rows = load_rows(path) | |
| leaks = [] | |
| checked_rows = 0 | |
| ids = [row.get("id") for row in rows] | |
| for row in rows: | |
| candidates = candidate_names(row) | |
| if candidates: | |
| checked_rows += 1 | |
| surface = row.get("input", "") | |
| for name in candidates: | |
| if re.search(r"(?<![A-Za-z0-9_.])" + re.escape(name) + r"(?![A-Za-z0-9_])", surface): | |
| leaks.append((row.get("id"), row.get("family"), name)) | |
| break | |
| print(f"file={path}") | |
| print(f"summary: leak_check items={len(rows)} unique_ids={len(set(ids))} checked_rows={checked_rows} leaks={len(leaks)}") | |
| for l in leaks[:10]: | |
| print("LEAK", *l) | |
| return 0 if not leaks else 1 | |
| if __name__ == "__main__": | |
| raise SystemExit(main()) | |