TWIX: Automatically Reconstructing Structured Data from Templatized Documents

Yiming Lin, Mawil Hasan, Rohan Kosalge, Alvin Cheung, Aditya G. ParameswaranarXiv 2025 · arXiv · OpenReview

Abstract

Many documents, which we call templatized documents, are programmatically generated by populating fields in a visual template. Effective data extraction from these documents is crucial to supporting downstream analytical tasks. Current data extraction tools often struggle with complex document layouts, incur high latency and/or cost on large datasets, and often require significant human effort when extracting tables or values given user-specified fields from documents. The key insight of our tool, TWIX, is to predict the underlying template used to create such documents, modeling the visual and structural commonalities across documents. Data extraction based on this predicted template provides a more principled, accurate, and efficient solution at a low cost. Comprehensive evaluations on 34 diverse real-world datasets show that uncovering the template is crucial for data extraction from templatized documents. TWIX achieves over 90% precision and recall on average, outperforming tools from industry: Textract and Azure Document Intelligence, and vision-based LLMs like GPT-4-Vision, by over 25% in precision and recall. TWIX scales easily to large datasets and is 734X faster and 5836X cheaper than vision-based LLMs for extracting data from a large document collection with 817 pages.

Introduction

A massive amount of real-world data is locked in "templatized" documents—files programmatically generated by filling a visual template with data, such as police reports, tax forms, or invoices. Current extraction approaches generally fall into three categories: point extraction, general-purpose industry APIs, and vision-based Large Language Models (LLMs).

Point extraction focuses on finding specific fields in isolation, which often loses the global context and the hierarchical relationships between fields. Industry APIs frequently struggle with complex, nested, or non-standard layouts. While vision-based LLMs like GPT-4V are powerful, they are prohibitively expensive for large datasets, suffer from high latency, and struggle with precise spatial reasoning in complex tables. TWIX addresses these challenges by reconstructing the underlying visual template to serve as a structural backbone for extraction.

Comparison of TWIX structured extraction vs. traditional point extraction.

Methodology: Template-First Extraction

TWIX’s core philosophy is to "reverse-engineer" the original template by observing a collection of documents rather than treating every page as a new puzzle.

Field Prediction via Location Vectors

The system identifies fields by observing that across many records, "fields" (like "Date:") appear in consistent relative positions, while "values" (like "05/01/2023") vary. TWIX uses these positional matches and "gaps" to identify potential fields. It utilizes an LLM in a targeted, cost-effective manner solely to confirm if a cluster of phrases semantically resembles keys or values.

Field prediction via location vectors showing consistent spatial coordinates for template fields.

Row Labeling and Template Assembly

TWIX organizes phrases into rows and assigns labels (Key, Value, Key-Value, or Metadata) using Integer Linear Programming (ILP) to find the most probable valid layout. Once rows are labeled, they are assembled into a tree structure representing the document's hierarchy, including nested tables. With the template reconstructed, extracting data from the rest of the collection becomes a high-speed "fill-in-the-blank" process.

Evaluation and Results

TWIX was evaluated on 34 diverse real-world datasets, ranging from simple tables to complex, nested invoices. The system achieved over 90% precision and recall, outperforming AWS Textract and Azure Document Intelligence by over 25%. On "Hard" datasets, it surpassed GPT-4 Vision by 25% in precision and 33% in recall.

Beyond accuracy, TWIX offers significant efficiency gains. For a large collection of 817 pages, TWIX was 734x faster and 5836x cheaper than vision-based LLMs. Because the LLM is only used once to learn the template, the cost of processing 10,000 pages is nearly identical to processing 10 pages, making it highly scalable.

Conclusion

By treating the template as an invariant backbone, TWIX gains a global understanding of document structure that point-extraction tools lack. While it remains dependent on the quality of initial OCR and assumes relatively static templates, TWIX represents a major step forward in efficient, high-precision data extraction. Future work may involve integrating Document Layout Analysis (DLA) to better handle non-structured elements like images or free-form text within templatized documents.

Summary updated

Abstract

Many documents, that we call templatized documents, are programmatically generated by populating fields in a visual template. Effective data extraction from these documents is crucial to supporting downstream analytical tasks. Current data extraction tools often struggle with complex document layouts, incur high latency and/or cost on large datasets, and often require significant human effort, when extracting tables or values given user-specified fields from documents. The key insight of our tool, TWIX, is to predict the underlying template used to create such documents, modeling the visual and structural commonalities across documents. Data extraction based on this predicted template provides a more principled, accurate, and efficient solution at a low cost. Comprehensive evaluations on 34 diverse real-world datasets show that uncovering the template is crucial for data extraction from templatized documents. TWIX achieves over 90% precision and recall on average, outperforming tools from industry: Textract and Azure Document Intelligence, and vision-based LLMs like GPT-4-Vision, by over 25% in precision and recall. TWIX scales easily to large datasets and is 734X faster and 5836X cheaper than vision-based LLMs for extracting data from a large document collection with 817 pages.
BibTeX
@misc{lin2025twix,
  author = {Yiming Lin and Mawil Hasan and Rohan Kosalge and Alvin Cheung and Aditya G. Parameswaran},
  title = {{TWIX: Automatically Reconstructing Structured Data from Templatized Documents}},
  year = {2025},
  eprint = {2501.06659},
  archivePrefix = {arXiv},
  url = {https://arxiv.org/abs/2501.06659},
}
Figure