Download scripts/02_extract.py from arthrod/edgar_segmenter_artifacts: direct link, hf CLI and curl.
- Browser
- Download file 2.13 kB
-
https://huggingface.co/datasets/arthrod/edgar_segmenter_artifacts/resolve/main/scripts/02_extract.py
- Command line
-
hf download hf://datasets/arthrod/edgar_segmenter_artifacts/scripts/02_extract.py
-
curl -L -o 02_extract.py https://huggingface.co/datasets/arthrod/edgar_segmenter_artifacts/resolve/main/scripts/02_extract.py
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() | |