Buckets:
| """Print the numbers for every finished run: per-checkpoint validation macro-F1 (from the trainer log | |
| history), final validation / test_ood metrics, and the natural-vs-edited breakdown. | |
| python scripts/collect_results.py checkpoints/<run> [checkpoints/<run> ...] | |
| """ | |
| import json | |
| import sys | |
| from pathlib import Path | |
| LABELS = ("followed", "violated", "not_applicable") | |
| def checkpoint_scores(run_dir): | |
| """Validation macro-F1 at each quarter checkpoint, read from trainer_state.json log history.""" | |
| state = json.loads((run_dir / "trainer_state.json").read_text()) | |
| return [(round(entry["epoch"], 2), entry["eval_macro_f1"]) for entry in state["log_history"] if "eval_macro_f1" in entry] | |
| def split_summary(report): | |
| metrics = report["metrics"] | |
| row = {"macro_f1": metrics["macro_f1"], "accuracy": metrics["accuracy"]} | |
| for label in LABELS: | |
| for stat in ("precision", "recall", "f1"): | |
| row[f"{label}_{stat}"] = metrics[f"{label}_{stat}"] | |
| return row | |
| results = {} | |
| for argument in sys.argv[1:]: | |
| run_dir = Path(argument) | |
| if not (run_dir / "validation_report.json").exists(): | |
| continue | |
| entry = {"checkpoints": checkpoint_scores(run_dir)} | |
| for split in ("validation", "test_ood"): | |
| report = json.loads((run_dir / f"{split}_report.json").read_text()) | |
| entry[split] = split_summary(report) | |
| entry[split]["confusion_matrix"] = report.get("confusion_matrix") | |
| entry[f"{split}_by_source"] = { | |
| source: {"pairs": part["pairs"], **{key: part["metrics"][key] for key in | |
| ("macro_f1", "accuracy", "violated_precision", "violated_recall", "violated_f1")}} | |
| for source, part in report["by_source"].items() | |
| } | |
| hardware = run_dir / "hardware_metrics.json" | |
| if hardware.exists(): | |
| entry["training_minutes"] = json.loads(hardware.read_text())["training_wall_seconds"] / 60 | |
| wandb_info = run_dir / "wandb_run.json" | |
| if wandb_info.exists(): | |
| entry["wandb_url"] = json.loads(wandb_info.read_text())["url"] | |
| results[run_dir.name] = entry | |
| print(json.dumps(results, indent=1)) | |
Xet Storage Details
- Size:
- 2.12 kB
- Xet hash:
- 104996c8af722e37d795040059b407e31e4db5241e2773ab19a4ea362259370f
·
Xet efficiently stores files, intelligently splitting them into unique chunks and accelerating uploads and downloads. More info.