Download examples/evaluate_track_a.py from TrangBui/RoutingBench-V2: direct link, hf CLI and curl.
- Browser
- Download file 1.54 kB
-
https://huggingface.co/datasets/TrangBui/RoutingBench-V2/resolve/main/examples/evaluate_track_a.py
- Command line
-
hf download hf://datasets/TrangBui/RoutingBench-V2/examples/evaluate_track_a.py
-
curl -L -o evaluate_track_a.py https://huggingface.co/datasets/TrangBui/RoutingBench-V2/resolve/main/examples/evaluate_track_a.py
1.54 kB
| from __future__ import annotations | |
| import argparse | |
| import json | |
| from pathlib import Path | |
| from datasets import load_dataset | |
| def main() -> None: | |
| parser = argparse.ArgumentParser( | |
| description="Score RoutingBench Track A predictions." | |
| ) | |
| parser.add_argument("predictions", type=Path) | |
| parser.add_argument("--split", choices=("development", "validation", "test")) | |
| parser.add_argument("--revision", default=None) | |
| args = parser.parse_args() | |
| rows = load_dataset( | |
| "TrangBui/RoutingBench-V2", | |
| "decision", | |
| split=args.split, | |
| revision=args.revision, | |
| ) | |
| gold = {row["decision_id"]: set(row["admissible_actions"]) for row in rows} | |
| predictions = {} | |
| with args.predictions.open("r", encoding="utf-8") as handle: | |
| for line in handle: | |
| item = json.loads(line) | |
| predictions[str(item["decision_id"])] = str(item["selected_action"]) | |
| missing = sorted(set(gold) - set(predictions)) | |
| unknown = sorted(set(predictions) - set(gold)) | |
| if missing or unknown: | |
| raise SystemExit( | |
| f"Prediction IDs mismatch: missing={len(missing)}, unknown={len(unknown)}" | |
| ) | |
| correct = sum(predictions[key] in actions for key, actions in gold.items()) | |
| print( | |
| json.dumps( | |
| { | |
| "split": args.split, | |
| "count": len(gold), | |
| "admissible_next_action_accuracy": correct / len(gold), | |
| }, | |
| indent=2, | |
| ) | |
| ) | |
| if __name__ == "__main__": | |
| main() | |