Skip to main content

gmft

Documentation Status

There are many pdfs out there, and many of those pdfs have tables. But despite a plethora of table extraction options, there is still no definitive extraction method.

About

gmft converts pdf tables to many formats. It is lightweight, modular, and performant. Batteries included: it just works, offering strong performance with the default settings.

It relies on microsoft's Table Transformers, qualitatively the most performant and reliable of the many alternatives.

Install: pip install gmft

Quickstarts: demo notebook, bulk extract, readthedocs.

Documentation: readthedocs

Why should I use gmft?

Fast, lightweight, and performant, gmft is a great choice for extracting tables from pdfs.

The extraction quality is superb: check out the bulk extract notebook for approximate quality. When testing the same tables across many table extraction options, gmft fares extremely well.

Many Formats

We support the following export options:

  • Pandas dataframe
  • By extension: markdown, latex, html, csv, json, etc.
  • List of text + positions
  • Cropped image of table
  • Table caption

Cropped images can be passed into a vision recognizer, like:

  • GPT-4 vision
  • Mathpix/Adobe/Google/Amazon/Azure/etc.
  • Or saved to disk for human evaluation

Lightweight

gmft is very lightweight. It can run on cpu - no GPU necessary.

High throughput

Benchmark using Colab's cpu indicates ~1.381 s/page; converting to df takes ~1.168 s/table. This makes gmft about 10x faster than alternatives like unstructured, nougat, and open-parse/unitable on cpu.

  • The base model, Smock et al.'s Table Transformer, is very efficient.
  • gmft focuses on table extraction, so figures, titles, sections, etc. are not extracted.
  • In most cases, OCR is not necessary; pdfs already contain text positional data. Using this existing data drastically speeds up inference. For images or scanned pdfs, bboxes can be exported for further processing.
  • PyPDFium2 is chosen for its high throughput and permissive license.

Few dependencies

gmft does not require any external dependencies (detectron2, poppler, paddleocr, tesseract etc.)

To install gmft, first install transformers and pytorch with the necessary GPU/CPU options. We also rely on pypdfium2 and transformers.

Dependable

The base model is Microsoft's Table Transformer (TATR) pretrained on PubTables-1M, which works best with scientific papers. TATR handles implicit table structure very well. Current failure modes include OCR issues, merged cells, or false positives. Even so, the text is highly useable, and alignment of a value to its row/column header remains very accurate because of the underlying procedural algorithm.

We invite you to explore the comparison notebooks to survey use cases and compare results.

As of gmft v0.3, the library supports multiple-column headers (TATRFormatConfig.enable_multi_header = True), spanning cells (TATRFormatConfig.semantic_spanning_cells = True), and rotated tables.

Why should I not use gmft?

gmft focuses on tables, and aims to maximize performance on tables alone. If you need to extract other document features like figures or table of contents, you may want a different tool. You should instead check out: (in no particular order) marker, nougat, open-parse, docling, unstructured, surya, deepdoctection, DocTR. For table detection, img2table is excellent for tables with explicit (solid) cell boundaries.

Current limitations include: false positives (references, indexes, and large columnar text), false negatives, and no OCR support.

Quickstart

See the docs and the config guide for more information. The demo notebook and bulk extract contain more comprehensive code examples.

# new in v0.3: gmft.auto
from gmft.auto import CroppedTable, TableDetector, AutoTableFormatter, AutoTableDetector
from gmft.pdf_bindings import PyPDFium2Document

detector = AutoTableDetector()
formatter = AutoTableFormatter()

def ingest_pdf(pdf_path): # produces list[CroppedTable]
    doc = PyPDFium2Document(pdf_path)
    tables = []
    for page in doc:
        tables += detector.extract(page)
    return tables, doc

tables, doc = ingest_pdf("path/to/pdf.pdf")
doc.close() # once you're done with the document

Configuration

See the config guide for discussion on gmft settings.

Development

git clone https://github.com/conjuncts/gmft
cd gmft
pip install -e .
pip install pytest

Run tests:

tests are in ./test directory

Build docs:

cd docs
make html

What does gmft stand for?

give

me

formatted

tables!

Acknowledgements

  • I gratefully acknowledge the support of Vanderbilt Data Science Institute and the Zhongyue Yang Lab at Vanderbilt.
  • The library builds upon work by:
    • Smock, Brandon, Rohith Pesala, and Robin Abraham. "PubTables-1M: Towards comprehensive table extraction from unstructured documents." Proceedings of the IEEE/CVF Conference on Computer Vision and Pattern Recognition. 2022.
    • Niels Rogge from huggingface.

License

GMFT is released under MIT.

PyMuPDF support is available in a separate repository in observance of pymupdf's AGPL 3.0 license.

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

gmft-0.4.4.tar.gz (63.6 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

gmft-0.4.4-py3-none-any.whl (76.5 kB view details)

Uploaded Python 3

File details

Details for the file gmft-0.4.4.tar.gz.

File metadata

  • Download URL: gmft-0.4.4.tar.gz
  • Upload date:
  • Size: 63.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: python-requests/2.32.3

File hashes

Hashes for gmft-0.4.4.tar.gz
Algorithm Hash digest
SHA256 14d2f9400b48d7ec3598ba685111c40598798202c7eb33c6122d299fb6e9747d
MD5 845124b341c38179c0fa401ce83f522b
BLAKE2b-256 d0364cf3bee780161646d98d5ec98deda6596e68afd0ab0a67e2cbae992aefbf

See more details on using hashes here.

File details

Details for the file gmft-0.4.4-py3-none-any.whl.

File metadata

  • Download URL: gmft-0.4.4-py3-none-any.whl
  • Upload date:
  • Size: 76.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: python-requests/2.32.3

File hashes

Hashes for gmft-0.4.4-py3-none-any.whl
Algorithm Hash digest
SHA256 48edae64a1c2d6cb0cdbf98cb72cea43a4f65fc3d7f5947a349cb53c5c781714
MD5 871bc8fb99794f68581a85ae883c751b
BLAKE2b-256 ff8efdb7b4444a7712368d66f037e1a875a1e868ab33fca4ba7ec44902ee94ee

See more details on using hashes here.

Release history Release notifications | RSS feed

This release

0.4.4 This release

2 files

0.4.3

2 files

0.4.2

2 files

0.4.1

2 files

0.4.0

2 files

0.3.2

2 files

0.3.1

2 files

0.3.0

2 files

0.2.2

2 files

0.2.1

2 files

0.2.0

2 files

0.1.1

2 files

0.1.0

2 files

0.0.4

2 files

0.0.3

2 files

0.0.2

2 files

0.0.1

2 files

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page