Download code/run_tcb.py from ai4he/trust-calibration-benchmark: direct link, hf CLI and curl.
- Browser
- Download file 3 kB
-
https://huggingface.co/datasets/ai4he/trust-calibration-benchmark/resolve/main/code/run_tcb.py
- Command line
-
hf download hf://datasets/ai4he/trust-calibration-benchmark/code/run_tcb.py
-
curl -L -o run_tcb.py https://huggingface.co/datasets/ai4he/trust-calibration-benchmark/resolve/main/code/run_tcb.py
3 kB
| """TCB harness: evaluate a new chat model on the benchmark and append it to the panel. | |
| Loads ../data/tcb_benchmark.json (60 yes/no items with gold truth and difficulty tier) and | |
| administers it under the paper's validated protocol, implemented once in tcb_parsing.py: the | |
| audited parser (template-quote guard; answers only from tagged or bare final lines) and the | |
| escalate-on-unparseable budget rule (one re-query at 4000 tokens). Writes per-trial records in | |
| exactly the schema analyze_panel.py consumes. | |
| Usage (generation requires a chat endpoint and the repository's _common client; analysis of | |
| shipped data needs neither): | |
| export VLLM_API_KEY=<your-endpoint-token> # and VLLM_BASE_URL if not the default | |
| python3 run_tcb.py <model-name> > my_trials.json | |
| Then append the rows of my_trials.json to ../data/tcb_v03_trials.json and re-run | |
| analyze_panel.py; the new model is analyzed after the canonical nine. To use a different chat | |
| client, replace make_client() with any object exposing | |
| chat(model, messages, max_tokens=..., temperature=..., seed=...) -> {"content": str}. | |
| """ | |
| import json, sys, pathlib | |
| HERE = pathlib.Path(__file__).resolve().parent | |
| sys.path.insert(0, str(HERE)) | |
| from tcb_parsing import chat_parsed | |
| BENCH = json.load(open(HERE / ".." / "data" / "tcb_benchmark.json")) | |
| PROMPT = BENCH["prompt"] | |
| MAX_TOKENS = 512 | |
| SEED0 = 7000000 | |
| def make_client(): | |
| """Default client: the repository's endpoint wrapper. Swap for your own if needed.""" | |
| root = next((q for q in [HERE] + list(HERE.parents) if (q / "_common").is_dir()), None) | |
| if root is None: | |
| raise SystemExit("generation needs the repository's _common/ client (or replace " | |
| "make_client() with your own chat client); analysis of the shipped " | |
| "trials requires no client at all") | |
| sys.path.insert(0, str(root)) | |
| from _common.llm_client import LLMClient, ClientConfig | |
| return LLMClient(ClientConfig(cache_dir=HERE / ".." / "data" / "llm_cache")) | |
| def evaluate(model): | |
| cli = make_client() | |
| trials, seed = [], SEED0 | |
| for scenario, items in BENCH["scenarios"].items(): | |
| for it in items: | |
| ans, conf, strict, conf_stated, raw = chat_parsed( | |
| cli, model, PROMPT, it["q"], seed, max_tokens=MAX_TOKENS) | |
| base = {"model": model, "scenario": scenario, "id": it["id"], "truth": it["truth"], | |
| "tier": it["tier"], "seed": seed, "raw": raw, "strict": int(strict), | |
| "conf_stated": conf_stated} | |
| if ans is None: | |
| trials.append({**base, "answer": None, "conf": None, "correct": None, "adherent": 0}) | |
| else: | |
| trials.append({**base, "answer": ans, "conf": conf, | |
| "correct": int(ans == it["truth"]), "adherent": 1}) | |
| seed += 10 | |
| return trials | |
| if __name__ == "__main__": | |
| model = sys.argv[1] if len(sys.argv) > 1 else "glm-5.1-fp8" | |
| print(json.dumps(evaluate(model), indent=1)) | |