PyTorch¶
TableFormer extractor implementation using PyTorch backend.
Uses the TFPredictor from docling-ibm-models for table structure recognition.
TableFormerExtractor
¶
Bases: BaseTableExtractor
Table structure extractor using TableFormer model.
TableFormer is a transformer-based model that predicts table structure using OTSL (Optimal Table Structure Language) tags. It can detect: - Cell boundaries (bounding boxes) - Row and column spans - Header cells (column and row headers) - Section rows
Example
from omnidocs.tasks.table_extraction import TableFormerExtractor, TableFormerConfig
# Initialize extractor
extractor = TableFormerExtractor(
config=TableFormerConfig(mode="fast", device="cuda")
)
# Extract table structure
result = extractor.extract(table_image)
# Get HTML output
html = result.to_html()
# Get DataFrame
df = result.to_dataframe()
Initialize TableFormer extractor.
| PARAMETER | DESCRIPTION |
|---|---|
config
|
TableFormerConfig with model settings
TYPE:
|
Source code in omnidocs/tasks/table_extraction/tableformer/pytorch.py
extract
¶
extract(
image: Union[Image, ndarray, str, Path],
ocr_output: Optional[OCROutput] = None,
) -> TableOutput
Extract table structure from an image.
| PARAMETER | DESCRIPTION |
|---|---|
image
|
Table image (should be cropped to table region)
TYPE:
|
ocr_output
|
Optional OCR results for cell text matching
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
TableOutput
|
TableOutput with cells, structure, and export methods |