Datasets:
Preserve nested prediction directories for page_ids containing "/"
Browse filespage_id can contain "/" (e.g. this dataset uses <source>/<page>), which prepare/run/convert scripts preserve as nested prediction directories. Use rglob instead of glob and mirror the relative path in the output dir, instead of flattening to the basename, so evaluate_from_hf.py can look predictions up by predictions_dir / f"{page_id}.csv".
evaluation_kit/convert_predictions_to_evaluation_csv.py
CHANGED
|
@@ -106,20 +106,27 @@ def main() -> None:
|
|
| 106 |
args = parse_args()
|
| 107 |
args.output_dir.mkdir(parents=True, exist_ok=True)
|
| 108 |
|
| 109 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 110 |
if not prediction_files:
|
| 111 |
raise FileNotFoundError(f"No JSON files found in {args.predictions_dir}")
|
| 112 |
|
| 113 |
written = 0
|
| 114 |
skipped = 0
|
| 115 |
for pred_path in prediction_files:
|
| 116 |
-
|
|
|
|
| 117 |
if output_path.exists() and not args.overwrite:
|
| 118 |
skipped += 1
|
| 119 |
continue
|
| 120 |
|
| 121 |
predictions = load_predictions(pred_path)
|
| 122 |
rows = to_csv_rows(predictions, path=pred_path)
|
|
|
|
| 123 |
write_csv(rows, output_path)
|
| 124 |
written += 1
|
| 125 |
|
|
|
|
| 106 |
args = parse_args()
|
| 107 |
args.output_dir.mkdir(parents=True, exist_ok=True)
|
| 108 |
|
| 109 |
+
# rglob (not glob): page_id can itself contain "/" (e.g. RLALT/ACoPPer uses
|
| 110 |
+
# "<source>/<page>"), which prepare/run/convert scripts preserve as nested
|
| 111 |
+
# prediction directories. evaluate_from_hf.py looks up predictions by
|
| 112 |
+
# `predictions_dir / f"{page_id}.csv"`, i.e. it expects that same nested
|
| 113 |
+
# layout to be mirrored here rather than flattened.
|
| 114 |
+
prediction_files = sorted(args.predictions_dir.rglob("*.json"))
|
| 115 |
if not prediction_files:
|
| 116 |
raise FileNotFoundError(f"No JSON files found in {args.predictions_dir}")
|
| 117 |
|
| 118 |
written = 0
|
| 119 |
skipped = 0
|
| 120 |
for pred_path in prediction_files:
|
| 121 |
+
relative_path = pred_path.relative_to(args.predictions_dir).with_suffix(".csv")
|
| 122 |
+
output_path = args.output_dir / relative_path
|
| 123 |
if output_path.exists() and not args.overwrite:
|
| 124 |
skipped += 1
|
| 125 |
continue
|
| 126 |
|
| 127 |
predictions = load_predictions(pred_path)
|
| 128 |
rows = to_csv_rows(predictions, path=pred_path)
|
| 129 |
+
output_path.parent.mkdir(parents=True, exist_ok=True)
|
| 130 |
write_csv(rows, output_path)
|
| 131 |
written += 1
|
| 132 |
|