---
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
---
DocSEAM enriches visual features with context from neighboring pages for multi-page document understanding, preserving the visual token count.
Introducing DocSEAM
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.
The architecture below details the directional gates and anchored attention mask used to enrich the center page.
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
## 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},
}
```