arthrod's picture
Add files using upload-large-folder tool
1e5748d verified
Raw History Blame Contribute Delete
2.13 kB
"""Copy out what the evaluation reads from a committed run (the run stays).
Usage: uv run python claude_run/NEW/scripts/02_extract.py <workspace> <run_id>
Writes predictions/<run_id>.jsonl.gz with exactly the rows
`ablations/evaluate_step.py` hands to the evaluator (segment rows with
projection.include and no alternative_group; run_status rows) and a trimmed
copy of the manifest.
"""
import os
import gzip
import json
import sys
from pathlib import Path
ROOT = Path(os.environ.get("SEG_ROOT") or Path(__file__).resolve().parents[1]).resolve() # SEG_ROOT: another document set (new100/)
def main():
ws, run = Path(sys.argv[1]), sys.argv[2]
rd = ws / "runs" / run
manifest = json.loads((rd / "manifest.json").read_text())
out = ROOT / "predictions"; out.mkdir(exist_ok=True)
n = {"segment": 0, "run_status": 0, "excluded": 0}
with gzip.open(out / f"{run}.jsonl.gz", "wt") as fh, (rd / "projection.jsonl").open() as src:
for line in src:
r = json.loads(line); r = r.get("current", r)
if r["record_type"] == "run_status":
fh.write(json.dumps({"record_type": "run_status", "document_id": r["source"]["document_id"], "run_status": r["run_status"]}) + "\n")
n["run_status"] += 1; continue
if r["record_type"] != "segment": continue
if not r["projection"]["include"] or r["annotation"]["alternative_group"]:
n["excluded"] += 1; continue
fh.write(json.dumps({"record_type": "segment", "document_id": r["source"]["document_id"],
"text_sha256": r["source"]["text_sha256"], "ranges": r["source"]["ranges"]}) + "\n")
n["segment"] += 1
keep = {k: manifest.get(k) for k in ("run_id", "stage", "parent_run_id", "additional_parents", "parameters", "status",
"change_counts", "record_count", "created_at", "code_sha256", "metadata", "manifest_sha256")}
(out / f"{run}.manifest.json").write_text(json.dumps(keep, indent=1, default=str))
print(run, json.dumps(n))
if __name__ == "__main__":
main()