docling-ibm-models 0.1.0__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (32) hide show
  1. docling_ibm_models/layoutmodel/layout_predictor.py +171 -0
  2. docling_ibm_models/tableformer/__init__.py +0 -0
  3. docling_ibm_models/tableformer/common.py +200 -0
  4. docling_ibm_models/tableformer/data_management/__init__.py +0 -0
  5. docling_ibm_models/tableformer/data_management/data_transformer.py +504 -0
  6. docling_ibm_models/tableformer/data_management/functional.py +574 -0
  7. docling_ibm_models/tableformer/data_management/matching_post_processor.py +1325 -0
  8. docling_ibm_models/tableformer/data_management/tf_cell_matcher.py +596 -0
  9. docling_ibm_models/tableformer/data_management/tf_dataset.py +1233 -0
  10. docling_ibm_models/tableformer/data_management/tf_predictor.py +1020 -0
  11. docling_ibm_models/tableformer/data_management/transforms.py +396 -0
  12. docling_ibm_models/tableformer/models/__init__.py +0 -0
  13. docling_ibm_models/tableformer/models/common/__init__.py +0 -0
  14. docling_ibm_models/tableformer/models/common/base_model.py +279 -0
  15. docling_ibm_models/tableformer/models/table04_rs/__init__.py +0 -0
  16. docling_ibm_models/tableformer/models/table04_rs/bbox_decoder_rs.py +163 -0
  17. docling_ibm_models/tableformer/models/table04_rs/encoder04_rs.py +72 -0
  18. docling_ibm_models/tableformer/models/table04_rs/tablemodel04_rs.py +324 -0
  19. docling_ibm_models/tableformer/models/table04_rs/transformer_rs.py +203 -0
  20. docling_ibm_models/tableformer/otsl.py +541 -0
  21. docling_ibm_models/tableformer/settings.py +90 -0
  22. docling_ibm_models/tableformer/test_dataset_cache.py +37 -0
  23. docling_ibm_models/tableformer/test_prepare_image.py +99 -0
  24. docling_ibm_models/tableformer/utils/__init__.py +0 -0
  25. docling_ibm_models/tableformer/utils/app_profiler.py +243 -0
  26. docling_ibm_models/tableformer/utils/torch_utils.py +216 -0
  27. docling_ibm_models/tableformer/utils/utils.py +376 -0
  28. docling_ibm_models/tableformer/utils/variance.py +175 -0
  29. docling_ibm_models-0.1.0.dist-info/LICENSE +21 -0
  30. docling_ibm_models-0.1.0.dist-info/METADATA +172 -0
  31. docling_ibm_models-0.1.0.dist-info/RECORD +32 -0
  32. docling_ibm_models-0.1.0.dist-info/WHEEL +4 -0
