--- library_name: transformers pipeline_tag: image-text-to-text base_model: Qwen/Qwen3.5-4B license: other license_name: ocria-1-license license_link: LICENSE language: - en tags: - ocr - pdf - markdown - document-parsing - tables - charts - parsebench ---
Technical report · Blog post · Inference blog · LlamaParse · ParseBench · Ollama · GGUF
OCRia-1 is a 4B vision-language model for document parsing from [LlamaIndex](https://www.llamaindex.ai). It reads a page image and writes the page as Markdown, with tables in HTML, and it is built for the content that document parsers get wrong most often: merged cells and spanning headers, tables with thousands of cells, charts whose data has to be read off the plot, and formatting that carries meaning, such as strikethrough, underline, sub- and superscripts and checkboxes. - **Accuracy:** the highest-scoring open-weight model on both [ParseBench](https://parsebench.ai) leaderboards, with visual grounding included: 85.2 on ParseBench 2 (six dimensions, seventh of 61 systems) and 84.7 on ParseBench 1 (five dimensions, second of 158). It is also first on olmOCR-bench tables and formulas, PulseBench-Tab and fr-bench-pdf2md. See [Benchmarks](#benchmarks). - **Tables:** nested headers, merged cells as `colspan` / `rowspan`, irregular grids and long financial tables. - **Charts:** every chart becomes an HTML table of its data points, with each value under the right series and label (82.5 on ParseBench 1 charts, against 69.1 for the next-best open-weight model). - **Formatting and math:** bold, italic, ~~strikethrough~~, `underline`, `` highlights, `` / ``, `[ ]` / `[x]` checkboxes, `[___]` blank fields, and formulas in LaTeX, including handwritten ones. - **Page structure:** headers, footers, page numbers and watermarks in their own tags, multi-column text unrolled, diagrams as Mermaid. - **One call per page:** the text comes from the page image alone, with no layout detector, OCR engine or text layer. [Layout boxes](#layout-boxes-experimental) are added afterwards. > [!NOTE] > This repository holds the **unoptimized BF16 weights**. The OCRia-1 that serves > [LlamaParse](https://cloud.llamaindex.ai) is the same model, quantized and served with a speculative decoder and > custom kernels, which makes it about ten times faster. See [Speed](#speed) and > [The Inference Stack Behind OCRia](https://www.llamaindex.ai/blog/the-inference-stack-behind-ocria). OCRia-1 runs inside [LlamaParse](https://cloud.llamaindex.ai), which also handles multi-page documents.
|
|
| **Chart as data:** a line chart with three series over five years becomes a table of its 15 data points, matching the printed labels. |
|
|
| **Formatting:** a hearing notice with struck-through withdrawn cases, underlined case names and bold times; all three are kept. |
|
|
| **Handwritten formulas:** a handwritten note in Czech; the text is transcribed and each formula written as LaTeX. |
|
|
More examples, including cash-flow statements, bank statements, timetables and economic charts, are in the
[blog post](https://www.llamaindex.ai/blog/parse-ocria-1).
## Quickstart
To run OCRia-1 on your own machine with llama.cpp or Ollama (Linux, Windows, macOS), use the GGUF builds in
[llamaindex/OCRia-1-GGUF](https://huggingface.co/llamaindex/OCRia-1-GGUF); the Q8_0 build scores the same as these
weights on a ParseBench 2 sample. On a GPU server:
Serve with vLLM 0.30 or later. vLLM compiles kernels for this architecture at start-up and needs the CUDA toolkit
(`nvcc`); the `vllm/vllm-openai` Docker image has it.
```bash
vllm serve llamaindex/OCRia-1 --served-model-name ocria-1 --max-model-len 32768 \
--limit-mm-per-prompt '{"image": 1}'
```
Send each page as one image, with [`prompt.txt`](prompt.txt) as the system message, no user text, and **thinking off**.
The Qwen3.5 chat template turns thinking on by default, and with it on the model answers in the wrong format.
```python
import base64
from huggingface_hub import hf_hub_download
from openai import OpenAI
prompt = open(hf_hub_download("llamaindex/OCRia-1", "prompt.txt")).read()
page = base64.b64encode(open("page.png", "rb").read()).decode()
client = OpenAI(base_url="http://localhost:8000/v1", api_key="EMPTY")
resp = client.chat.completions.create(
model="ocria-1",
messages=[
{"role": "system", "content": prompt},
{"role": "user", "content": [{"type": "image_url", "image_url": {"url": f"data:image/png;base64,{page}"}}]},
],
temperature=0.0,
max_tokens=24576,
extra_body={"chat_template_kwargs": {"enable_thinking": False}},
)
print(resp.choices[0].message.content)
```
### Offline with vLLM
```python
from vllm import LLM, SamplingParams
llm = LLM("llamaindex/OCRia-1", max_model_len=32768, limit_mm_per_prompt={"image": 1})
messages = [
{"role": "system", "content": prompt},
{"role": "user", "content": [{"type": "image_url", "image_url": {"url": f"data:image/png;base64,{page}"}}]},
]
out = llm.chat(messages, SamplingParams(temperature=0.0, max_tokens=24576),
chat_template_kwargs={"enable_thinking": False})
print(out[0].outputs[0].text)
```
### With Hugging Face Transformers
```python
import torch
from PIL import Image
from transformers import AutoModelForImageTextToText, AutoProcessor
model = AutoModelForImageTextToText.from_pretrained("llamaindex/OCRia-1", dtype=torch.bfloat16, device_map="auto").eval()
processor = AutoProcessor.from_pretrained("llamaindex/OCRia-1")
messages = [
{"role": "system", "content": [{"type": "text", "text": prompt}]},
{"role": "user", "content": [{"type": "image", "image": Image.open("page.png").convert("RGB")}]},
]
inputs = processor.apply_chat_template(messages, add_generation_prompt=True, tokenize=True, return_dict=True,
return_tensors="pt", enable_thinking=False).to(model.device)
ids = model.generate(**inputs, max_new_tokens=24576, do_sample=False)
print(processor.decode(ids[0, inputs["input_ids"].shape[1]:], skip_special_tokens=True))
```
Needs `pip install transformers accelerate torchvision` (Transformers 5.3 or later). Use it to try the model; use vLLM
for throughput.
### Input
- **One page per request.** Render PDF pages at 300 DPI, for example with `pymupdf`: `page.get_pixmap(dpi=300)`.
- **Image size.** The benchmark numbers below use an image budget of about 4.1 megapixels, about 210 DPI for a letter
page. To match them, downscale larger renders:
```python
from PIL import Image
img = Image.open("page.png")
scale = min(1.0, (4_100_000 / (img.width * img.height)) ** 0.5)
img = img.resize((round(img.width * scale), round(img.height * scale)), Image.LANCZOS)
```
Larger images also work and cost more image tokens; the model was trained on pages of about 1,024 px.
- **No PDF text.** The model reads only the image.
### Output
Markdown inside a ```` ```markdown ```` fence. Strip the fence:
```python
import re
m = re.search(r"```markdown\n(.*?)(?:\n```|$)", text, re.S)
markdown = m.group(1) if m else text
```
| Content | How OCRia-1 writes it |
|---|---|
| Tables, and charts as data | HTML `