File size: 3,003 Bytes
f8c91b8
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
"""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))