Feature request: the document without table structure from the same conversion (one layout pass)

Aperta
#5,437 1 commento 0 reazioni 0 assegnatari Vedi su GitHub

I maintainer di solito rispondono entro 2 giorni

Nessuno ha ancora preso questa issue.

Valutazione

Difficoltà
4/5
Tempo stimato
3-5 giorni
Idoneità per principianti
48/100
Tipo di issue
Funzionalità
Chiarezza
Abbastanza chiara
Stato di attività
Attiva
Stack tecnologico
python
Ambito
ai, backend

Direzione di ricerca

Read the PageAssembleModel and ReadingOrderModel behavior described in the issue, then inspect Page.assembled and StandardPdfPipeline._assemble_document to find a suitable public API. Compare the proposed result with a separate conversion using do_table_structure=False, including Markdown output, page count, tables, pictures, and page numbering; done means the public path matches that conversion without running another model pass.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

enhancement pdf priority:medium
Requested feature

A public way to get, from one PDF conversion, the document with table structure (TableFormer) and the same document without it (what do_table_structure=False produces). Today the only public way to get both is to convert twice, which runs the layout model over every page twice.

Use case

A scientific-paper ingestion pipeline keeps two Markdown exports per paper:

  • the table-structured one, for tables;
  • the unstructured one, whose text is the stored, hashed source for downstream steps (sections, page-1 metadata).

Changing the unstructured export would invalidate everything stored from it, so it must stay byte-identical. Converting twice per paper costs roughly a quarter of the conversion time on our CPU-only hosts: the layout pass runs twice.

What we found (Docling 2.143.1, docling-core 2.105.0)

Without a table-structure prediction, PageAssembleModel falls back to Table(otsl_seq=[], table_cells=[], cluster=cluster, ...). ReadingOrderModel then adds the cluster's children under the table as a group. So after a conversion with do_table_structure=True, the unstructured document can be rebuilt without running any model:

result = converter.convert(source)          # do_table_structure=True
structured = result.document
for page in result.pages:
    if page.assembled is None:
        continue
    swap = {id(e): Table(label=e.cluster.label, id=e.cluster.id, text="", otsl_seq=[], table_cells=[],
                         cluster=e.cluster, page_no=page.page_no)
            for e in page.assembled.elements if isinstance(e, Table)}
    for name in ("elements", "body", "headers"):
        setattr(page.assembled, name, [swap.get(id(e), e) for e in getattr(page.assembled, name)])
pipeline = converter._get_pipeline(InputFormat.PDF)
unstructured = pipeline._assemble_document(result).document

On the papers we checked (19 and 46 pages, 12 and 29 tables), the export_to_markdown() of unstructured is identical to a separate do_table_structure=False conversion, including page_no=1. So are num_pages(), the table items (1×1 data plus the child group) and the picture items. The re-assembly takes 1–3 s.

It relies on two internals, Page.assembled and StandardPdfPipeline._assemble_document, so it can break on any release.

Proposal

One of these as public API, whichever fits the design better:

  1. a PdfPipelineOptions flag (for example also_produce_unstructured_tables: bool) that adds a second document to the ConversionResult; or
  2. a public method, for example StandardPdfPipeline.reassemble(conv_res, table_structure=False) -> DoclingDocument (or on ConversionResult), documented as running no model.

We are happy to open a PR for either, with a test that compares against a do_table_structure=False conversion.

Alternatives considered
  • Two conversions: what we do today, at the cost of a second layout pass.
  • A custom Markdown table serializer over the structured document: public API, but the output is not identical to the unstructured conversion. The cell order and tokenization differ.
Lingua principale
Python
Stelle
71k
Fork
5.4k
Merge medio
2g 22h
PR unite (30g)
161

Preparare l'ambiente

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di docling-project/docling

Tutte le issue di docling-project/docling

Issue simili

Altre issue su Python

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.