Pix2Struct is an image-to-text encoder-decoder model from Google Research that understands visually situated language, such as documents, charts, infographics and user interface screenshots, directly from pixels without an OCR step. In Document AI, it is a leading example of OCR-free document understanding: the model receives an image and generates text, for example an answer to a question, a caption or a structured description of the page.
Its distinctive idea is the pretraining task. Pix2Struct learns by parsing masked web page screenshots into simplified HTML, which teaches it how visual layout, text and structure relate. Released in 2022 with Base and Large checkpoints, it became a common baseline for document question answering and the foundation for chart-focused successors such as MatCha and DePlot.
How Pix2Struct reads a page
Pix2Struct uses a Vision Transformer encoder and a Transformer text decoder. The encoder splits the input image into fixed-size patches, embeds each patch and processes them as a sequence; the decoder then generates output tokens one by one while attending to the encoded image. No external text recognition engine is involved, so the model must learn to read characters from pixels itself.
Two design choices separate it from a standard ViT. First, variable-resolution input keeps the original aspect ratio: the image is scaled so that the largest possible number of patches fits within a fixed budget, instead of being stretched to a square. Second, the model uses two-dimensional absolute position embeddings for rows and columns, so it knows where every patch sits on the page.
Text inputs, such as a question in visual question answering, are not fed through a separate channel. Instead, they are rendered as a header on top of the image, and the model reads them visually together with the page. This keeps a single pixel-only input interface for every task.
Screenshot parsing as pretraining
Pix2Struct is pretrained on about 80 million web page screenshots paired with a simplified version of their HTML. Parts of each screenshot are masked, and the model must output the HTML structure, including the hidden text, which combines the goals of OCR, layout understanding and language modeling in one objective.
This objective generalizes several earlier pretraining signals. Predicting visible text resembles OCR, filling in masked regions resembles masked language modeling, and producing alt text for images resembles image captioning. A short warm-up curriculum on reading rendered text precedes the main pretraining and helps the model learn to read before it learns structure.
| Component | What it does | Why it matters |
|---|---|---|
| Screenshot parsing objective | Predicts simplified HTML from masked screenshots | Teaches layout and text together |
| Variable-resolution patches | Preserves aspect ratio within a patch budget | Keeps small text and tall pages legible |
| 2D position embeddings | Encodes row and column of each patch | Supports arbitrary page shapes |
| Rendered text prompts | Draws questions onto the input image | One input format for all tasks |
| Reading warm-up | Short curriculum on rendered text | Stabilizes early pretraining |
Model sizes and fine-tuned tasks
Pix2Struct is released as pretrained checkpoints that require fine-tuning for each task. The Base model has roughly 282 million parameters and the Large model roughly 1.3 billion. Fine-tuned variants cover documents, illustrations, user interfaces and natural images, and they are available through common open-source model libraries.
| Domain | Example benchmarks | Typical output |
|---|---|---|
| Documents | DocVQA | Short answer extracted from a scanned page |
| Charts and infographics | ChartQA, InfographicVQA | Answer that may require reading values |
| Diagrams | AI2D | Choice among answer options |
| User interfaces | Screen2Words, Widget Captioning, RefExp | Screen summary or element description |
| Natural images with text | TextCaps, OCR-VQA | Caption or answer about visible text |
The patch budget is the most important inference setting. Fine-tuned document models commonly use 2,048 or 4,096 patches; a larger budget improves reading of small fonts on dense pages but increases memory and latency roughly in proportion to sequence length.
Pix2Struct compared with other document models
Pix2Struct belongs to the OCR-free family together with Donut and Nougat, and it contrasts with layout-aware language models such as LayoutLM that consume OCR tokens and their bounding boxes. The comparison below shows where each approach fits.
| Model | Input | Pretraining signal | Strength |
|---|---|---|---|
| Pix2Struct | Pixels only | Screenshot to simplified HTML | Broad visual language, charts and UIs |
| Donut | Pixels only | Reading text from synthetic documents | Receipts and form extraction |
| Nougat | Pixels only | Academic PDFs to markup | Scientific papers and formulas |
| LayoutLM family | OCR tokens, boxes and image | Masked layout-aware language modeling | Precise field extraction with good OCR |
| General vision-language models | Pixels plus text prompt | Large-scale image-text data | Flexible zero-shot instructions |
Compared with pipelines that rely on OCR, Pix2Struct avoids OCR error propagation and the cost of an extra engine, but it typically needs more compute per page. Larger general vision-language models now often outperform it in zero-shot settings, yet Pix2Struct remains attractive where a compact, fine-tunable model is required.
Limitations and practical cautions
Pix2Struct is not an instruction-following assistant: each checkpoint performs only the task it was fine-tuned on, and the raw pretrained model is of little direct use. Teams adopting it in Document AI pipelines should also plan for the following constraints.
- Small or dense text may become unreadable when a large page is squeezed into a limited patch budget.
- Multi-page documents must be split and processed page by page, with answers merged afterward.
- No bounding boxes are returned by default, so locating the source of an answer requires extra work.
- Hallucinated values can appear in generated answers, which makes confidence checks or human review necessary for financial data.
- Pretraining on web pages means handwriting and non-Latin scripts may need substantial additional fine-tuning data.
In everyday language
Most document software first turns a picture of a page into plain text and then tries to understand that text. Pix2Struct skips the first step. It looks at the page like a person does and answers questions about it directly.
It learned this skill by studying millions of web page pictures and guessing the code behind them. That taught it how titles, tables, buttons and charts usually look. The key idea is simple: the picture itself is the input.
Seen in the real world
A logistics company receives thousands of scanned delivery notes and supplier charts each week. Its data team fine-tunes a Pix2Struct Base model on about 3,000 labeled pages, teaching it to answer fixed questions such as the delivery date, the order number and the total weight. Each question is rendered on top of the page image, and the model returns a short answer for each field.
Because the pipeline no longer depends on a separate OCR engine, faded or skewed scans cause fewer cascading errors. The team runs the model with a 4,096-patch budget to keep small print legible and routes any answer that fails a format check, such as an invalid date, to a human reviewer. As a result, most notes are processed automatically, while reviewers concentrate on the minority of difficult pages.