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

62
scripts/11_m34_classify.py Executable file
View File

@@ -0,0 +1,62 @@
#!/usr/bin/env python3
"""Build the frozen M3–M4 inputs or run grouped classification baselines."""
from __future__ import annotations
import argparse
import fcntl
import pandas as pd
from volve_dia import m2, m34
from volve_dia.m34_classify import classical
from volve_dia.m34_features import feature_tables
def main():
parser = argparse.ArgumentParser(description=__doc__)
parser.add_argument("stage", choices=["prepare", "classical", "distilbert"])
parser.add_argument("--task", choices=["t1", "t2", "t3"])
args = parser.parse_args()
protocol, spec = m34.configuration()
root, digests = m34.inputs(protocol)
out = root / "m34"
out.mkdir(exist_ok=True)
with (out / f"{args.stage}.lock").open("a") as lock:
fcntl.flock(lock, fcntl.LOCK_EX | fcntl.LOCK_NB)
run(args, protocol, spec, root, out, digests)
def run(args, protocol, spec, root, out, digests):
provenance = {"inputs": digests, "code": m34.code_fingerprint("classification")}
if args.stage == "prepare":
for name, frame in feature_tables(root, protocol, spec).items():
m34.write_parquet(frame, out / f"features_{name}.parquet")
print(f"{name}: {len(frame)} items")
m2.write_json(out / "features_provenance.json", {"inputs": digests})
return
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")}
if args.stage == "distilbert":
from volve_dia.m34_distilbert import distilbert
distilbert(tables, protocol, spec, out, provenance, args.task)
return
for task in ([args.task] if args.task else tables):
path = out / f"classical_{task}.parquet"
meta = path.with_suffix(".json")
if path.is_file() and meta.is_file():
existing = m2.read_json(meta)
if all(existing.get(k) == v for k, v in provenance.items()):
print(f"{task}: checkpoint complete ({existing['rows']} predictions)", flush=True)
continue
print(f"{task}: fitting grouped baselines", flush=True)
frames = list(classical(tables, protocol, spec, root, task))
result = pd.concat(frames, ignore_index=True)
m34.write_parquet(result, path)
m2.write_json(meta, provenance | {"rows": len(result)})
print(f"{task}: {len(result)} predictions", flush=True)
if __name__ == "__main__":
main()