Skip to content

Commit ae10646

Browse files
feat: Introduce examples how to evaluate using external predictions using the API and the CLI.
Signed-off-by: Nikos Livathinos <nli@zurich.ibm.com>
1 parent 94b3938 commit ae10646

File tree

2 files changed

+157
-0
lines changed

2 files changed

+157
-0
lines changed
Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
#!/bin/bash
2+
3+
###########################################################################################
4+
# Invariants
5+
#
6+
7+
readonly GT_DIR=scratch/DPBench/gt_dataset
8+
9+
readonly MODALITIES=(
10+
layout
11+
table_structure
12+
document_structure
13+
reading_order
14+
markdown_text
15+
bboxes_text
16+
key_value
17+
timings
18+
)
19+
20+
21+
###########################################################################################
22+
# Functions
23+
#
24+
25+
evaluate() {
26+
local pred_dir save_dir modality
27+
pred_dir="$1"
28+
save_dir="$2"
29+
30+
# Check if the GT/preds dirs exist
31+
if [ ! -d "${GT_DIR}" ]; then
32+
echo "Missing GT dir: ${GT_DIR}"
33+
exit 1
34+
fi
35+
if [ ! -d "${pred_dir}" ]; then
36+
echo "Missing predictions dir: ${pred_dir}"
37+
exit 2
38+
fi
39+
40+
for modality in "${MODALITIES[@]}"; do
41+
echo "Evaluation modality: ${modality}, predictions: ${pred_dir}"
42+
uv run docling-eval evaluate \
43+
--benchmark DPBench \
44+
--modality "${modality}" \
45+
--input-dir "${GT_DIR}" \
46+
--external-predictions-path "${pred_dir}" \
47+
--output-dir "${save_dir}"
48+
done
49+
}
50+
51+
52+
###########################################################################################
53+
# Main
54+
#
55+
56+
# json predictions
57+
evaluate \
58+
scratch/DPBench/predicted_documents/json \
59+
scratch/DPBench/external_evaluations_jsons
60+
61+
62+
# doctags predictions
63+
evaluate \
64+
scratch/DPBench/predicted_documents/doctag \
65+
scratch/DPBench/external_evaluations_doctags
66+
67+
68+
# yaml predictions
69+
evaluate \
70+
scratch/DPBench/predicted_documents/yaml \
71+
scratch/DPBench/external_evaluations_yaml
72+
Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
import argparse
2+
import logging
3+
from pathlib import Path
4+
5+
from docling_eval.cli.main import evaluate
6+
from docling_eval.datamodels.types import BenchMarkNames, EvaluationModality
7+
8+
_log = logging.getLogger(__name__)
9+
10+
11+
def evaluate_external_predictions(
12+
benchmark: BenchMarkNames,
13+
modality: EvaluationModality,
14+
gt_path: Path,
15+
predictions_dir: Path,
16+
save_dir: Path,
17+
):
18+
r""" """
19+
evaluate(
20+
modality,
21+
benchmark,
22+
gt_path,
23+
save_dir,
24+
external_predictions_path=predictions_dir,
25+
)
26+
27+
28+
def main():
29+
r""" """
30+
parser = argparse.ArgumentParser(
31+
description="Example how to use GT from parquet and predictions from externally provided prediction files",
32+
formatter_class=argparse.RawTextHelpFormatter,
33+
)
34+
parser.add_argument(
35+
"-b",
36+
"--benchmark",
37+
required=True,
38+
type=BenchMarkNames,
39+
help="Evaluation modality",
40+
)
41+
parser.add_argument(
42+
"-m",
43+
"--modality",
44+
required=True,
45+
type=EvaluationModality,
46+
help="Evaluation modality",
47+
)
48+
parser.add_argument(
49+
"-g",
50+
"--gt_parquet_dir",
51+
required=True,
52+
type=Path,
53+
help="Path to the parquet GT dataset",
54+
)
55+
parser.add_argument(
56+
"-p",
57+
"--predictions_dir",
58+
required=True,
59+
type=Path,
60+
help="Dir with the external prediction files (json, dt, yaml)",
61+
)
62+
parser.add_argument(
63+
"-s",
64+
"--save_dir",
65+
required=False,
66+
type=Path,
67+
help="Path to save the produced evaluation files",
68+
)
69+
args = parser.parse_args()
70+
71+
# Configure logger
72+
log_format = "%(asctime)s - %(levelname)s - %(message)s"
73+
logging.basicConfig(level=logging.INFO, format=log_format)
74+
75+
evaluate_external_predictions(
76+
args.benchmark,
77+
args.modality,
78+
args.gt_parquet_dir,
79+
args.predictions_dir,
80+
args.save_dir,
81+
)
82+
83+
84+
if __name__ == "__main__":
85+
main()

0 commit comments

Comments
 (0)