-
Notifications
You must be signed in to change notification settings - Fork 54
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix cells with duplicated indexes (#341)
The post processing in table-transformer allows for returning multiple cells with same indexes. It happens when 1 cell is covered in more than 50% by two different spanning cells. This happens because this 'cell' is later assigned as subcell for both spanning cells instead of one with the highest probability. Example: Simple 2x2 table ``` # +-----------+----------+ # | one | two | # |-----------+----------| # | three | four | # +-----------+----------+ ``` With spanning cells over cells 'one three' (column spanning cell) and another one over 'one two' (row spanning cell). In this case cell "one" will be assigned to both spanning cells. Reproduction: ```python3 from pprint import pprint from unstructured_inference.models.tables import structure_to_cells table_structure = { "rows": [ {"bbox": [0, 0, 10, 20]}, {"bbox": [10, 0, 20, 20]}, ], "columns": [ {"bbox": [0, 0, 20, 10]}, {"bbox": [0, 10, 20, 20]}, ], "spanning cells": [ {"bbox": [0, 0, 20, 10], "score": 0.9, "projected row header": False}, {"bbox": [0, 0, 10, 20], "score": 0.8, "projected row header": False}, ], } tokens = [ {"text": "one", "bbox": [0, 0, 10, 10], "span_num": 1, "line_num": 1, "block_num": 1}, {"text": "two", "bbox": [0, 10, 10, 20], "span_num": 1, "line_num": 1, "block_num": 1}, {"text": "three", "bbox": [10, 0, 20, 10], "span_num": 1, "line_num": 1, "block_num": 1}, {"text": "four", "bbox": [10, 10, 20, 20], "span_num": 1, "line_num": 1, "block_num": 1}, ] predicted_cells, _ = structure_to_cells(table_structure, tokens=tokens) pprint(predicted_cells) ``` This yields: ``` [ .... {'cell text': 'one three', 'column_nums': [0], 'row_nums': [0, 1] }, {''cell text': 'two', 'column_nums': [0, 1], 'row_nums': [0] }] ``` You can see coordinates (0,0) are included in both spanning cells. This PR fixes this by assigning only to the most probably spanning cell
- Loading branch information
Showing
4 changed files
with
110 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
__version__ = "0.7.29" # pragma: no cover | ||
__version__ = "0.7.30" # pragma: no cover |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters