Download verification_kit/random_wrong.py from S3RL4/binary-reasoning-v1: direct link, hf CLI and curl.
- Browser
- Download file 3.18 kB
-
https://huggingface.co/datasets/S3RL4/binary-reasoning-v1/resolve/main/verification_kit/random_wrong.py
- Command line
-
hf download hf://datasets/S3RL4/binary-reasoning-v1/verification_kit/random_wrong.py
-
curl -L -o random_wrong.py https://huggingface.co/datasets/S3RL4/binary-reasoning-v1/resolve/main/verification_kit/random_wrong.py
3.18 kB
| #!/usr/bin/env python3 | |
| """Random-wrong sanity check: a deliberately wrong deterministic reply should score 0.""" | |
| import json | |
| import sys | |
| from pathlib import Path | |
| ROOT = Path(__file__).resolve().parents[1] | |
| sys.path.insert(0, str(ROOT / "environment" / "src")) | |
| from binary_reasoning_v1.grading import _answer_symbol, grade_item, needs_judge, norm_symbol # noqa: E402 | |
| 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 parse_json_answer(ans): | |
| if isinstance(ans, dict): | |
| return ans | |
| if isinstance(ans, str): | |
| try: | |
| obj = json.loads(ans) | |
| if isinstance(obj, dict): | |
| return obj | |
| except Exception: | |
| pass | |
| return {} | |
| def mutate_token(s): | |
| s = str(s) | |
| if not s: | |
| return "RELAB_WRONG" | |
| mid = len(s) // 2 | |
| return f"{s[:mid]}_RELAB_WRONG_{s[mid:]}" | |
| def wrong_reply(row): | |
| fam = row.get("family", "") | |
| ans = row.get("answer") | |
| if fam == "func_id_mc" and isinstance(ans, dict): | |
| opts = ans.get("options", []) | |
| correct = norm_symbol(ans.get("correct", "")) | |
| for i, opt in enumerate(opts[:4]): | |
| if norm_symbol(opt) != correct: | |
| return "ABCD"[i] | |
| return "RELAB_WRONG" | |
| if fam == "toolchain_fp" and isinstance(ans, dict): | |
| parts = [mutate_token(s) for s in ans.get("toolchain_strings", []) if str(s)] | |
| return "\n".join(parts) if parts else "RELAB_WRONG" | |
| if fam == "library_ident": | |
| ans_str = str(_answer_symbol(ans) or ans or "") | |
| toks = [t for t in ans_str.split() if len(t) >= 2] | |
| return " ".join(mutate_token(t) for t in toks) if toks else "RELAB_WRONG" | |
| if fam == "crossarch_equivalence": | |
| obj = parse_json_answer(ans) | |
| if bool(obj.get("same")): | |
| return "Not the same." | |
| return "Same function: RELAB_WRONG" | |
| sym = _answer_symbol(ans) or ans or "" | |
| if row.get("family") == "agentic_flag_hunt": | |
| return mutate_token(sym) | |
| return f"{sym}_RELAB_WRONG" | |
| def main(): | |
| path = resolve_path() | |
| rows = load_rows(path) | |
| passed = failed = skipped = 0 | |
| fails = [] | |
| for row in rows: | |
| fam = row.get("family", "") | |
| ans = row.get("answer") | |
| if needs_judge(fam, ans): | |
| skipped += 1 | |
| continue | |
| score = grade_item(fam, wrong_reply(row), ans) | |
| if score == 0.0: | |
| passed += 1 | |
| else: | |
| failed += 1 | |
| fails.append((row.get("id"), fam, score)) | |
| print(f"file={path}") | |
| print(f"summary: random_wrong pass={passed}/{passed + failed} fail={failed} skipped_judge={skipped}") | |
| for f in fails[:10]: | |
| print("FAIL", *f) | |
| return 0 if failed == 0 else 1 | |
| if __name__ == "__main__": | |
| raise SystemExit(main()) | |