Preprint
Large Language Models

Layout LM v2

December 1, 2020

0

Citations

0

Influential Citations

Venue

2020

Year

Abstract

Uses a multi-modal Transformer model, to integrate text, layout, and image in the pre-training stage, to learn end-to-end cross-modal interaction.

Analysis

Why This Paper Matters

Document understanding has long been a challenge because documents contain not just text but also complex layouts, images, tables, and visual cues. Traditional NLP models ignore spatial and visual information, while computer vision models miss textual semantics. LayoutLMv2 bridges this gap by jointly pre-training on text, layout, and image modalities, enabling the model to learn cross-modal interactions from scratch. This is a significant step toward truly intelligent document processing systems that can handle forms, receipts, invoices, and other visually-rich documents.

How It Works

LayoutLMv2 builds on the original LayoutLM but introduces a critical change: visual information is integrated during pre-training rather than only at fine-tuning. The architecture is a multi-modal Transformer encoder that takes three types of embeddings as input.

Figure 1

Text Embeddings follow standard practice: WordPiece tokenization, with [CLS] and [SEP] tokens, plus token, 1D positional, and segment embeddings. The i-th text embedding is: ti = TokEmb(wi) + PosEmb1D(i) + SegEmb(si).

Visual Embeddings come from a ResNeXt-FPN CNN backbone. The page image is resized to 224×224, passed through the CNN, then average-pooled to a fixed W×H feature map. This is flattened into a sequence of visual tokens, each projected to match text embedding dimensions. A shared 1D positional embedding and a visual segment embedding [C] are added. The i-th visual embedding is: vi = Proj(VisTokEmb(I)i) + PosEmb1D(i) + SegEmb([C]).

Layout Embeddings encode bounding box coordinates from OCR. Coordinates are normalized to [0,1000] and embedded separately for x and y axes. For each token (text or visual), the layout embedding concatenates six features: xmin, xmax, ymin, ymax, width, height. The i-th layout embedding is: li = Concat(PosEmb2Dx(xmin, xmax, width), PosEmb2Dy(ymin, ymax, height)).

Figure 2

These three embeddings are summed and fed into a multi-modal Transformer encoder with a spatial-aware self-attention mechanism. Unlike standard self-attention which only uses absolute positions, spatial-aware attention explicitly models relative spatial relationships between tokens, crucial for understanding document layout.

The pre-training stage uses three tasks:

  • Masked Visual-Language Modeling (MVLM): Randomly mask text tokens and recover them using layout and visual clues. To prevent visual leakage, corresponding image regions are also masked.
  • Text-Image Alignment (TIA): Randomly cover image regions at the line level and predict for each text token whether its visual region is covered. This teaches fine-grained spatial correspondence.
  • Text-Image Matching (TIM): Predict whether the image and text come from the same document page. Negative samples are created by replacing the image with another document's page or dropping it entirely.

Pre-training uses the IIT-CDIP dataset, a large collection of scanned documents.

Results

LayoutLMv2 is fine-tuned on six public benchmarks:

  • FUNSD (form understanding)
  • CORD (receipt understanding)
  • SROIE (receipt understanding)
  • Kleister-NDA (long document understanding with complex layout)
  • RVL-CDIP (document image classification)
  • DocVQA (visual question answering on documents)

On all tasks, LayoutLMv2 achieves new state-of-the-art results, outperforming both the original LayoutLM and other multi-modal baselines. The gains are particularly notable on tasks requiring fine-grained spatial reasoning, such as form parsing and receipt extraction.

Significance

LayoutLMv2 demonstrates that joint pre-training across text, layout, and image modalities is highly effective for visually-rich document understanding. By learning cross-modal interactions from the start, the model develops a deeper understanding of document structure than models that only combine modalities at fine-tuning. The spatial-aware self-attention mechanism is a key innovation that explicitly captures relative positions, which is essential for layout-sensitive tasks. This work has practical implications for automating document processing in industries like finance, legal, and healthcare, where forms, receipts, and contracts are ubiquitous. Future work could explore extending this approach to other document types, reducing reliance on OCR, or incorporating more fine-grained visual features.