Latest commit
History
2 Commits2 CommitsFolders and files
| Name | Name | Last commit message | Last commit date |
|---|---|---|---|
| code | code | ||
| construction | construction | ||
| error_analysis | error_analysis | ||
| settings | settings | ||
| src/docgallery | src/docgallery | ||
| .gitignore | .gitignore | ||
| LICENSE | LICENSE | ||
| README.md | README.md | ||
| requirements.txt | requirements.txt | ||
Repository files navigation
DocGallery: Diagnosing Multi-Hop Visual Reasoning in Rich DocumentsProject page | Paper (arXiv, coming soon) | Dataset (Hugging Face)
DocGallery is a benchmark for multi-hop visual reasoning in rich documents. It comprises 120 documents rendered from agent-written source code, spanning maps, handwritten records, engineering drawings and dense tables at a mean resolution of 7,655 × 6,106 pixels, and 932 questions that each require composing evidence from several regions of a page. Reference answers are computed by programs, and each question comes with its evidence regions and intermediate results.
This repository contains the code that prepares the page images, renders the prompts and scores the answers, together with the prompts and settings of every run reported in the paper. The data (images, questions and annotations) is on Hugging Face.
Contents
requirements.txt Pillow and jsonschema (Python 3.12)
src/docgallery/ library: data loading, binding of predictions to questions, scorer
code/
build_prompt.py renders the system message, user message and run settings of a question
prepare_images.py resizes a page to its recommended size and tiles it for an API
input_meter.py input-token threshold T of every question for every model (library)
input_acceptance.py acceptance of a request by its input tokens
evaluate.py scores a file of predictions
settings/
common_parameters.json default request parameters; models.json and qwen_budget.json replace them per model
models.json thinking, effort and temperature of the 18 models (Table 5), agent of their tool runs
qwen_budget.json separate reasoning and answer budgets of the two Qwen models
image_input.md recommended size, tiling, input-token threshold and acceptance
recommended_sizes.json recommended and original size of the 120 pages
visual_token_rules.json whole-canvas visual-token estimate of each model
input_thresholds.json threshold T and original-size value R of every question for every model
answer_protocol.zh.md answer protocol included in every prompt (verbatim)
answer_protocol.en.md English translation
no_tools/ main run without tools: configuration, system prompt, user-prompt template
tools_codex/ tool runs in Codex: configuration, CLI settings, instructions, user-prompt template
tools_claude_code/ tool runs of the two Claude models in Claude Code
budget_sweep/ runs with output caps of 38,400 and 51,200 tokens
question_lists/ the 93-question tool subset, the 93 questions of the budget sweep,
and the questions each model capped at 25,600 tokens
error_analysis/
error_types.csv error type of every incorrect response of 11 models (Appendix A.1)
construction/ how the documents and questions are built: method, prompts of the three stages,
worked example DG004 with its two solvers, and further visual examples
Files under settings/ ending in .zh.txt or .zh.md contain the Chinese text that was sent to the models; each has an English translation next to it (.en.txt, .en.md) that was not sent. In the user-prompt templates, {{ANSWER_PROTOCOL}}, {{QUESTION}}, {{OUTPUT_SCHEMA}} and {{FIELD_SPECS}} mark the parts filled in for each question. The title of the answer protocol contains "DocGallery120", the working name of the benchmark at the time of the runs.
Quick start
python -m pip install -r requirements.txt
huggingface-cli download inclusionAI/DocGallery --repo-type dataset --local-dir DocGallery
# prompt and run settings of one question for one model
python code/build_prompt.py --root DocGallery --question-id DG005_Q4 --mode no_tools --model "GPT-6.1 Sol" --output out/DG005_Q4.json
# images of one page for an API whose single-image limits are 1,536 px per edge and 2,359,296 px per image (example values)
python code/prepare_images.py --source DocGallery/images/DG005/DG005.png --doc-id DG005 --max-edge 1536 --max-area 2359296 --max-images 100 --output-dir out/DG005_images
# input-token threshold of one question for one model; with --actual-tokens, the input tokens and whether they reach
# the threshold are recorded; --enforce-input-threshold turns the acceptance test on (exit status 1 when the input
# tokens are below the threshold or missing)
python code/input_acceptance.py --model "Qwen3.8-27B" --question-id DG003_Q6 --mode tools
# scoring: the reference answers, written as predictions, score 932 of 932
python code/evaluate.py --root DocGallery --predictions DocGallery/reference_answers_as_predictions.jsonl --output-dir out/scored
# scoring only the questions of a list, here the 93-question tool subset (--skip-unknown-ids ignores the other predictions)
python code/evaluate.py --root DocGallery --predictions DocGallery/reference_answers_as_predictions.jsonl --question-ids-file settings/question_lists/tool_subset_93.json --skip-unknown-ids --output-dir out/scored_tool_subset
The scripts do not overwrite existing output; give a new --output or --output-dir for every run.
Evaluation settings
Runs without tools (Table 2). The 18 models answer all 932 questions, one request per question, with no other question in the context and one answer per question. The system message and the user-message template are in settings/no_tools/. The user message states the budget (finish reasoning within 24,576 tokens and reserve at least 1,024 tokens for the final answer) and the order of the images, followed by the answer protocol, the question, its output schema and its field conventions. Every response, reasoning included, is capped at 25,600 output tokens; a response that reaches the cap without a final answer is scored as incorrect. The APIs of Qwen3.8-Max and Qwen3.8-27B limit reasoning and the visible answer separately, to 24,576 and 1,024 tokens (settings/qwen_budget.json); no reasoning effort is sent to them in the runs without tools, while their Codex configuration sets reasoning effort xhigh. Thinking, reasoning effort and temperature of every model are in settings/models.json; where an API does not accept a temperature, its fixed value is listed. Page images are prepared and every request is checked against its input-token threshold as described in settings/image_input.md.
Runs with tools (Tables 2 and 11). A tool run takes several rounds of model calls per question and costs more time and API usage than a run without tools. All 18 models were therefore run with tools on one fixed subset of 93 questions, drawn uniformly without replacement from the 932 questions (settings/question_lists/tool_subset_93.json), and Table 2 reports this subset for every model so that all models are compared on the same questions. Claude Fable 5.2, GPT-6.1 Sol and Claude Opus 5.5 were also run with tools on all 932 questions (Table 11).
- Codex (all models except the two Claude models;
settings/tools_codex/). Codex CLI 0.148.0, one session per question, in an offline environment with Python 3.12, its standard library and Pillow. The tools run commands, interact with a running process and view images, so that the model can compute and crop, rescale or convert the page image. At most 24 successful tool calls are allowed; after that the tools are disabled and one request for the final answer remains. Reasoning, tool calls and the final answer of all rounds count toward the cap of 25,600 output tokens. The instruction filemodel_instructions.txtreplaces the built-in instructions of Codex and takes the place of the Chinese system message, and the user message adds a paragraph on the tool environment. - Claude Code (Claude Fable 5.2 and Claude Opus 5.5;
settings/tools_claude_code/). Claude Code 2.1.292 at reasoning effort high, a new session per question, in the same offline environment. The system message of the runs without tools is appended to the built-in instructions of Claude Code, and the user message is that of the runs without tools, with the prepared page images. The model has a shell (Bash) and file reading (Read); MCP servers and web search are disabled. As in the Codex runs, at most 24 successful tool calls are allowed, counted by the harness, and the output of all rounds counts toward the cap of 25,600 tokens.
The two environments thus differ in the agent, its instructions and the available tools; the limit on tool calls and the output cap are the same.
Larger budgets (Table 8 and Appendix A.2; settings/budget_sweep/). Each model keeps its settings of the main run; only the output cap and the reasoning budget stated in the user message change (37,376 or 50,176 reasoning tokens plus 1,024 for the answer). Table 8 reruns, at 51,200 tokens, every question on which Tencent Hy4, Seed-2.1-Turbo, LongCat-2.5, Step 5 Preview or MiMo-V2.6-Pro reached the 25,600-token cap (question_lists/capped_at_25600.json, 2,028 questions in total). The budget sweep of Appendix A.2 runs Seed-2.1-Turbo, Tencent Hy4 and LongCat-2.5 under caps of 25,600, 38,400 and 51,200 tokens on 93 questions drawn uniformly from the 316 questions all three capped (question_lists/budget_sweep_93.json).
Scoring
The scorer (src/docgallery/scorer.py, version dg-scorer-1.0) is a deterministic program; no model takes part in scoring. It scores the final answer only and never appends a separate reasoning channel to it.
- Leading and trailing ASCII spaces, tabs and line breaks are ignored. The rest must parse as strict JSON (no duplicate keys, NaN or Infinity), with an object at the top level that satisfies the JSON Schema of the question.
- Content. Booleans must match in type and value; numbers by exact decimal value, without tolerance (rounding prescribed by the question is part of the task); strings after Unicode NFC normalization, with case, spaces and character width significant; arrays element by element, in the order the question prescribes. An array that represents a set must list its members in the canonical order of the protocol, so the same members in another order are scored as incorrect.
- Format. The answer text must equal the canonical serialization of the protocol: keys sorted by Unicode code point, no whitespace between tokens, strings in NFC with no escapes other than those JSON requires, and numbers with the declared number of decimal places or in their shortest plain form.
- A question scores 1 only when content and format are both correct, otherwise 0. A correct value in a non-canonical form, such as an answer in a code fence, followed by a note, or with spaces after the separators, scores 0 and is recorded as a format error. An answer that cannot be parsed, for example one written with single quotes, scores 0 and is recorded as invalid output.
- Accuracy is the number of questions scoring 1 divided by the number of questions. A question without a prediction counts as incorrect. A request that failed for technical reasons is marked by the caller and excluded from the denominator; an incorrect, empty or truncated answer is never excluded.
Predictions
A prediction file has one JSON object per line with the fields id, answer (the raw final-answer string, not parsed), and prompt_sha256, image_sha256, question_revision and protocol_id as written by code/build_prompt.py. These four fields bind the answer to the version of the question the model received. Optional fields: technical_failure with failure_reason. reference_answers_as_predictions.jsonl in the dataset is an example.
Error types
error_analysis/error_types.csv gives the error type of each of the 4,982 incorrect responses that the 11 models with an available reasoning trace produce in the main run without tools (Appendix A.1, Figures 6 and 7). The columns are model (as in settings/models.json), question_id and error_type:
perceptual(717 responses): the response misreads the page.logical(3,129): the values are read correctly and combined incorrectly.hallucination(240): the response uses values that are not on the page.other(896): the remaining failures, among them responses that end without an answer.
The responses concern 838 of the 932 questions. For each of the 11 models, the number of lines equals its number of incorrect answers in Table 2.
Construction
construction/ describes how the pages and questions are built (Figures 2 and 3 of the paper) and runs a worked example: the facts and text of DG004, its two independent solvers, which reproduce the reference answers of the data, and the implementations of three further visual examples. See construction/README.md.
Citation
@article{li2026docgallery,
title = {DocGallery: Diagnosing Multi-Hop Visual Reasoning in Rich Documents},
author = {Li, Zhiheng and Li, Zongyi and Zhang, Hengrui and Su, Ziyu and Lan, Jun and Zhang, Beibei and Li, Yansi and Cao, Linhan and Yu, Zhiyin and Chen, Jiaxian and Zhang, Jianing and Lin, Haobo and Yu, Hao and Liu, Kang and Zhao, Linnan and Zhu, Huijia and Wang, Weiqiang and Ma, Zongyang and Zhang, Ziqi and Yuan, Chunfeng and Li, Bing and Hu, Weiming},
journal = {arXiv preprint},
year = {2026}
}
License
The code in this repository is released under the MIT License (LICENSE). The data on Hugging Face is released under CC BY-NC 4.0.
AI Trends