Preprint
Large Language Models

ERNIE Layout

October 1, 2022

0

Citations

0

Influential Citations

Venue

2022

Year

Abstract

Reorganizes tokens using layout information, combines text and visual embeddings, utilizes multi-modal transformers with spatial aware disentangled attention.

Analysis

Why This Paper Matters

Understanding documents that mix text and visual elements—like invoices, receipts, forms, and scanned pages—is a critical challenge for AI systems. Traditional NLP models treat text as a flat sequence, ignoring spatial cues such as columns, tables, and headings. ERNIE-Layout tackles this by explicitly incorporating layout information into a multi-modal transformer, enabling the model to grasp the logical reading order and visual structure of documents. This matters because real-world documents are rarely linear; they rely on layout to convey meaning. By learning from both text and image patches with spatial awareness, ERNIE-Layout sets a new benchmark for document AI tasks.

How It Works

ERNIE-Layout processes a document in three main stages: serialization, embedding, and multi-modal transformer encoding.

Serialization Module

Figure 3

Inspired by human reading habits, the model uses a Document-Parser (based on Layout-Parser) to detect document elements like paragraphs, lists, tables, and figures from OCR output. It then applies element-specific algorithms to determine the correct reading order, rearranging the token sequence accordingly.

Text Embedding

Figure 4

Text tokens are embedded using token embeddings, 1D position embeddings, and token type embeddings.

Visual Embedding

Figure 5

A Faster-RCNN backbone extracts visual features from the document image (resized to 224x224). An adaptive pooling layer converts the output into a 7x7 feature map, which is flattened into a visual sequence and projected to the same dimension as text embeddings.

Layout Embedding

Figure 6

Separate embedding layers for x-axis and y-axis coordinates (normalized to [0,1000]) capture spatial positions.

Ultimate Input Representation

Figure 7

The final input H combines text, visual, and layout embeddings.

Multi-modal Transformer

Figure 8

Inspired by DeBERTa's disentangled attention, ERNIE-Layout computes attention weights using separate matrices for content and relative spatial positions. This spatial-aware disentangled attention allows layout features to directly influence token interactions.

Pre-training Tasks

  • Reading Order Prediction: The model predicts whether token j is the next token of token i, learning layout-aware sequential relationships.
  • Replaced Region Prediction: 10% of image patches are replaced with patches from other images; the model predicts which patches are swapped, fostering fine-grained text-image alignment.
  • Masked Visual-Language Modeling and Text-Image Alignment further strengthen cross-modal understanding.

The model uses 24 transformer layers (1024 hidden units, 16 heads), initialized from RoBERTa-large, with a maximum text sequence length of 512 and 49 visual tokens.

Results

ERNIE-Layout achieves state-of-the-art performance across several benchmarks:

  • Form and Receipt Understanding: FUNSD, SROIE, Kleister-NDA, CORD datasets.
  • Document Image Classification: RVL-CDIP dataset.
  • Document Visual Question Answering: DocVQA dataset.

These results demonstrate that incorporating layout knowledge and spatial-aware attention significantly improves document understanding compared to models that treat text and images separately.

Significance

ERNIE-Layout advances the field by showing that layout is not just an auxiliary feature but a core component for understanding visually-rich documents. Its serialization module and spatial-aware attention provide a principled way to integrate layout into transformer architectures. This work has practical implications for automating document processing in industries like finance, legal, and healthcare, where forms and receipts are ubiquitous. Future research could extend this approach to handle more complex layouts, multilingual documents, or real-time processing scenarios.