SAIL: Sample-Centric In-Context Learning for Document Information Extraction

Jinyu Zhang, Zhiyuan You, Jize Wang, Xinyi Le

TL;DR

SAIL (SAmple-centric In-context Learning) is a training-free framework that significantly boosts the ability of Large Language Models (LLMs) to extract information from complex documents like receipts and forms. By dynamically selecting few-shot examples based on both layout structure and fine-grained entity similarity, SAIL creates tailored prompts that allow LLMs to rival the performance of models trained on massive labeled datasets.

What Problem Does This Paper Address?

Document Information Extraction (DIE) involves turning "Visually Rich Documents" (VRDs)—think scanned invoices, medical forms, or retail receipts—into structured data. This is notoriously difficult because the meaning of text is often tied to its physical location (e.g., a price is only meaningful if you know which line item it sits next to).

While traditional models like LayoutLM perform well, they require extensive task-specific training data. Recent "training-free" approaches leverage LLMs via In-Context Learning (ICL), but they face two major hurdles:

  1. Layout Blindness: LLMs often struggle to grasp the relationship between spatial coordinates and text.
  2. Generic Guidance: Most ICL methods use a fixed set of examples for every query. If the fixed examples don't look like the test document, the LLM's performance plummets.

Methods

The authors introduce SAIL, which moves away from "one-size-fits-all" prompting toward a sample-centric approach. The core of the method lies in how it selects and presents examples to the LLM:

  • Multi-Angle Similarity Search: For every new document, SAIL searches a small pool of labeled data to find the best matches based on three criteria:
  • Document-Level Text: Finding documents with similar overall topics.
  • Entity-Level Text: Finding specific text snippets (entities) that are semantically similar to those in the test sample.
  • Layout Similarity: This is a key innovation. SAIL renders document layouts as simplified black-and-white images (boxes only) and uses Mean Square Error (MSE) to find documents with nearly identical visual structures.
  • Unified Prompt Template: SAIL constructs a sophisticated 5-part prompt that includes:
  • A list of candidate labels.
  • Entity-level demonstrations.
  • Layout Analysis: SAIL asks the LLM to first analyze why labels are positioned where they are in the similar layout examples, forcing the model to "understand" the spatial logic before extracting data.
  • Document-level demonstrations.
  • The actual test question.

Datasets

The researchers evaluated SAIL on three standard DIE benchmarks:

  • FUNSD: A dataset of noisy, scanned forms with complex spatial relationships.
  • CORD: A receipt dataset with a very high number of hierarchical labels (30 categories), making it the most challenging test.
  • SROIE: A standard receipt dataset focused on four key entities (Company, Date, Address, Total).

Key Insights and Ideas

  • Layout is a Stronger Signal than Text: The authors found that for complex documents, seeing a document that looks the same is often more helpful for the LLM than seeing one that reads the same.
  • The "Aha" Moment of Layout Analysis: By adding a step where the LLM must explicitly describe the layout of the example documents, the model becomes much better at distinguishing between ambiguous entities (e.g., telling the difference between a "Unit Price" and a "Total Price" when they are both just numbers).
  • Adaptive beats Fixed: The performance gap between SAIL and previous methods was largest on the CORD dataset. This suggests that as the complexity of the extraction task increases (more labels, more varied layouts), the need for sample-specific examples becomes critical.

Key Results

SAIL consistently outperformed previous training-free SOTA methods (like ICL-D3IE) and even approached the performance of "full-training" models:

  • Superiority over GPT-4o alone: In one case study, standard GPT-4o misidentified three entities on a CORD receipt, while SAIL (using GPT-4o as the backbone) extracted everything perfectly.
  • Quantitative Gains: On the difficult CORD dataset, SAIL achieved an F1 score of 96.41, significantly higher than the ICL-D3IE baseline of 87.47.
  • Robustness: When tested with different LLMs (GPT-3.5, GPT-4, ChatGLM3), SAIL showed much better stability than baselines. For instance, when switching to the smaller ChatGLM3, the baseline's performance on SROIE crashed to 18.83 F1, while SAIL maintained a strong 85.03 F1.

Limitations and Future Work

The authors acknowledge two primary trade-offs:

  1. Computational Overhead: The similarity search process adds an extra step to the pipeline. When using GPT-4, this search accounted for roughly 13.3% of the total time cost.
  2. Token Usage: Because SAIL includes multiple detailed examples and a layout analysis step, the prompts are long. This increases the "token count," which translates to higher API costs and latency.

Future work will likely focus on optimizing the search algorithms and finding ways to compress these prompts without losing the vital layout context.

Summary updated

BibTeX
@inproceedings{zhang2025sail,
  author = {Jinyu Zhang and Zhiyuan You and Jize Wang and Xinyi Le},
  title = {{SAIL: Sample-Centric In-Context Learning for Document Information Extraction}},
  booktitle = {AAAI Conference on Artificial Intelligence},
  year = {2025},
  url = {https://openreview.net/forum?id=QJO2bZaxE0},
}

Loading related content...

Figure