cai-bench / tools /to_5_4_0.py
compressionawareintelligence's picture
CAI-Bench 5.4.0: one-question card, leaderboard and prediction-ledger configs, future split and results (what memory keeps for later decisions), claims split (agent actions), coupling split and results, currency split and results, every 5.2 prediction scored, CAI Headline leaderboard, prompts config for any harness, lm-eval tasks, import_replies, report cards, datasheet (part 2)
19b9db5 verified
Raw History Blame
5.29 kB
#!/usr/bin/env python3
"""Rename the 5.2.1 package to 5.3.0 (it adds data files, so the minor version bumps) and add the
run-anywhere layer: data/prompts.jsonl (config `prompts`), import_replies.py, the lm-evaluation-harness tasks, DATASHEET.md."""
import hashlib, re
from pathlib import Path
HERE = Path(__file__).resolve().parent.parent
def sub(path, pairs):
p = HERE / path
s = p.read_text()
for a, b in pairs:
assert a in s, (path, a[:70])
s = s.replace(a, b)
p.write_text(s)
# version strings (card, changelog, results guide, pyproject, currency note)
for f in ("README.md", "CHANGELOG.md", "results/README.md", "RESULTS_currency_2026-10-18.md"):
p = HERE / f
p.write_text(p.read_text().replace("5.2.1", "5.3.0"))
sub("pyproject.toml", [('version = "5.2.1"', 'version = "5.3.0"')])
# card: prompts config, run-anywhere, data fields, datasheet
sub("README.md", [
("""- config_name: currency
data_files:""", """- config_name: prompts
data_files:
- split: test
path: data/prompts.jsonl
- config_name: currency
data_files:"""),
("""**Fine-tune on it (`train`).**""", """**Run it in any harness (`prompts`).** One flat file holds every test prompt exactly as the native runners send it (5,832 prompts, with split, gold, Headline membership and the answer line to read). Send `prompt`, keep the reply, and score with the official scorers:
```bash
python3 import_replies.py --model my-model replies.jsonl # any JSONL or CSV with item_id and reply
python3 score_all.py results/my-model && python3 score_headline.py results/my-model
```
**lm-evaluation-harness.** `integrations/lm_eval/cai_bench/` adds tasks `cai_bench`, `cai_bench_headline` and `cai_bench_<split>`:
```bash
lm_eval --model hf --model_args pretrained=Qwen/Qwen2.5-7B-Instruct --apply_chat_template \\
--include_path integrations/lm_eval --tasks cai_bench_headline --log_samples --output_path out/
python3 import_replies.py --model qwen2.5-7b --lm-eval out/*/samples_cai_bench_*.jsonl # official paired scores
```
Inspect, promptfoo, LangSmith and OpenAI Evals exports remain available through `caibench_export.py`.
**Fine-tune on it (`train`).**"""),
("""| `currency` (new in 5.3.0) |""", """| `prompts` (new in 5.3.0) | n/a | 5,832 | Every test prompt, rendered, in one file: run CAI-Bench from any harness and score with `import_replies.py` |
| `currency` (new in 5.3.0) |"""),
("""### `currency`
`item_id`, `group_id`""", """### `prompts`
| Field | Description |
|---|---|
| `item_id`, `split`, `group_id`, `variant_type` | the test item it renders |
| `prompt` | the user message exactly as `run_local.py` / `run_api.py` send it (for multi-turn items, the first turn) |
| `messages_json`, `tools_json` | set when the prompt needs system or tool turns (`provider`); send these instead of `prompt` |
| `multi_turn`, `followups_json` | set for items with follow-up turns; the model's own replies go between them |
| `answer_format`, `answer_line`, `gold` | how the reply ends (`DECISION:`, `CHOICE:`, `OWED:`) and the rule-computed answer |
| `in_headline`, `level` | Headline membership; difficulty level (`dynamics`; level 1 only here, as in `run_local.py`) |
Built deterministically by `build_prompts.py` from the split files; `distinctions` is left out until v1.1.
### `currency`
`item_id`, `group_id`"""),
("""## Citation""", """## Datasheet
`DATASHEET.md` answers the *Datasheets for Datasets* questions: motivation, composition, collection, labelling, uses and limits, distribution and maintenance.
## Citation"""),
])
sub("CHANGELOG.md", [("## 5.3.0 (2026-10-18)\n\nResults.", """## 5.3.0 (2026-10-18)
Run it anywhere, and results. A minor release because it adds data files (`prompts`, `currency`, `distinctions`); no published data file changed.
- **`prompts` config** (`data/prompts.jsonl`, `build_prompts.py`): all 5,832 test prompts rendered exactly as the native runners send them, with split, gold, answer line, Headline membership, and system/tool/multi-turn fields where needed. Any harness can now run CAI-Bench from one file.
- **`import_replies.py`**: replies from any harness (JSONL or CSV with item_id and reply, or lm-evaluation-harness `--log_samples` output) become native result files for the official scorers. Round-trip tested: re-importing qwen2.5:7b's published replies reproduces every index exactly.
- **lm-evaluation-harness tasks** (`integrations/lm_eval/cai_bench/`): `cai_bench`, `cai_bench_headline`, `cai_bench_<split>`, with an answer-line check that agrees with the native parsers on 90–100% of published replies; official paired scores come from `import_replies.py --lm-eval`.
- **`DATASHEET.md`** (Datasheets for Datasets).
Results."""),
])
for f in ("tools/card_5_2_1.py", "tools/finish_5_2_1.py"):
p = HERE / f
p.rename(p.with_name(p.name.replace("5_2_1", "5_3_0")))
files = sorted(p for p in HERE.rglob("*") if p.is_file() and "_to_delete" not in p.parts and "__pycache__" not in p.parts
and p.name not in ("SHA256SUMS", ".DS_Store") and p.suffix != ".pyc")
(HERE / "SHA256SUMS").write_text("".join(f"{hashlib.sha256(p.read_bytes()).hexdigest()} {p.relative_to(HERE)}\n" for p in files))
print("5.3.0:", len(files), "files in SHA256SUMS")