A Simple yet Effective Layout Token in Large Language Models for Document Understanding

Zhaoqing Zhu, Chuwei Luo, Zirui Shao, Feiyu Gao, Hangdi Xing, Qi Zheng, Ji Zhang

Abstract

Document understanding requires integrating both textual content and spatial layout. Current "layout-as-token" methods often suffer from "position ID exhaustion," where coordinate tokens consume the limited context window of Large Language Models (LLMs). We present LayTokenLLM, which introduces a lightweight Layout Tokenizer that compresses spatial information into a single hidden embedding. By sharing position IDs between text and layout tokens, LayTokenLLM eliminates the "position ID tax," maintaining a 100% text utilization ratio (T-Ratio). Our approach achieves state-of-the-art performance on complex multi-page document benchmarks like MP-DocVQA while remaining computationally efficient.

Introduction

To achieve comprehensive document understanding, an AI must process both the semantic content of words and their spatial arrangement on a page. Existing approaches generally fall into two categories: "Layout-as-Modality," which treats layout as a separate visual input requiring significant architectural changes, and "Layout-as-Tokens," which represents coordinates as text strings interleaved with content.

While the latter is simpler to implement, it introduces a significant bottleneck: position ID exhaustion. LLMs operate with a fixed maximum position ID, defining their context window. When bounding boxes are represented as long coordinate strings (e.g., <box>123, 456...</box>), they consume a large portion of this window. This "position ID tax" is particularly detrimental for multi-page documents, where layout metadata can squeeze out actual text and introduce untrained position IDs during inference, leading to hallucinations.

Comparison of position ID allocation between traditional layout-as-token methods and LayTokenLLM.

Methodology

LayTokenLLM addresses these challenges through three primary innovations designed to integrate layout information efficiently.

The Layout Tokenizer

Instead of serializing coordinates into text, we employ a Layout Tokenizer. This module uses a small neural network—comprising a projector and an attention mechanism—to compress 4D bounding box coordinates into a single hidden embedding. This reduces the layout representation of a text segment to exactly one token.

Shared Positional Encoding

The key breakthrough is the use of Shared Positional Encoding. Rather than incrementing the position ID for each layout token, the layout token shares the position ID of the first token in its corresponding text segment. This ensures a 100% "T-Ratio" (text utilization), meaning the model's capacity to process text is never compromised by layout data. This scheme also preserves the relative distances between text segments as perceived by the model.

Next Interleaved Text and Layout Token Prediction (NTLP)

To ensure the model deeply understands the relationship between text and its location, we introduce the NTLP training objective. In addition to standard next-token prediction, the model is trained to predict the next layout token using a dedicated "Layout Head" with a Mean Squared Error (MSE) loss.

The architecture of LayTokenLLM, featuring the Layout Tokenizer and the interleaved training objective.

Experiments and Results

We evaluated LayTokenLLM across a variety of single-page and multi-page document benchmarks, including DocVQA, FUNSD, and MP-DocVQA.

Performance and Efficiency

LayTokenLLM-8B (based on Llama3) achieved a state-of-the-art ANLS score of 74.31 on MP-DocVQA, outperforming larger multimodal models like InternVL2-8B (68.00). The efficiency gains are equally notable; LayTokenLLM requires only 9.32 FLOPs/MACs, significantly lower than the ~28-32 required by traditional coordinate-string methods.

Long-Context Robustness

The model demonstrates superior robustness in multi-page scenarios. By maintaining a high T-Ratio, LayTokenLLM can handle sequences of 16k+ tokens without the performance degradation typically seen when position IDs are wasted on layout metadata. Qualitative analysis confirms that the model maintains clear reasoning across dozens of pages, avoiding the cross-page confusion common in standard LLMs.

Discussion and Limitations

While LayTokenLLM offers a highly efficient path for layout integration, some limitations remain. The current focus is on text-bearing segments, which may lead the model to overlook purely graphical elements like icons or complex charts without OCR text. Furthermore, layout prediction is currently performed at the segment level; future work could explore word-level granularity or the integration of richer visual features like fonts and textures.

Conclusion

LayTokenLLM provides a simple yet effective solution to the "position ID tax" in document understanding. By leveraging a dedicated layout tokenizer and a shared positional encoding scheme, it enables LLMs to process complex, multi-page documents with unprecedented efficiency and accuracy.

Summary updated

BibTeX
@inproceedings{zhu2025simple,
  author = {Zhaoqing Zhu and Chuwei Luo and Zirui Shao and Feiyu Gao and Hangdi Xing and Qi Zheng and Ji Zhang},
  title = {{A Simple yet Effective Layout Token in Large Language Models for Document Understanding}},
  booktitle = {IEEE/CVF Conference on Computer Vision and Pattern Recognition},
  year = {2025},
  doi = {10.1109/cvpr52734.2025.01349},
}
Figure