dolfim-ibm commited on
Commit
e41ba5d
·
verified ·
1 Parent(s): 51559fa

Create README.md

Browse files
Files changed (1) hide show
  1. README.md +176 -0
README.md ADDED
@@ -0,0 +1,176 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ---
2
+ license: apache-2.0
3
+ library_name: docling
4
+ pipeline_tag: image-to-text
5
+ tags:
6
+ - docling
7
+ - table-structure-recognition
8
+ - document-conversion
9
+ - tables
10
+ - pdf
11
+ - preview
12
+ ---
13
+
14
+ # TableFormerV2
15
+
16
+ > [!WARNING]
17
+ > **Preview model.** TableFormerV2 is a preview release. Its weights, outputs, and
18
+ > integration options can change in future releases without notice. The default
19
+ > table structure model in Docling is still
20
+ > [TableFormer V1](https://huggingface.co/docling-project/docling-models).
21
+
22
+ TableFormerV2 is a table structure recognition model for
23
+ [Docling](https://github.com/docling-project/docling). It takes an image of a
24
+ table and predicts its structure as an
25
+ [OTSL](https://arxiv.org/abs/2305.03393) token sequence, together with a
26
+ bounding box for each cell. Docling then maps the cells back to the text of the
27
+ document to build a `TableItem` in the `DoclingDocument`.
28
+
29
+ ## Model details
30
+
31
+ | | |
32
+ |---|---|
33
+ | **Developed by** | IBM Research, for the Docling project |
34
+ | **Model type** | Image-to-sequence (table structure + cell boxes) |
35
+ | **Parameters** | ~52M (FP32) |
36
+ | **Input** | Table crop, resized to 448×448 |
37
+ | **Output** | OTSL structure tokens and one bounding box per cell |
38
+ | **License** | Apache-2.0 |
39
+ | **Status** | Preview |
40
+
41
+ ### Architecture
42
+
43
+ - **Image encoder:** EfficientNetV2-S backbone with Squeeze-and-Excitation.
44
+ - **Spatial mixer:** depthwise separable convolutions (no self-attention in the
45
+ encoder).
46
+ - **Structure decoder:** cache-aware Transformer decoder with cross-attention to
47
+ the image features.
48
+ - **Bounding-box head:** multi-layer attention decoder that predicts one box per
49
+ cell.
50
+
51
+ The design is lightweight. It targets fast CPU inference and GPU batch
52
+ inference.
53
+
54
+ The model implementation is in
55
+ [`docling-ibm-models`](https://github.com/docling-project/docling-ibm-models)
56
+ (`docling_ibm_models.tableformer_v2`).
57
+
58
+ ## Usage with Docling
59
+
60
+ Install Docling:
61
+
62
+ ```bash
63
+ pip install docling
64
+ ```
65
+
66
+ Docling downloads the weights from this repository automatically the first time
67
+ you use the model. To download them before you run a conversion (for example,
68
+ for offline use), run:
69
+
70
+ ```bash
71
+ docling-tools models download tableformerv2
72
+ ```
73
+
74
+ ### Option 1: Use the preset
75
+
76
+ The fastest way to enable TableFormerV2 is to select it by name.
77
+
78
+ **CLI:**
79
+
80
+ ```bash
81
+ docling report.pdf --table-structure-engine docling_tableformer_v2
82
+ ```
83
+
84
+ **Docling Serve / Service Client:** set the `tableformer_v2` preset.
85
+
86
+ ```python
87
+ from docling.datamodel.service.options import ConvertDocumentsOptions
88
+ from docling.service_client import DoclingServiceClient
89
+
90
+ options = ConvertDocumentsOptions(table_structure_preset="tableformer_v2")
91
+
92
+ with DoclingServiceClient(url="http://localhost:5001") as client:
93
+ result = client.convert(source="report.pdf", options=options)
94
+ print(result.document.export_to_markdown())
95
+ ```
96
+
97
+ ### Option 2: Set the full pipeline options
98
+
99
+ Use the Python SDK when you need full control over the pipeline. Set
100
+ `table_structure_options` to `TableStructureV2Options`:
101
+
102
+ ```python
103
+ from docling.datamodel.accelerator_options import AcceleratorOptions
104
+ from docling.datamodel.base_models import InputFormat
105
+ from docling.datamodel.pipeline_options import (
106
+ PdfPipelineOptions,
107
+ TableStructureV2Options,
108
+ )
109
+ from docling.document_converter import DocumentConverter, PdfFormatOption
110
+
111
+ pipeline_options = PdfPipelineOptions(
112
+ do_table_structure=True,
113
+ table_structure_options=TableStructureV2Options(
114
+ # True: match the predicted cells to the text cells of the PDF.
115
+ # False: use the cells predicted by the model and ignore the PDF cells.
116
+ do_cell_matching=True,
117
+ ),
118
+ accelerator_options=AcceleratorOptions(device="auto", num_threads=8),
119
+ )
120
+
121
+ converter = DocumentConverter(
122
+ format_options={
123
+ InputFormat.PDF: PdfFormatOption(pipeline_options=pipeline_options),
124
+ }
125
+ )
126
+
127
+ result = converter.convert("report.pdf")
128
+
129
+ for table in result.document.tables:
130
+ print(table.export_to_dataframe())
131
+ ```
132
+
133
+ To load pre-downloaded weights, set `artifacts_path` on the pipeline options:
134
+
135
+ ```python
136
+ pipeline_options = PdfPipelineOptions(
137
+ artifacts_path="/path/to/models", # contains docling-project--TableFormerV2/
138
+ table_structure_options=TableStructureV2Options(),
139
+ )
140
+ ```
141
+
142
+ ### Options
143
+
144
+ | Option | Default | Description |
145
+ |---|---|---|
146
+ | `do_cell_matching` | `True` | Match the predicted cells to the PDF text cells. Set to `False` if PDF cells span more than one column, because this can break the table output. |
147
+
148
+ ## Limitations
149
+
150
+ - This is a **preview** model. Quality and behavior can change between
151
+ releases.
152
+ - On Apple Silicon, the model runs on CPU. Docling does not use MPS for this
153
+ model.
154
+ - The model sees only the table crop. Errors in the layout model (missed or
155
+ wrongly cropped tables) propagate to the table structure.
156
+
157
+ ## License
158
+
159
+ This model is released under the
160
+ [Apache License 2.0](https://www.apache.org/licenses/LICENSE-2.0).
161
+
162
+ ## Citation
163
+
164
+ If you use TableFormerV2, please cite Docling:
165
+
166
+ ```bibtex
167
+ @misc{Docling,
168
+ author = {Docling Team},
169
+ title = {Docling: An Efficient Open-Source Toolkit for AI-driven Document Conversion},
170
+ url = {https://arxiv.org/abs/2501.17887},
171
+ eprint = {2501.17887},
172
+ archivePrefix = {arXiv},
173
+ doi = {10.48550/arXiv.2501.17887},
174
+ year = {2025}
175
+ }
176
+ ```