llamaindex/OCRia-1 · Hugging Face

Reddit r/LocalLLaMA Models

Summary

LlamaIndex 发布 OCRia-1,一个用于文档解析的 4B 视觉语言模型,可将页面图像直接转为 Markdown/HTML,并在 ParseBench 等多项基准上取得开源权重模型最高分。

No content available
Original Article
View Cached Full Text

Cached at: 11/24/26, 10:36 AM

llamaindex/OCRia-1 · Hugging Face

Source: https://huggingface.co/llamaindex/OCRia-1 LlamaIndex

Technical report·Blog post·Inference blog·LlamaParse·ParseBench·Ollama

OCRia-1 is a 4B vision-language model for document parsing fromLlamaIndex. 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 bothParseBenchleaderboards, 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. SeeBenchmarks.
  • **Tables:**nested headers, merged cells ascolspan/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,<u\>underline</u\>,<mark\>highlights,<sub\>/<sup\>,\[ \]/\[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 boxesare added afterwards.

This repository holds theunoptimized BF16 weights. The OCRia-1 that servesLlamaParseis the same model, quantized and served with a speculative decoder and custom kernels, which makes it about ten times faster. SeeSpeedandThe Inference Stack Behind OCRia.

OCRia-1 runs insideLlamaParse, which also handles multi-page documents.

OCRia-1 against leading document-parsing VLMs

https://huggingface.co/llamaindex/OCRia-1#examplesExamples

Pages from ParseBench, rendered at 150 DPI and transcribed with greedy decoding. The right-hand image renders what the model wrote, without editing.

More examples, including cash-flow statements, bank statements, timetables and economic charts, are in theblog post.

https://huggingface.co/llamaindex/OCRia-1#quickstartQuickstart

Serve with vLLM 0.30 or later. vLLM compiles kernels for this architecture at start-up and needs the CUDA toolkit (nvcc); thevllm/vllm\-openaiDocker image has it.

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, withprompt\.txtas the system message, no user text, andthinking off. The Qwen3.5 chat template turns thinking on by default, and with it on the model answers in the wrong format.

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)

https://huggingface.co/llamaindex/OCRia-1#offline-with-vllmOffline with vLLM

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)

https://huggingface.co/llamaindex/OCRia-1#with-hugging-face-transformersWith Hugging Face Transformers

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

Needspip install transformers accelerate torchvision(Transformers 5.3 or later). Use it to try the model; use vLLM for throughput.

https://huggingface.co/llamaindex/OCRia-1#inputInput

  • **One page per request.**Render PDF pages at 300 DPI, for example withpymupdf: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: 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.

https://huggingface.co/llamaindex/OCRia-1#outputOutput

Markdown inside a\``markdown`fence. Strip the fence:

import re
m = re.search(r"```markdown\n(.*?)(?:\n```|$)", text, re.S)
markdown = m.group(1) if m else text

ContentHow OCRia-1 writes itTables, and charts as dataHTML<table\>, withcolspan/rowspanDiagrams and flowchartsa\``mermaidblockFormulas\.\.\.inline,\.\.\.displayChemical formulasplain text with<sub>/<sup>, e\.g\.K<sub>3</sub>Fe(CN)<sub>6</sub>Checkboxes and blank fields[ ],[x],[___]Images![label: description], withlabelone of logo, icon, photo, illustration, screenshot, map, signature, seal, code, drawing, imagePage furniture<page_header>,<page_footer>,<page_number>\(inside the header or footer\),<watermark> Decode greedily \(temperature=0\) withmax_tokens`24,576: dense pages can need more than 20,000 output tokens.

https://huggingface.co/llamaindex/OCRia-1#the-promptThe prompt

The model was trained and evaluated with this system prompt, which is also inprompt\.txt. Use it unchanged; other prompts change the output format.

Show the prompt``` 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: