Overview¶
Table Extraction Module.
Provides extractors for detecting and extracting table structure from document images. Outputs structured table data with cells, spans, and multiple export formats (HTML, Markdown, Pandas DataFrame).
Available Extractors
- TableFormerExtractor: Transformer-based table structure extractor
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()
# Get Markdown
md = result.to_markdown()
# Access cells
for cell in result.cells:
print(f"[{cell.row},{cell.col}] {cell.text}")
BaseTableExtractor
¶
Bases: ABC
Abstract base class for table structure extractors.
Table extractors analyze table images to detect cell structure, identify headers, and extract text content.
Example
extract
abstractmethod
¶
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. If not provided, model will attempt to extract text.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
TableOutput
|
TableOutput with cells, structure, and export methods |
Example
Source code in omnidocs/tasks/table_extraction/base.py
batch_extract
¶
batch_extract(
images: List[Union[Image, ndarray, str, Path]],
ocr_outputs: Optional[List[OCROutput]] = None,
progress_callback: Optional[
Callable[[int, int], None]
] = None,
) -> List[TableOutput]
Extract tables from multiple images.
Default implementation loops over extract(). Subclasses can override for optimized batching.
| PARAMETER | DESCRIPTION |
|---|---|
images
|
List of table images
TYPE:
|
ocr_outputs
|
Optional list of OCR results (same length as images)
TYPE:
|
progress_callback
|
Optional function(current, total) for progress
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
List[TableOutput]
|
List of TableOutput in same order as input |
Examples:
Source code in omnidocs/tasks/table_extraction/base.py
extract_document
¶
extract_document(
document: Document,
table_bboxes: Optional[List[List[float]]] = None,
progress_callback: Optional[
Callable[[int, int], None]
] = None,
) -> List[TableOutput]
Extract tables from all pages of a document.
| PARAMETER | DESCRIPTION |
|---|---|
document
|
Document instance
TYPE:
|
table_bboxes
|
Optional list of table bounding boxes per page. Each element should be a list of [x1, y1, x2, y2] coords.
TYPE:
|
progress_callback
|
Optional function(current, total) for progress
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
List[TableOutput]
|
List of TableOutput, one per detected table |
Examples:
Source code in omnidocs/tasks/table_extraction/base.py
BoundingBox
¶
Bases: BaseModel
Bounding box in pixel coordinates.
to_list
¶
to_xyxy
¶
from_list
classmethod
¶
Create from [x1, y1, x2, y2] list.
Source code in omnidocs/tasks/table_extraction/models.py
from_ltrb
classmethod
¶
Create from left, top, right, bottom coordinates.
to_normalized
¶
Convert to normalized coordinates (0-1024 range).
| PARAMETER | DESCRIPTION |
|---|---|
image_width
|
Original image width in pixels
TYPE:
|
image_height
|
Original image height in pixels
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
BoundingBox
|
New BoundingBox with coordinates in 0-1024 range |
Source code in omnidocs/tasks/table_extraction/models.py
CellType
¶
Bases: str, Enum
Type of table cell.
TableCell
¶
Bases: BaseModel
Single table cell with position, span, and content.
The cell position uses 0-indexed row/column indices. Spans indicate how many rows/columns the cell occupies.
to_dict
¶
Convert to dictionary representation.
Source code in omnidocs/tasks/table_extraction/models.py
TableOutput
¶
Bases: BaseModel
Complete table extraction result.
Provides multiple export formats and utility methods for working with extracted table data.
Example
get_cell
¶
Get cell at specific position.
Handles merged cells by returning the cell that covers the position.
Source code in omnidocs/tasks/table_extraction/models.py
get_row
¶
get_column
¶
to_html
¶
Convert table to HTML string.
| PARAMETER | DESCRIPTION |
|---|---|
include_styles
|
Whether to include basic CSS styling
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
str
|
HTML table string |
Source code in omnidocs/tasks/table_extraction/models.py
229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 | |
to_dataframe
¶
Convert table to Pandas DataFrame.
| RETURNS | DESCRIPTION |
|---|---|
|
pandas.DataFrame with table data |
| RAISES | DESCRIPTION |
|---|---|
ImportError
|
If pandas is not installed |
Source code in omnidocs/tasks/table_extraction/models.py
to_markdown
¶
Convert table to Markdown format.
Note: Markdown tables don't support merged cells, so spans are ignored and only the top-left cell value is used.
| RETURNS | DESCRIPTION |
|---|---|
str
|
Markdown table string |
Source code in omnidocs/tasks/table_extraction/models.py
to_dict
¶
Convert to dictionary representation.
Source code in omnidocs/tasks/table_extraction/models.py
save_json
¶
Save to JSON file.
load_json
classmethod
¶
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,
)
)
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
TableFormerMode
¶
Bases: str, Enum
TableFormer inference mode.
base
¶
Base class for table extractors.
Defines the abstract interface that all table extractors must implement.
BaseTableExtractor
¶
Bases: ABC
Abstract base class for table structure extractors.
Table extractors analyze table images to detect cell structure, identify headers, and extract text content.
Example
extract
abstractmethod
¶
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. If not provided, model will attempt to extract text.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
TableOutput
|
TableOutput with cells, structure, and export methods |
Example
Source code in omnidocs/tasks/table_extraction/base.py
batch_extract
¶
batch_extract(
images: List[Union[Image, ndarray, str, Path]],
ocr_outputs: Optional[List[OCROutput]] = None,
progress_callback: Optional[
Callable[[int, int], None]
] = None,
) -> List[TableOutput]
Extract tables from multiple images.
Default implementation loops over extract(). Subclasses can override for optimized batching.
| PARAMETER | DESCRIPTION |
|---|---|
images
|
List of table images
TYPE:
|
ocr_outputs
|
Optional list of OCR results (same length as images)
TYPE:
|
progress_callback
|
Optional function(current, total) for progress
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
List[TableOutput]
|
List of TableOutput in same order as input |
Examples:
Source code in omnidocs/tasks/table_extraction/base.py
extract_document
¶
extract_document(
document: Document,
table_bboxes: Optional[List[List[float]]] = None,
progress_callback: Optional[
Callable[[int, int], None]
] = None,
) -> List[TableOutput]
Extract tables from all pages of a document.
| PARAMETER | DESCRIPTION |
|---|---|
document
|
Document instance
TYPE:
|
table_bboxes
|
Optional list of table bounding boxes per page. Each element should be a list of [x1, y1, x2, y2] coords.
TYPE:
|
progress_callback
|
Optional function(current, total) for progress
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
List[TableOutput]
|
List of TableOutput, one per detected table |
Examples:
Source code in omnidocs/tasks/table_extraction/base.py
models
¶
Pydantic models for table extraction outputs.
Provides structured table data with cells, spans, and multiple export formats including HTML, Markdown, and Pandas DataFrame conversion.
Example
CellType
¶
Bases: str, Enum
Type of table cell.
BoundingBox
¶
Bases: BaseModel
Bounding box in pixel coordinates.
to_list
¶
to_xyxy
¶
from_list
classmethod
¶
Create from [x1, y1, x2, y2] list.
Source code in omnidocs/tasks/table_extraction/models.py
from_ltrb
classmethod
¶
Create from left, top, right, bottom coordinates.
to_normalized
¶
Convert to normalized coordinates (0-1024 range).
| PARAMETER | DESCRIPTION |
|---|---|
image_width
|
Original image width in pixels
TYPE:
|
image_height
|
Original image height in pixels
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
BoundingBox
|
New BoundingBox with coordinates in 0-1024 range |
Source code in omnidocs/tasks/table_extraction/models.py
TableCell
¶
Bases: BaseModel
Single table cell with position, span, and content.
The cell position uses 0-indexed row/column indices. Spans indicate how many rows/columns the cell occupies.
to_dict
¶
Convert to dictionary representation.
Source code in omnidocs/tasks/table_extraction/models.py
TableOutput
¶
Bases: BaseModel
Complete table extraction result.
Provides multiple export formats and utility methods for working with extracted table data.
Example
get_cell
¶
Get cell at specific position.
Handles merged cells by returning the cell that covers the position.
Source code in omnidocs/tasks/table_extraction/models.py
get_row
¶
get_column
¶
to_html
¶
Convert table to HTML string.
| PARAMETER | DESCRIPTION |
|---|---|
include_styles
|
Whether to include basic CSS styling
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
str
|
HTML table string |
Source code in omnidocs/tasks/table_extraction/models.py
229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 | |
to_dataframe
¶
Convert table to Pandas DataFrame.
| RETURNS | DESCRIPTION |
|---|---|
|
pandas.DataFrame with table data |
| RAISES | DESCRIPTION |
|---|---|
ImportError
|
If pandas is not installed |
Source code in omnidocs/tasks/table_extraction/models.py
to_markdown
¶
Convert table to Markdown format.
Note: Markdown tables don't support merged cells, so spans are ignored and only the top-left cell value is used.
| RETURNS | DESCRIPTION |
|---|---|
str
|
Markdown table string |
Source code in omnidocs/tasks/table_extraction/models.py
to_dict
¶
Convert to dictionary representation.
Source code in omnidocs/tasks/table_extraction/models.py
save_json
¶
Save to JSON file.
load_json
classmethod
¶
tableformer
¶
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 |