Add M3-M4 baselines, C4 comparison and G2 report

Frozen feature tables for T1-T3, TF-IDF + logistic regression and DistilBERT
baselines with grouped splits, T4/C4 question answering (zero-shot, few-shot,
RAG, tool_only, agent), Qwen zero-shot T2, paired well-cluster bootstrap and
the G2 coverage report.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-11-20 07:00:36 +00:00
parent 2b59d635ce
commit 59fa1f4d08
16 changed files with 1999 additions and 0 deletions

View File

@@ -0,0 +1,78 @@
#!/usr/bin/env python3
"""Run the v1 DistilBERT baseline on one block (task, definition, mode) so blocks can share a GPU.
This replicates the ``distilbert`` stage of ``scripts/11_m34_classify.py`` (same configuration, inputs,
provenance and checkpoints under ``outputs/m34/distilbert/``) but takes a per-block lock instead of
``distilbert.lock`` and restricts ``volve_dia.m34_distilbert.datasets`` to the chosen block. The v1 code files
are not modified, so the classification code fingerprint and every checkpoint provenance stay unchanged.
T1 has a single block: ``--task t1 --definition section --mode masked``.
"""
from __future__ import annotations
import argparse
import fcntl
import itertools
import pandas as pd
from volve_dia import m2, m34
from volve_dia import m34_classify
def block_filter(task, definition, mode):
"""Return a replacement for ``datasets`` that yields only the chosen block."""
def datasets(tables, protocol):
for block in m34_classify.datasets(tables, protocol):
if block[:3] == (task, definition, mode):
yield block
return datasets
def completed(out, protocol, task, definition, mode, frame):
"""Count finished folds (parquet and json present) against the folds the block requires."""
splits = protocol["splits"]
seeds = protocol["statistics"]["seeds"]
done = total = 0
for group, seed in itertools.product((splits["group"], splits["sensitivity_group"]), seeds):
directory = out / "distilbert" / task / definition / mode / group / str(seed)
total += frame[group].nunique()
done += sum(1 for meta in directory.glob("*.json") if meta.with_suffix(".parquet").exists())
return done, total
def main():
parser = argparse.ArgumentParser(description=__doc__, formatter_class=argparse.RawDescriptionHelpFormatter)
parser.add_argument("--task", choices=["t1", "t2", "t3"], required=True)
parser.add_argument("--definition", choices=["a", "b", "section"], required=True)
parser.add_argument("--mode", choices=["masked", "unmasked"], required=True)
parser.add_argument("--dry-run", action="store_true", help="print the block and checkpoint count, then exit")
args = parser.parse_args()
protocol, spec = m34.configuration()
root, digests = m34.inputs(protocol)
out = root / "m34"
out.mkdir(exist_ok=True)
provenance = {"inputs": digests, "code": m34.code_fingerprint("classification")}
if m2.read_json(out / "features_provenance.json")["inputs"] != digests:
raise ValueError("Features were built from other inputs. Run prepare again.")
tables = {name: pd.read_parquet(out / f"features_{name}.parquet") for name in ("t1", "t2", "t3")}
selected = block_filter(args.task, args.definition, args.mode)
blocks = list(selected(tables, protocol))
if len(blocks) != 1:
raise ValueError(f"Expected one block for {args.task}/{args.definition}/{args.mode}, found {len(blocks)}.")
task, definition, mode, frame, target = blocks[0]
if args.dry_run:
done, total = completed(out, protocol, task, definition, mode, frame)
print(f"block {task}/{definition}/{mode} target={target} items={len(frame)} "
f"checkpointed folds {done}/{total}", flush=True)
return
lock_path = out / f"distilbert_{args.task}_{args.definition}_{args.mode}.lock"
with lock_path.open("a") as lock:
fcntl.flock(lock, fcntl.LOCK_EX | fcntl.LOCK_NB)
from volve_dia import m34_distilbert
m34_distilbert.datasets = selected
m34_distilbert.distilbert(tables, protocol, spec, out, provenance, args.task)
if __name__ == "__main__":
main()