@@ -0,0 +1,172 @@
1
+ Metadata-Version: 2.1
2
+ Name: docling-ibm-models
3
+ Version: 0.1.0
4
+ Summary: This package contains the AI models used by the Docling PDF conversion package
5
+ License: MIT
6
+ Keywords: docling,convert,document,pdf,layout model,segmentation,table structure,table former
7
+ Author: Nikos Livathinos
8
+ Author-email: nli@zurich.ibm.com
9
+ Requires-Python: >=3.11,<4.0
10
+ Classifier: Development Status :: 5 - Production/Stable
11
+ Classifier: Intended Audience :: Developers
12
+ Classifier: Intended Audience :: Science/Research
13
+ Classifier: License :: OSI Approved :: MIT License
14
+ Classifier: Operating System :: MacOS :: MacOS X
15
+ Classifier: Operating System :: POSIX :: Linux
16
+ Classifier: Programming Language :: Python :: 3
17
+ Classifier: Programming Language :: Python :: 3.11
18
+ Classifier: Programming Language :: Python :: 3.12
19
+ Classifier: Topic :: Scientific/Engineering :: Artificial Intelligence
20
+ Requires-Dist: Distance (>=0.1.3,<0.2.0)
21
+ Requires-Dist: Pillow (>=10.0.0,<11.0.0)
22
+ Requires-Dist: apted (>=1.0.3,<2.0.0)
23
+ Requires-Dist: jsonlines (>=3.1.0,<4.0.0)
24
+ Requires-Dist: lxml (>=4.9.1,<5.0.0)
25
+ Requires-Dist: mean_average_precision (>=2021.4.26.0,<2022.0.0.0)
26
+ Requires-Dist: numpy (>=1.24.4,<2.0.0)
27
+ Requires-Dist: onnxruntime (>=1.16.2,<2.0.0)
28
+ Requires-Dist: opencv-python (>=4.9.0.80,<5.0.0.0) ; sys_platform != "linux"
29
+ Requires-Dist: opencv-python-headless (>=4.9.0.80,<5.0.0.0) ; sys_platform == "linux"
30
+ Requires-Dist: torch @ https://download.pytorch.org/whl/cpu/torch-2.2.2%2Bcpu-cp311-cp311-linux_x86_64.whl ; python_version == "3.11" and platform_machine == "x86_64" and sys_platform == "linux"
31
+ Requires-Dist: torch @ https://download.pytorch.org/whl/cpu/torch-2.2.2%2Bcpu-cp312-cp312-linux_x86_64.whl ; python_version == "3.12" and platform_machine == "x86_64" and sys_platform == "linux"
32
+ Requires-Dist: torch @ https://download.pytorch.org/whl/cpu/torch-2.2.2-cp311-none-macosx_10_9_x86_64.whl ; python_version == "3.11" and platform_machine == "x86_64" and sys_platform == "darwin"
33
+ Requires-Dist: torch @ https://download.pytorch.org/whl/cpu/torch-2.2.2-cp311-none-macosx_11_0_arm64.whl ; python_version == "3.11" and platform_machine == "arm64" and sys_platform == "darwin"
34
+ Requires-Dist: torch @ https://download.pytorch.org/whl/cpu/torch-2.2.2-cp312-none-macosx_10_9_x86_64.whl ; python_version == "3.12" and platform_machine == "x86_64" and sys_platform == "darwin"
35
+ Requires-Dist: torch @ https://download.pytorch.org/whl/cpu/torch-2.2.2-cp312-none-macosx_11_0_arm64.whl ; python_version == "3.12" and platform_machine == "arm64" and sys_platform == "darwin"
36
+ Requires-Dist: torchvision @ https://download.pytorch.org/whl/cpu/torchvision-0.17.2%2Bcpu-cp311-cp311-linux_x86_64.whl ; python_version == "3.11" and platform_machine == "x86_64" and sys_platform == "linux"
37
+ Requires-Dist: torchvision @ https://download.pytorch.org/whl/cpu/torchvision-0.17.2%2Bcpu-cp312-cp312-linux_x86_64.whl ; python_version == "3.12" and platform_machine == "x86_64" and sys_platform == "linux"
38
+ Requires-Dist: torchvision @ https://download.pytorch.org/whl/cpu/torchvision-0.17.2-cp311-cp311-macosx_10_13_x86_64.whl ; python_version == "3.11" and platform_machine == "x86_64" and sys_platform == "darwin"
39
+ Requires-Dist: torchvision @ https://download.pytorch.org/whl/cpu/torchvision-0.17.2-cp311-cp311-macosx_11_0_arm64.whl ; python_version == "3.11" and platform_machine == "arm64" and sys_platform == "darwin"
40
+ Requires-Dist: torchvision @ https://download.pytorch.org/whl/cpu/torchvision-0.17.2-cp312-cp312-macosx_10_13_x86_64.whl ; python_version == "3.12" and platform_machine == "x86_64" and sys_platform == "darwin"
41
+ Requires-Dist: torchvision @ https://download.pytorch.org/whl/cpu/torchvision-0.17.2-cp312-cp312-macosx_11_0_arm64.whl ; python_version == "3.12" and platform_machine == "arm64" and sys_platform == "darwin"
42
+ Requires-Dist: tqdm (>=4.64.0,<5.0.0)
43
+ Description-Content-Type: text/markdown
44
+
45
+ # Docling-models
46
+
47
+ AI modules to support the Dockling PDF document conversion project.
48
+
49
+ - TableFormer is an AI module that recognizes the structure of a table and the bounding boxes of the table content.
50
+ - Layout model is an AI model that provides among other things ability to detect tables on the page. This package contains inference code for Layout model.
51
+
52
+
53
+ ## Installation Instructions
54
+
55
+ ### MacOS / Linux
56
+
57
+ To install `poetry` locally, use either `pip` or `homebrew`.
58
+
59
+ To install `poetry` on a docker container, do the following:
60
+ ```
61
+ ENV POETRY_NO_INTERACTION=1 \
62
+ POETRY_VIRTUALENVS_CREATE=false
63
+
64
+ # Install poetry
65
+ RUN curl -sSL 'https://install.python-poetry.org' > install-poetry.py \
66
+ && python install-poetry.py \
67
+ && poetry --version \
68
+ && rm install-poetry.py
69
+ ```
70
+
71
+ To install and run the package, simply set up a poetry environment
72
+
73
+ ```
74
+ poetry env use $(which python3.11)
75
+ poetry shell
76
+ ```
77
+
78
+ and install all the dependencies,
79
+
80
+ ```
81
+ poetry install # this will only install the deps from the poetry.lock
82
+
83
+ poetry install --no-dev # this will skip installing dev dependencies
84
+ ```
85
+
86
+ To update or add new dependencies from `pyproject.toml`, rebuild `poetry.lock`
87
+ ```
88
+ poetry update
89
+ ```
90
+
91
+
92
+ ## Pipeline Overview
93
+ ![Architecture](docs/tablemodel_overview_color.png)
94
+
95
+ ## Datasets
96
+ Below we list datasets used with their description, source, and ***"TableFormer Format"***. The TableFormer Format is our processed version of the version of the original format to work with the dataloader out of the box, and to augment the dataset when necassary to add missing groundtruth (bounding boxes for empty cells).
97
+
98
+
99
+ | Name | Description | URL |
100
+ | ------------- |:-------------:|----|
101
+ | PubTabNet | PubTabNet contains heterogeneous tables in both image and HTML format, 516k+ tables in the PubMed Central Open Access Subset | [PubTabNet](https://developer.ibm.com/exchanges/data/all/pubtabnet/) |
102
+ | FinTabNet| A dataset for Financial Report Tables with corresponding ground truth location and structure. 112k+ tables included.| [FinTabNet](https://developer.ibm.com/exchanges/data/all/fintabnet/) |
103
+ | TableBank| TableBank is a new image-based table detection and recognition dataset built with novel weak supervision from Word and Latex documents on the internet, contains 417K high-quality labeled tables. | [TableBank](https://github.com/doc-analysis/TableBank) |
104
+
105
+ ## Models
106
+
107
+ ### TableModel04:
108
+ ![TableModel04](docs/tbm04.png)
109
+ **TableModel04rs (OTSL)** is our SOTA method that using transformers in order to predict table structure and bounding box.
110
+
111
+
112
+ ## Configuration file
113
+
114
+ Example configuration can be seen inside test `tests/test_tf_predictor.py`
115
+ These are the main sections of the configuration file:
116
+
117
+ - `dataset`: The directory for prepared data and the parameters used during the data loading.
118
+ - `model`: The type, name and hyperparameters of the model. Also the directory to save/load the
119
+ trained checkpoint files.
120
+ - `train`: Parameters for the training of the model.
121
+ - `predict`: Parameters for the evaluation of the model.
122
+ - `dataset_wordmap`: Very important part that contains token maps.
123
+
124
+
125
+ ## Model weights
126
+
127
+ You can download the model weights and config files from the links:
128
+
129
+ - [TableFormer Checkpoint](https://huggingface.co/ds4sd/docling-models/tree/main/model_artifacts/tableformer)
130
+ - [beehive_v0.0.5](https://huggingface.co/ds4sd/docling-models/tree/main/model_artifacts/layout/beehive_v0.0.5)
131
+
132
+ Place the downloaded files into `tests/test_data/model_artifacts/` directory.
133
+
134
+
135
+ ## Inference Tests
136
+
137
+ This contains unit tests for Docling models.
138
+
139
+ First download the model weights (see above), then run:
140
+ ```
141
+ ./devtools/check_code.sh
142
+ ```
143
+
144
+ This will also generate prediction and matching visualizations that can be found here:
145
+ `tests\test_data\viz\`
146
+
147
+ Visualization outlines:
148
+ - `Light Pink`: border of recognized table
149
+ - `Grey`: OCR cells
150
+ - `Green`: prediction bboxes
151
+ - `Red`: OCR cells matched with prediction
152
+ - `Blue`: Post processed, match
153
+ - `Bold Blue`: column header
154
+ - `Bold Magenta`: row header
155
+ - `Bold Brown`: section row (if table have one)
156
+
157
+
158
+ ## Demo
159
+
160
+ A demo application allows to apply the `LayoutPredictor` on a directory `<input_dir>` that contains
161
+ `png` images and visualize the predictions inside another directory `<viz_dir>`.
162
+
163
+ First download the model weights (see above), then run:
164
+ ```
165
+ python -m demo.demo_layout_predictor -i <input_dir> -v <viz_dir>
166
+ ```
167
+
168
+ e.g.
169
+ ```
170
+ python -m demo.demo_layout_predictor -i tests/test_data/samples -v viz/
171
+ ```
172
+
@@ -0,0 +1,32 @@
1
+ docling_ibm_models/layoutmodel/layout_predictor.py,sha256=SdEsqlsb9zq2sCEzgim4geuCXlcno6eEu2PmYopGzOU,5557
2
+ docling_ibm_models/tableformer/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
3
+ docling_ibm_models/tableformer/common.py,sha256=RV2ptqgkfz1OIoN-WqiSeln0pkZ_7zTO9DhOcbvPS5k,6023
4
+ docling_ibm_models/tableformer/data_management/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
5
+ docling_ibm_models/tableformer/data_management/data_transformer.py,sha256=lNKkAk0VALbixapCuDDSIQKtA0QPCGQF8AGO3D64new,18263
6
+ docling_ibm_models/tableformer/data_management/functional.py,sha256=UrXsEm4DSc1QXdUPb0tZ7nvbg7mGVjpQhX3pGL6C5bA,20633
7
+ docling_ibm_models/tableformer/data_management/matching_post_processor.py,sha256=HYG-wx5PQC38hTQfyXr3zUnZ6--aSs55x8g9PdsROGU,54207
8
+ docling_ibm_models/tableformer/data_management/tf_cell_matcher.py,sha256=DFu428Cr84maT9WehdoZkpkJKeahwe5JlclvTC6fuVY,20870
9
+ docling_ibm_models/tableformer/data_management/tf_dataset.py,sha256=6_qSsYt6qoE2JBzUNrJfCDX3Kgg7tyrv3kimGLdEQ5o,49890
10
+ docling_ibm_models/tableformer/data_management/tf_predictor.py,sha256=I317-qMK13eqUvT4Ix2Q02uzkKQDCoKcf9GqIGVBy70,38508
11
+ docling_ibm_models/tableformer/data_management/transforms.py,sha256=_i1HXkX8LAuHbeGRrg8kF9yFNJRQZOKmWzxKt559ABQ,13268
12
+ docling_ibm_models/tableformer/models/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
13
+ docling_ibm_models/tableformer/models/common/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
14
+ docling_ibm_models/tableformer/models/common/base_model.py,sha256=_Pn6hjIx49DVTU-po6qsR788RhD7Q4FhVyBqaGl0tMw,9972
15
+ docling_ibm_models/tableformer/models/table04_rs/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
16
+ docling_ibm_models/tableformer/models/table04_rs/bbox_decoder_rs.py,sha256=mMZSGk0PjQ4_fhuP44_WJVzfxyLky6S3zlVxCrNKRgc,5991
17
+ docling_ibm_models/tableformer/models/table04_rs/encoder04_rs.py,sha256=vlDW890mCIzHdgaGXFZ4avlnCmuUCPHUaJ30P9N6eWo,1991
18
+ docling_ibm_models/tableformer/models/table04_rs/tablemodel04_rs.py,sha256=7iGkrTNLzjC1yn1zuA3N6DvBvbrcO_BR5tmHG3RKmXs,12159
19
+ docling_ibm_models/tableformer/models/table04_rs/transformer_rs.py,sha256=4106qxxH0w92CVOFzFuCb87tRMvqAUP3X3F1WT5Z47A,6371
20
+ docling_ibm_models/tableformer/otsl.py,sha256=k8l1hYWvcCkcnWbLxuBUYEcigYBFTRqiM2GBAHcUDok,21024
21
+ docling_ibm_models/tableformer/settings.py,sha256=UlpsP0cpJZR2Uk48lgysYy0om3fr8Xt3z1xzvlTw5j4,3067
22
+ docling_ibm_models/tableformer/test_dataset_cache.py,sha256=zvVJvUnYz4GxAQfPUmLTHUbqj0Yhi2vwgOBnsRgt1rI,818
23
+ docling_ibm_models/tableformer/test_prepare_image.py,sha256=oPmU93-yWIkCeUYulGQ1p676Vq-zcjw2EX24WA5lspA,3155
24
+ docling_ibm_models/tableformer/utils/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
25
+ docling_ibm_models/tableformer/utils/app_profiler.py,sha256=13dvwo5byzfP2ejqGBFwtOWNnS-0EZVUrjTpeevbke8,7993
26
+ docling_ibm_models/tableformer/utils/torch_utils.py,sha256=uN0rK9mSXy1ewBnBnILrWebJhhVU4N-XJZBqNiLJwlQ,8893
27
+ docling_ibm_models/tableformer/utils/utils.py,sha256=8Bxf1rEn977lFbY9NX0r5xh9PvxIRipQZX_EZW92XfA,10980
28
+ docling_ibm_models/tableformer/utils/variance.py,sha256=USjRwaMsCmzvc6PeWskaAJnUjbliRVd_MqNKLjMDQw8,4675
29
+ docling_ibm_models-0.1.0.dist-info/LICENSE,sha256=ACwmltkrXIz5VsEQcrqljq-fat6ZXAMepjXGoe40KtE,1069
30
+ docling_ibm_models-0.1.0.dist-info/METADATA,sha256=a1WTE9WZmQAkRhvb3VD9DtuJE64XL5Z5WdQ9Q0f1R6Q,8350
31
+ docling_ibm_models-0.1.0.dist-info/WHEEL,sha256=sP946D7jFCHeNz5Iq4fL4Lu-PrWrFsgfLXbbkciIZwg,88
32
+ docling_ibm_models-0.1.0.dist-info/RECORD,,
@@ -0,0 +1,4 @@
1
+ Wheel-Version: 1.0
2
+ Generator: poetry-core 1.9.0
3
+ Root-Is-Purelib: true
4
+ Tag: py3-none-any