LayoutLM is a multimodal transformer architecture that fuses textual tokens with their corresponding 2D spatial coordinates to create a unified representation of a document. Unlike standard NLP models that treat text as a linear sequence, LayoutLM ingests bounding box coordinates for each word, allowing it to learn the relationship between what a word says and where it appears on the page. This spatial intelligence enables the model to understand that a number in a 'Total' row of a table has a different semantic function than the same number appearing in a body paragraph.
Glossary
LayoutLM

What is LayoutLM?
LayoutLM is a family of pre-trained transformer models that jointly model text and layout information from scanned documents to understand the spatial structure of forms and agreements.
The architecture combines a text embedding layer with four distinct spatial embedding layers representing the x-axis, y-axis, width, and height of each token's bounding box. These embeddings are summed and passed through a standard transformer encoder, allowing the model to attend jointly to text and layout. Pre-trained on massive corpora of scanned business documents using Masked Visual-Language Modeling and Multi-Label Document Classification objectives, LayoutLM achieves state-of-the-art results on downstream tasks like form understanding, receipt parsing, and complex legal contract structure extraction where spatial context is critical.
Key Features of LayoutLM
LayoutLM is a pre-trained transformer that jointly models text and visual layout information, enabling machines to understand the spatial structure of scanned documents, forms, and agreements.
Multimodal Joint Pre-Training
LayoutLM integrates text embeddings from BERT-style tokenization with 2D positional embeddings representing each token's bounding box coordinates on the page. This joint modeling allows the model to learn relationships between words and their spatial positions simultaneously.
- Text modality: Token-level word embeddings capture semantic meaning
- Layout modality: x0, y0, x1, y1 coordinates encode spatial position
- Visual modality: Optional image embeddings from Faster R-CNN capture font styles and visual features
The pre-training tasks include Masked Visual-Language Modeling (MVLM) where the model predicts masked tokens using both text and layout context, and Multi-Label Document Classification for understanding document types.
Spatial-Aware Self-Attention
Unlike standard transformers that treat text as a linear sequence, LayoutLM's attention mechanism incorporates relative spatial relationships between tokens. The model learns to attend to tokens that are spatially proximate or aligned in document structures.
- Captures column relationships in multi-column layouts
- Identifies key-value pairs in forms based on horizontal alignment
- Understands table cell relationships through grid-based spatial reasoning
- Distinguishes between headers, body text, and footnotes based on vertical position
This spatial awareness is critical for understanding structured documents where reading order is non-linear, such as invoices, contracts, and medical forms.
Pre-Training on IIT-CDIP Test Collection
LayoutLM was pre-trained on the IIT-CDIP Test Collection 1.0, a massive dataset containing over 6 million scanned documents from the tobacco industry litigation. This corpus provides diverse document layouts including letters, memos, emails, and forms.
- 6M+ documents with diverse layouts and structures
- Includes OCR-generated text with realistic noise and errors
- Covers multiple document types for robust generalization
- Enables transfer learning to downstream legal and financial document tasks
The scale and diversity of this pre-training data allows LayoutLM to develop strong priors about document structure that transfer effectively to legal, financial, and administrative document understanding tasks.
Document Understanding Benchmarks
LayoutLM established new state-of-the-art results on key document AI benchmarks, demonstrating the value of joint text-layout modeling over text-only approaches.
- FUNSD Dataset: Form understanding with semantic entity labeling and entity linking tasks. LayoutLM achieved significant improvements in extracting question-answer pairs from noisy scanned forms
- SROIE Dataset: Scanned receipt OCR and information extraction, where LayoutLM excelled at extracting company names, dates, and totals
- RVL-CDIP Dataset: Document image classification across 16 categories with 94.42% accuracy
- CORD Dataset: Consolidated receipt understanding requiring hierarchical parsing of menu items and prices
These benchmarks validate LayoutLM's effectiveness for real-world document processing pipelines in legal, financial, and administrative domains.
Token-Level Structural Classification
LayoutLM enables fine-grained token classification for extracting structured information from documents. Each token can be classified into semantic categories based on its textual content and spatial position.
- BIO tagging scheme: Tokens are labeled as Beginning, Inside, or Outside of entities
- Field extraction: Identify question labels, answer values, headers, and other field types
- Entity linking: Connect related tokens across the document, such as linking a header to its corresponding value
- Table cell classification: Assign row and column roles to tokens within detected table structures
This token-level approach is essential for legal document structure parsing, where precise identification of clauses, parties, dates, and obligations requires understanding both what the text says and where it appears on the page.
Integration with OCR Pipelines
LayoutLM is designed to work downstream of Optical Character Recognition (OCR) engines, accepting both the recognized text and the bounding box coordinates of each word as input. This architecture enables seamless integration with existing document processing pipelines.
- Compatible with Tesseract OCR, Azure Cognitive Services, and Amazon Textract
- Accepts hOCR format and other structured OCR output standards
- Handles noisy OCR output through robust pre-training on real-world scanned documents
- Supports multi-page documents by processing pages independently or with page-level position encoding
For legal document structure parsing, this integration allows LayoutLM to consume the output of OCR engines and add semantic understanding of the document's logical structure, including section boundaries, header hierarchies, and reading order.
Frequently Asked Questions
Concise answers to the most common technical questions about Microsoft's multimodal document understanding model, bridging the gap between text semantics and spatial structure.
LayoutLM is a multimodal pre-trained transformer model that jointly models text and layout information from scanned documents. Unlike standard text-only transformers like BERT that treat a document as a flat sequence of tokens, LayoutLM incorporates the 2D spatial positioning of each word—specifically its bounding box coordinates (x0, y0, x1, y1)—as an explicit input modality. This allows the model to understand the spatial structure of forms and agreements. The architecture adds spatial embedding layers to the traditional token and positional embeddings, enabling the self-attention mechanism to relate words not just by their semantic context but also by their physical proximity and alignment on the page. For example, it can learn that a value directly to the right of a 'Total Due' label is the corresponding monetary amount, a relationship invisible to text-only models.
Enabling Efficiency, Speed & Accuracy
Intelligent Analysis, Decision & Execution
We build AI systems for teams that need search across company data, workflow automation across tools, or AI features inside products and internal software.
Talk to Us
Search across company data
Give teams answers from docs, tickets, runbooks, and product data with sources and permissions.
Useful when people spend too long searching or get different answers from different systems.

