miscellaneous / prune_broken_rows.py
Rakancorle11's picture
Upload supp/ and root scripts
203a7fb verified
"""Prune broken rows (empty raw_output / judge_fail) from eval_results.jsonl
files in-place so the next eval run will re-process them.
A backup .bak is written next to each modified file.
Usage:
python3 /home/ubuntu/prune_broken_rows.py <jsonl_or_dir> [more...]
python3 /home/ubuntu/prune_broken_rows.py /home/ubuntu/eval_results/sync/sync_xiaomi_mimo-v2.5_audioMuxed
python3 /home/ubuntu/prune_broken_rows.py /home/ubuntu/eval_results/{sync,swap,mute,swap_original,mute_original}/*xiaomi*
"""
import json
import shutil
import sys
from pathlib import Path
def is_broken(row: dict) -> str:
raw = (row.get("raw_output") or "").strip()
if not raw:
return "empty_raw"
if row.get("parse_method") == "judge_fail":
return "judge_fail"
return ""
def prune(jsonl: Path) -> None:
if jsonl.is_dir():
jsonl = jsonl / "eval_results.jsonl"
if not jsonl.exists():
print(f"[skip] {jsonl} does not exist")
return
rows = [json.loads(l) for l in open(jsonl) if l.strip()]
keep, drop = [], []
for r in rows:
why = is_broken(r)
(drop if why else keep).append((r, why))
if not drop:
print(f"[ok] {jsonl.parent.name}: {len(rows)} rows, none broken")
return
bak = jsonl.with_suffix(".jsonl.bak")
if not bak.exists():
shutil.copy2(jsonl, bak)
with open(jsonl, "w") as f:
for r, _ in keep:
f.write(json.dumps(r, ensure_ascii=False) + "\n")
by_reason = {}
for r, why in drop:
by_reason[why] = by_reason.get(why, 0) + 1
reasons = ", ".join(f"{k}={v}" for k, v in by_reason.items())
print(f"[pruned] {jsonl.parent.name}: kept {len(keep)} / dropped {len(drop)} ({reasons}) -> backup: {bak.name}")
def main():
args = sys.argv[1:]
if not args:
print(__doc__)
sys.exit(1)
for a in args:
prune(Path(a).expanduser())
if __name__ == "__main__":
main()