Skip to content

Commit 079321a

Browse files
fix: Enclose evaluate_tables() in try catch
Signed-off-by: Nikos Livathinos <nli@zurich.ibm.com>
1 parent efbdd0e commit 079321a

File tree

1 file changed

+37
-32
lines changed

1 file changed

+37
-32
lines changed

docling_eval/evaluators/table_evaluator.py

Lines changed: 37 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -118,8 +118,7 @@ def evaluate_tables(
118118
pred_num_cols: int,
119119
is_complex: bool,
120120
structure_only: bool,
121-
# ) -> tuple[float, bool, bool]:
122-
) -> TableEvaluation:
121+
) -> Optional[TableEvaluation]:
123122
r"""
124123
Execution function
125124
Receive 2 tables as html-formatted string. Compute the TEDS score
@@ -130,35 +129,38 @@ def evaluate_tables(
130129
is_complex: bool
131130
structure_only: bool
132131
"""
133-
# TODO: Check if exceptions can be thrown in the following code
134-
for stopword in stopwords:
135-
pred_html = pred_html.replace(stopword, "")
136-
for stopword in stopwords:
137-
true_html = true_html.replace(stopword, "")
138-
139-
pred_html_obj = html.fromstring(pred_html)
140-
true_html_obj = html.fromstring(true_html)
141-
142-
teds = teds_scorer(
143-
gt_table=true_html_obj,
144-
pred_table=pred_html_obj,
145-
structure_only=structure_only,
146-
)
147-
teds = round(teds, 3)
148-
149-
# Prepare output
150-
table_evaluation = TableEvaluation(
151-
TEDS=teds,
152-
is_complex=is_complex,
153-
filename=doc_id,
154-
table_id=table_id,
155-
true_ncols=true_num_cols,
156-
pred_ncols=pred_num_cols,
157-
true_nrows=true_num_rows,
158-
pred_nrows=pred_num_rows,
159-
structure_only_evaluation=structure_only,
160-
)
161-
return table_evaluation
132+
try:
133+
for stopword in stopwords:
134+
pred_html = pred_html.replace(stopword, "")
135+
for stopword in stopwords:
136+
true_html = true_html.replace(stopword, "")
137+
138+
pred_html_obj = html.fromstring(pred_html)
139+
true_html_obj = html.fromstring(true_html)
140+
141+
teds = teds_scorer(
142+
gt_table=true_html_obj,
143+
pred_table=pred_html_obj,
144+
structure_only=structure_only,
145+
)
146+
teds = round(teds, 3)
147+
148+
# Prepare output
149+
table_evaluation = TableEvaluation(
150+
TEDS=teds,
151+
is_complex=is_complex,
152+
filename=doc_id,
153+
table_id=table_id,
154+
true_ncols=true_num_cols,
155+
pred_ncols=pred_num_cols,
156+
true_nrows=true_num_rows,
157+
pred_nrows=pred_num_rows,
158+
structure_only_evaluation=structure_only,
159+
)
160+
return table_evaluation
161+
except Exception:
162+
_log.error("Cannot evaluate doc_id: %s table: %d ", doc_id, table_id)
163+
return None
162164

163165

164166
class TableEvaluator(BaseEvaluator):
@@ -277,7 +279,10 @@ def __call__(
277279
ncols=120,
278280
total=len(ds_selection),
279281
):
280-
table_evaluation: TableEvaluation = future.result()
282+
table_evaluation: Optional[TableEvaluation] = future.result()
283+
if table_evaluation is None:
284+
continue
285+
281286
table_id: int = table_evaluation.table_id
282287
doc_id = table_evaluation.filename
283288

0 commit comments

Comments
 (0)