--- 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 ---

LlamaIndex

OCRia-1

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.

OCRia-1 against leading document-parsing VLMs

## Examples Pages from ParseBench, rendered at 150 DPI and transcribed with greedy decoding. The right-hand image renders what the model wrote, without editing. | | Page | OCRia-1 output | |---|:---:|:---:| | **Dense financial table:** a Texas insurance rate filing with a three-level header; the header spans become `colspan` and the section rows stay in place. | | | | **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 ``, with `colspan` / `rowspan` | | Diagrams and flowcharts | a ```` ```mermaid ```` block | | Formulas | `$...$` inline, `$$...$$` display | | Chemical formulas | plain text with `` / ``, e.g. `K3Fe(CN)6` | | Checkboxes and blank fields | `[ ]`, `[x]`, `[___]` | | Images | `![label: description]`, with `label` one of logo, icon, photo, illustration, screenshot, map, signature, seal, code, drawing, image | | Page furniture | ``, ``, `` (inside the header or footer), `` | Decode greedily (`temperature=0`) with `max_tokens` 24,576: dense pages can need more than 20,000 output tokens. ### The prompt The model was trained and evaluated with this system prompt, which is also in [`prompt.txt`](prompt.txt). Use it unchanged; other prompts change the output format.
Show the prompt ````text Transcribe this Page in markdown, be as accurate as possible in your transcription, do not describe/summarize. Formatting: - Use ** for bold text and * for italic text. - Use ~~ text ~~ for strikethrough text. Only use this for text that is visually stricken through. - Use and tags for highlighted text, aka text to wich a stabilo hilight was applied Only use to hilight sentence or words, not full block of text/tables. Use HTML color names for different colors of highlight, e.g. text. Do not use mark for first cell of a table, as it is often used for the header and should not be highlighted. - Use and tags for underlined text. - Use \* for bullet points and - for sub-bullets. - Use > for blockquotes. - Use ` for inline code. - Use ``` for code blocks. - Use [ ] for empty checkboxes. - Use [x] for checked checkboxes. - Use and for subscript text. - Use and for superscript text. - Use [___] for empty fields to fill, if the field is already filled, represent them as field content in markdown. - Use $...$ for inline equations and $$...$$ for display equations. Do NOT use \(...\) or \[...\] — the corpus uses dollar delimiters (43,604 inline occurrences against 35 in the parenthesis form). - Chemical formulas are NOT LaTeX: write them as plain text with and , e.g. K3Fe(CN)6 and 2H2O, never $K_3Fe(CN)_6$. Reserve $...$ for real mathematics. Tables: - Output tables in HTML when possible. - Table should not be use for page formatting (column or grid like layout), but only for tabular data. - Some table may be irregular, with merged cells, missing cells, or inconsistent formatting, or have an exotic structure (like a triangular table). Do your best to represent the table accurately with correct reading order. Charts, Graphs, and Figures: - IMPORTANT: Every chart or graph MUST be converted into an HTML
. This is non-negotiable. The table represent the chart data, not the chart layout. Focus on accurately capturing the underlying data and relationships in the table format. - FORBIDDEN outputs for charts: