File size: 5,186 Bytes
b312080
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
---
license: other
license_name: slab
license_link: LICENSE
library_name: transformers
pipeline_tag: image-text-to-text
base_model: Qwen/Qwen3.5-9B
tags:
  - document-question-answering
  - multi-page-documents
  - custom_code
---

<div align="center">
  <h2>DocSEAM: Bidirectional Cross-Page Encoding for Multi-Page Document Understanding</h2>
  <p>
    <a href="https://mossbee.github.io/">Hoang-Nhat Nguyen</a><sup>1</sup> &nbsp;·&nbsp;
    <a href="https://www.mmlab-ntu.com/person/ccloy/">Chen Change Loy</a><sup>1,2</sup>
  </p>
  <p>
    <sup>1</sup>S-Lab, Nanyang Technological University, Singapore &nbsp;·&nbsp; <sup>2</sup><a href="https://synvo.ai/">Synvo AI</a>
  </p>
  <p>
    <a href="https://mossbee.github.io/projects/DocSEAM/"><img src="https://img.shields.io/badge/%F0%9F%8C%90-Project_Page-267CB9" alt="Project page"></a>
    <a href="https://arxiv.org/abs/2611.34420"><img src="https://img.shields.io/badge/arXiv-Paper-B31B1B?logo=arxiv&amp;logoColor=white" alt="arXiv paper"></a>
    <a href="https://huggingface.co/mossbee/DocSEAM"><img src="https://img.shields.io/badge/%F0%9F%A4%97-Hugging_Face-FFD21E" alt="Hugging Face model"></a>
    <a href="https://github.com/mossbee/DocSEAM"><img src="https://img.shields.io/badge/GitHub-Code-181717?logo=github&amp;logoColor=white" alt="GitHub code"></a>
  </p>
</div>

<p align="center"><strong>DocSEAM enriches visual features with context from neighboring pages for multi-page document understanding, preserving the visual token count.</strong></p>

<p align="center">
  <img src="assets/overview.jpg" width="100%" alt="DocSEAM overview showing cross-page feature enrichment and benchmark results">
</p>

<details>
<summary><b>Introducing DocSEAM</b></summary>

<p>DocSEAM enriches each page's visual features with information from its immediate neighbors through center-anchored masked attention and directional salience gates. It preserves the visual token count passed to the language model.</p>
<p>The architecture below details the directional gates and anchored attention mask used to enrich the center page.</p>
<p align="center">
  <img src="assets/architecture.jpg" width="100%" alt="DocSEAM architecture with directional gates and anchored attention masking">
</p>

</details>

This repository contains the complete BF16 DocSEAM inference checkpoint in six safetensors shards. It incorporates the trained cross-page encoder, merged language-model adaptation, and trained vision merger.

## Run with Transformers

Install the dependencies in `requirements.txt`. Select a CUDA device with enough memory for the BF16 weights and the document's activations and cache. Peak memory increases with the number and resolution of pages.

```python
from pathlib import Path

import torch
from huggingface_hub import hf_hub_download
from qwen_vl_utils import process_vision_info
from transformers import AutoModelForImageTextToText, AutoProcessor

model_path = "mossbee/DocSEAM"
processor = AutoProcessor.from_pretrained(model_path)
model = AutoModelForImageTextToText.from_pretrained(
    model_path, dtype=torch.bfloat16, device_map={"": "cuda:0"}, trust_remote_code=True
)

page_paths = [
    hf_hub_download(model_path, f"examples/attention/1706.03762v7_page-{page:04d}.jpg")
    for page in (4, 5, 6)
]
question = "How many parallel attention heads are used in the model? Answer with only the number."
pages = [
    {"type": "image", "image": f"file://{Path(path).resolve()}",
     "min_pixels": 32768, "max_pixels": 524288}
    for path in page_paths
]
messages = [{"role": "user", "content": [*pages, {"type": "text", "text": question}]}]
prompt = processor.apply_chat_template(
    messages, tokenize=False, add_generation_prompt=True, enable_thinking=False
)
images, _ = process_vision_info(messages, image_patch_size=processor.image_processor.patch_size)
inputs = processor(text=[prompt], images=images, return_tensors="pt").to(model.device)
tokenizer = processor.tokenizer
with torch.inference_mode():
    tokens = model.generate(
        **inputs, max_new_tokens=128, do_sample=False,
        eos_token_id=tokenizer.eos_token_id, pad_token_id=tokenizer.pad_token_id,
    )
print(processor.decode(tokens[0, inputs.input_ids.shape[1]:], skip_special_tokens=True))
```

The example downloads pages 4–6 of *Attention Is All You Need* from this repository. For a local model checkout, use its path as `model_path` and pass the three local image paths directly in `page_paths`.

`trust_remote_code=True` loads the DocSEAM architecture from `modeling_docseam.py` and `docseam.py` in this model repository.

## Cross-page attention

<p align="center">
  <img src="assets/attention.jpg" width="100%" alt="Cross-page attention on neighboring document pages">
</p>

## License

DocSEAM is released under the [S-Lab License 1.0](LICENSE) for non-commercial use. The Qwen3.5-9B backbone's Apache-2.0 license is retained in [LICENSE-QWEN](LICENSE-QWEN).

## Citation

```bibtex
@article{nguyen2026docseam,
  title={DocSEAM: Bidirectional Cross-Page Encoding for Multi-Page Document Understanding},
  author={Nguyen, Hoang-Nhat and Loy, Chen Change},
  journal={arXiv preprint arXiv:2611.34420},
  year={2026},
}
```