Robust PDF Document Conversion Using Recurrent Neural Networks

Maksym Lysak, Nikolaos Livathinos, Cesar Berrospi, Viktor Kuropiatnyk, Ahmed Nassar, Andre Carvalho, Michele Dolfi, Christoph Auer, Kasper Dinkla, Peter Staar

TL;DR

This paper introduces a novel method for converting PDF documents into structured data by directly processing the low-level PDF printing commands using recurrent neural networks. This approach achieves higher accuracy and finer-grained structural detail than existing visual methods, while also being more computationally efficient and requiring less memory, making it ideal for large-scale document conversion.

What Problem Does This Paper Address?

The vast and ever-growing number of PDF documents, particularly in academic and commercial sectors, poses a significant challenge for information retrieval and analysis. The PDF format itself is designed for visual presentation, not for preserving document structure. It essentially stores a series of low-level printing instructions, losing crucial semantic information like titles, section headers, paragraphs, lists, and tables. This makes it difficult to perform accurate semantic searches or extract structured data. Existing solutions often rely on visual interpretation of rendered PDF pages, which can be computationally expensive and may not capture fine-grained structural details.

Methods

The core innovation of this paper lies in treating PDF document structure recovery as a sequence labeling problem, similar to those tackled in Natural Language Processing (NLP). Instead of analyzing the visual rendering of a PDF page, the authors directly process the sequence of PDF printing commands. These commands are converted into a set of features (e.g., position, dimensions, text style) associated with each "text cell" (the output of a printing command).

These feature sequences are then fed into recurrent neural networks (RNNs), specifically sequence-to-sequence models. The authors explored various RNN architectures, including GRU and LSTM layers, and investigated the impact of bidirectional encoding and attention mechanisms. A key aspect of their approach is the "indexed feeding mode," where features are discretized into bins and then mapped to indices, mimicking how NLP models handle word embeddings. They also experimented with a transformer-based architecture but found it less effective for their specific task.

Advanced feature engineering, including the use of stacked one-hot encoded feature vectors, was crucial for improving performance. This technique allows for the incorporation of more features without exponentially increasing the model's complexity.

Datasets

The primary dataset used for training and evaluation is the "diverse dataset," which consists of 2,940 PDF pages annotated with 17 distinct labels (e.g., title, abstract, author, text, table, list). This dataset covers seven different publishing layouts. A subset of this data, containing only articles from the "Physical Review" journal, is referred to as the "uniform dataset." For reproducibility, these datasets have been published on Kaggle.

Key Insights and Ideas

  • Direct PDF Command Processing is Powerful: The paper demonstrates that directly processing the low-level PDF printing commands, rather than relying on visual rendering, can yield more accurate and detailed structural information.
  • NLP Techniques Adapt Well: The success of applying NLP-inspired sequence-to-sequence models (like LSTMs) to PDF structure recovery highlights the generalizability of these architectures to structured data sequences.
  • Indexed Feeding Mode is Crucial: Discretizing features and using an indexed feeding mode significantly outperforms direct feature feeding, suggesting that mapping features to discrete representations is beneficial for this task.
  • Feature Engineering Matters: Simple geometric features are a starting point, but incorporating more sophisticated features (e.g., distances between cells, textual properties) through techniques like stacking dramatically improves accuracy.
  • Transformer Models Not Always Superior: While transformers are state-of-the-art in many NLP tasks, they were found to be overly complex and sensitive to hyperparameter tuning for this specific PDF structure recovery problem, suggesting that simpler RNNs can be more effective with careful feature engineering.
  • Fine-grained Labels are Key: The ability to distinguish between a larger number of structural labels (17 in this case) leads to a more accurate and detailed document structure resolution compared to methods that use fewer, broader categories.

Key Results

The authors achieved a weighted average F1 score of 97% across 17 distinct structural labels with their best model (model-4, a seq2seq model with stacked features, bidirectional LSTM layers, and attention, without an active decoder). This model significantly outperforms previous state-of-the-art methods, including RRF models and image-based approaches like Mask-RCNN, especially on diverse document layouts. For instance, Mask-RCNN showed mixed performance, particularly struggling with subtitles and lists, while the proposed model achieved high scores across all labels. The proposed method is also computationally more efficient, requiring less memory and offering faster inference times compared to visual methods.

Limitations and Future Work

The authors acknowledge that their transformer-based model (model-5) performed poorly, suggesting that transformer models might be too complex for their dataset and task, requiring extensive hyperparameter tuning. They also note that while their model is language-agnostic, it doesn't include actual text content, which could be a limitation for certain downstream tasks.

Future work could involve exploring more advanced feature engineering techniques to further improve accuracy. The authors also suggest that their approach could be extended to handle more complex document structures and potentially incorporate textual content for even richer document understanding. The successful deployment of their model as a microservice within the Corpus Conversion Service (CCS) also points towards future work in optimizing cloud-native deployment strategies for AI models in document processing pipelines.

Summary updated

Abstract

The number of published PDF documents in both the academic and commercial world has increased exponentially in recent decades. There is a growing need to make their rich content discoverable to information retrieval tools. Achieving high-quality semantic searches demands that a document’s structural components such as title, section headers, paragraphs, (nested) lists, tables and figures (including their captions) are properly identified. Unfortunately, the PDF format is known to not conserve such structural information because it simply represents a document as a stream of low-level printing commands, in which one or more characters are placed in a bounding box with a particular styling. In this paper, we present a novel approach to document structure recovery in PDF using recurrent neural networks to process the low-level PDF data representation directly, instead of relying on a visual re-interpretation of the rendered PDF page, as has been proposed in previous literature. We demonstrate how a sequence of PDF printing commands can be used as input into a neural network and how the network can learn to classify each printing command according to its structural function in the page. This approach has three advantages: First, it can distinguish among more fine-grained labels (typically 10–20 labels as opposed to 1–5 with visual methods), which results in a more accurate and detailed document structure resolution. Second, it can take into account the text flow across pages more naturally compared to visual methods because it can concatenate the printing commands of sequential pages. Last, our proposed method needs less memory and it is computationally less expensive than visual methods. This allows us to deploy such models in production environments at a much lower cost. Through extensive architectural search in combination with advanced feature engineering, we were able to implement a model that yields a weighted average F1 score of 97% across 17 distinct structural labels. The best model we achieved is currently served in production environments on our Corpus Conversion Service (CCS), which was presented at KDD18. This model enhances the capabilities of CCS significantly, as it eliminates the need for human annotated label ground-truth for every unseen document layout. This proved particularly useful when applied to a huge corpus of PDF articles related to COVID-19.
BibTeX
@inproceedings{lysak2021robust,
  author = {Maksym Lysak and Nikolaos Livathinos and Cesar Berrospi and Viktor Kuropiatnyk and Ahmed Nassar and Andre Carvalho and Michele Dolfi and Christoph Auer and Kasper Dinkla and Peter Staar},
  title = {{Robust PDF Document Conversion Using Recurrent Neural Networks}},
  booktitle = {AAAI Conference on Artificial Intelligence},
  year = {2021},
  doi = {10.1609/aaai.v35i17.17777},
}
Figure