Overview¶
TableFormer module for table structure extraction.
Provides the TableFormer-based table structure extractor.
TableFormerConfig
¶
Bases: BaseModel
Configuration for TableFormer table structure extractor.
TableFormer is a transformer-based model that predicts table structure using OTSL (Optimal Table Structure Language) tags and cell bounding boxes.
| ATTRIBUTE | DESCRIPTION |
|---|---|
mode |
Inference mode - "fast" or "accurate"
TYPE:
|
device |
Device for inference - "cpu", "cuda", "mps", or "auto"
TYPE:
|
num_threads |
Number of CPU threads for inference
TYPE:
|
do_cell_matching |
Whether to match predicted cells with OCR text cells
TYPE:
|
artifacts_path |
Path to pre-downloaded model artifacts
TYPE:
|
repo_id |
HuggingFace model repository
TYPE:
|
revision |
Model revision/tag
TYPE:
|
Example
from omnidocs.tasks.table_extraction import TableFormerExtractor, TableFormerConfig
# Fast mode
extractor = TableFormerExtractor(config=TableFormerConfig(mode="fast"))
# Accurate mode with GPU
extractor = TableFormerExtractor(
config=TableFormerConfig(
mode="accurate",
device="cuda",
do_cell_matching=True,
)
)
TableFormerMode
¶
Bases: str, Enum
TableFormer inference mode.
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 |
Example
Source code in omnidocs/tasks/table_extraction/tableformer/pytorch.py
config
¶
Configuration for TableFormer table structure extractor.
TableFormer uses a dual-decoder transformer architecture with OTSL+ support for recognizing table structure from images.
Example
from omnidocs.tasks.table_extraction import TableFormerExtractor, TableFormerConfig
# Fast mode (default)
extractor = TableFormerExtractor(config=TableFormerConfig())
# Accurate mode with GPU
extractor = TableFormerExtractor(
config=TableFormerConfig(
mode="accurate",
device="cuda",
do_cell_matching=True,
)
)
TableFormerMode
¶
Bases: str, Enum
TableFormer inference mode.
TableFormerConfig
¶
Bases: BaseModel
Configuration for TableFormer table structure extractor.
TableFormer is a transformer-based model that predicts table structure using OTSL (Optimal Table Structure Language) tags and cell bounding boxes.
| ATTRIBUTE | DESCRIPTION |
|---|---|
mode |
Inference mode - "fast" or "accurate"
TYPE:
|
device |
Device for inference - "cpu", "cuda", "mps", or "auto"
TYPE:
|
num_threads |
Number of CPU threads for inference
TYPE:
|
do_cell_matching |
Whether to match predicted cells with OCR text cells
TYPE:
|
artifacts_path |
Path to pre-downloaded model artifacts
TYPE:
|
repo_id |
HuggingFace model repository
TYPE:
|
revision |
Model revision/tag
TYPE:
|
Example
from omnidocs.tasks.table_extraction import TableFormerExtractor, TableFormerConfig
# Fast mode
extractor = TableFormerExtractor(config=TableFormerConfig(mode="fast"))
# Accurate mode with GPU
extractor = TableFormerExtractor(
config=TableFormerConfig(
mode="accurate",
device="cuda",
do_cell_matching=True,
)
)
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 |