Files
Volve-DIA/scripts/11_m34_classify.py
lamlvh 59fa1f4d08 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>
2026-11-20 07:00:36 +00:00

63 lines
2.5 KiB
Python
Executable File
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
#!/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()