Download scripts/derive_direct_llm_baseline.py from BeliefLens/FinGovBench: direct link, hf CLI and curl.
- Browser
- Download file 4.01 kB
-
https://huggingface.co/datasets/BeliefLens/FinGovBench/resolve/main/scripts/derive_direct_llm_baseline.py
- Command line
-
hf download hf://datasets/BeliefLens/FinGovBench/scripts/derive_direct_llm_baseline.py
-
curl -L -o derive_direct_llm_baseline.py https://huggingface.co/datasets/BeliefLens/FinGovBench/resolve/main/scripts/derive_direct_llm_baseline.py
4.01 kB
| #!/usr/bin/env python3 | |
| """Derive the graph-free direct GPT-OSS baseline from saved model choices. | |
| This script performs no inference and loads no benchmark labels. It releases a | |
| case iff the frozen primary GPT-OSS choice is NONE; otherwise it reviews only | |
| the selected component. Governance actions use the benchmark's public, | |
| deterministic authority/event router shared by the open-weight reference arms. | |
| """ | |
| from __future__ import annotations | |
| import argparse | |
| import json | |
| from pathlib import Path | |
| ROOT = Path(__file__).resolve().parents[1] | |
| def load_jsonl(path: Path) -> list[dict]: | |
| return [json.loads(line) for line in path.read_text().splitlines() if line.strip()] | |
| def default_measurements() -> Path: | |
| released = ROOT / "results/open_weight/gptoss20b_direct_measurements.jsonl" | |
| if released.exists(): | |
| return released | |
| return ROOT / "results/open_weight_full_archive/gptoss20b_open_weight_token_sseg_measurements.jsonl" | |
| def input_rows() -> list[dict]: | |
| base = ROOT / "closed_loop_inputs" if (ROOT / "closed_loop_inputs").exists() else ROOT / "hf/closed_loop_inputs" | |
| return sorted( | |
| (row for split in ("development", "validation", "test") for row in load_jsonl(base / f"{split}.jsonl")), | |
| key=lambda row: row["case_id"], | |
| ) | |
| def action_for(row: dict, release: bool) -> str: | |
| if release: | |
| return "release" | |
| trigger = row["event"]["trigger_category"] | |
| tier = row["workflow_context"]["authority_tier"] | |
| if any(c.get("status") == "failed" and not c.get("compensable", True) for c in row.get("red_line_controls", [])): | |
| return "suspend" | |
| if trigger == "tool_permission": | |
| return "restrict" if tier.startswith("C") else "scoped_revalidation" | |
| if trigger == "incident_near_miss": | |
| return "withhold" | |
| if trigger in {"performance_behaviour", "model_vendor"}: | |
| return "escalate" | |
| if trigger == "prompt_policy_orchestration": | |
| return "withhold" | |
| if trigger == "purpose_population": | |
| return "scoped_revalidation" | |
| if trigger == "memory_data": | |
| return "rollback" if tier.startswith("A") else ("withhold" if row["domain"] == "market_data" else "scoped_revalidation") | |
| return "escalate" | |
| def main() -> None: | |
| parser = argparse.ArgumentParser() | |
| parser.add_argument("--measurements", type=Path, default=default_measurements()) | |
| parser.add_argument("--output", type=Path, default=ROOT / "results/open_weight/direct_llm.jsonl") | |
| args = parser.parse_args() | |
| measurements = {row["case_id"]: row for row in load_jsonl(args.measurements)} | |
| predictions = [] | |
| for row in input_rows(): | |
| measurement = measurements[row["case_id"]] | |
| primary = measurement["observed_primary"] | |
| selected = primary.get("selected_node") or "NONE" | |
| release = selected == "NONE" | |
| scope = [] if release else [selected] | |
| predictions.append({ | |
| "case_id": row["case_id"], | |
| "method": "direct_llm", | |
| "model": measurement.get("model_requested", "openai/gpt-oss-20b"), | |
| "measurement_channel": "frozen primary model choice; no probability gate or graph propagation", | |
| "iceberg_detected": not release, | |
| "governance_action": action_for(row, release), | |
| "affected_components": scope, | |
| "revalidation_components": scope, | |
| "reviewed_components": scope, | |
| "release_permitted": release, | |
| "diagnostic": {"selected_code": primary.get("selected_code"), "selected_node": selected}, | |
| }) | |
| args.output.parent.mkdir(parents=True, exist_ok=True) | |
| args.output.write_text("".join(json.dumps(row, sort_keys=True) + "\n" for row in predictions)) | |
| print(json.dumps({ | |
| "method": "direct_llm", | |
| "predictions": len(predictions), | |
| "model_calls": 0, | |
| "uses_probability_gate": False, | |
| "uses_graph_propagation": False, | |
| "output": str(args.output), | |
| }, indent=2)) | |
| if __name__ == "__main__": | |
| main() | |