Automate internal workflows
Use AI to route work, draft outputs, trigger actions, and keep approvals and logs in place.
Useful when repetitive work moves across multiple tools and teams.

Add AI to products and internal tools
Build assistants, guided actions, or decision support into the software your team or customers already use.
Useful when AI needs to be part of the product, not a separate tool.
Related Terms
Core concepts and complementary technologies that form the ecosystem around multimodal document understanding, enabling the construction of robust legal document analysis pipelines.
Optical Character Recognition (OCR)
The foundational preprocessing step that converts scanned document images into machine-readable text. LayoutLM relies on OCR output to align text tokens with their 2D positional embeddings.
- Input: Scanned images, PDFs, or photographs of documents
- Output: Machine-encoded text with bounding box coordinates
- Key formats: HOCR, ALTO XML, and plain text with coordinate metadata
- Critical metric: Character Error Rate (CER) directly impacts downstream model accuracy
Optical Layout Analysis
The computational process of segmenting a document image into regions of interest—text columns, images, tables, and marginalia—before text recognition occurs. This step determines the spatial zones that LayoutLM's bounding box embeddings will encode.
- Detects text blocks, illustrations, and separator lines
- Enables zonal OCR for selective text extraction
- Critical for multi-column legal documents and complex forms
Table Extraction
The automated identification and reconstruction of tabular data structures into logical grids of rows, columns, and cells. LayoutLM's spatial attention mechanisms excel at understanding the two-dimensional relationships inherent in tables.
- Reconstructs merged cells and nested headers
- Preserves cell-to-header relationships for semantic querying
- Essential for extracting financial terms, schedules, and comparative clauses in contracts
Reading Order Detection
The algorithmic determination of the logical sequence in which text blocks should be read across a complex page layout. LayoutLM's spatial embeddings provide the geometric priors needed to resolve ambiguous multi-column or inset-heavy legal documents.
- Handles multi-column layouts and inset text boxes
- Resolves conflicts between visual proximity and logical flow
- Critical for reconstructing coherent narrative from scanned briefs and contracts
PDF Structural Extraction
The process of reconstructing logical document structure—paragraphs, headings, lists, and tables—from the unstructured stream of drawing commands in a PDF file. Unlike OCR-based approaches, this works directly with born-digital documents.
- Extracts text with precise coordinate metadata
- Identifies font changes that signal heading hierarchy
- Provides the structured input that LayoutLM can further enrich with semantic understanding
Graph-Based Document Parsing
A technique that represents text blocks as nodes and their spatial or semantic relationships as edges in a graph structure. This approach complements LayoutLM by providing an explicit relational model that can be fused with the model's implicit spatial attention.
- Models neighbor relationships between text blocks
- Enables graph neural network integration for structure prediction
- Handles complex layouts where simple linear reading order fails

About the author
Prasad Kumkar
CEO & MD, Inference Systems
Prasad Kumkar is the CEO & MD of Inference Systems and writes about AI systems architecture, LLM infrastructure, model serving, evaluation, and production deployment. Over 5+ years, he has worked across computer vision models, L5 autonomous vehicle systems, and LLM research, with a focus on taking complex AI ideas into real-world engineering systems.
His work and writing cover AI systems, large language models, AI agents, multimodal systems, autonomous systems, inference optimization, RAG, evaluation, and production AI engineering.
Partnered with leading AI, data, and software stack.
How We Work
Custom AI workflows for your Business
One-fit-all AI don't work for modern businesses. At Inferensys, we aim to understand your business & custom requirements; which we use to define most efficient agentic workflows, the data, and the tools for your business.
01
Review the use case
We understand the task, the users, and where AI can actually help.
Read more02
Pick the right approach
We define what needs search, automation, or product integration.
Read more03
Build the first useful version
We implement the part that proves the value first.
Read more04
Improve from there
We add the checks and visibility needed to keep it useful.
Read moreThe first call is a practical review of your use case and the right next step.
Talk to Us