---
license: apache-2.0
language:
- pt
- en
library_name: transformers
pipeline_tag: image-text-to-text
tags:
- ocr
- document-understanding
- structured-extraction
- specialized-small-language-model
- brazilian-portuguese
datasets:
- dharma-ai/DharmaOCR-Benchmark
---
# DharmaOCR Lite
## Introduction
**DharmaOCR Lite** is a 3B-parameter Specialized Small Language Model (SSLM) for structured OCR, developed by [Dharma-AI](https://dharma-ai.com). It extracts text from document images into a structured JSON format with explicit `header`, `text`, `footer`, and `margin` fields.
DharmaOCR Lite achieves **state-of-the-art performance** on [DharmaOCR-Benchmark](https://huggingface.co/datasets/dharma-ai/DharmaOCR-Benchmark), outperforming all evaluated open-source and commercial baselines — including GPT-4o, GPT-5.4, Claude Opus 4.6, Gemini 3.1 Pro, Google Document AI, Amazon Textract, and olmOCR-2-7B — while being significantly cheaper and faster to run.
For the full methodology, training details, and ablation studies, see our paper: **[DharmaOCR: Specialized Small Language Models for Structured OCR that Outperform Open-Source and Commercial Baselines](link_to_paper)**.
## Why DharmaOCR Lite?
### Best quality among all models evaluated
DharmaOCR Lite (3B) **outperforms models with more than twice as many parameters**, including olmOCR-2-7B, and surpasses every commercial API tested.
### 🏆 DharmaOCR-Benchmark Results
| Model |
Score ↑ |
Degeneration Rate (%) ↓ |
Time/Page (s) ↓ |
| 🥇 DharmaOCR Full (7B, ours) |
0.925 |
0.40 |
2.132 |
| 🥈 DharmaOCR Lite (3B, ours) |
0.911 |
0.20 ✨ |
1.464 |
Commercial APIs |
| Claude Opus 4.6 |
0.833 |
— |
— |
| Gemini 3.1 Pro |
0.820 |
— |
— |
| GPT-5.4 |
0.750 |
— |
— |
| Google Vision |
0.686 |
— |
— |
| Google Document AI |
0.640 |
— |
— |
| GPT-4o |
0.635 |
— |
— |
| Amazon Textract |
0.618 |
— |
— |
| Mistral OCR 3 |
0.574 |
— |
— |
Open-Source Models |
| Qwen2.5-VL-7B-Instruct |
0.839 |
2.42 |
3.101 |
| Qwen3-VL-8B |
0.829 |
5.65 |
7.250 |
| olmOCR-2-7B |
0.823 |
1.41 |
4.306 |
| Nanonets-OCR2-3B |
0.791 |
2.62 |
1.911 |
| Dots OCR |
0.738 |
6.85 |
2.526 |
| GLM-OCR |
0.710 |
11.69 |
1.480 |
| Qwen3-VL-2B-Instruct |
0.623 |
11.69 |
3.566 |
| Qwen2.5-VL-3B-Instruct |
0.549 |
0.60 |
1.500 |
| gemma-3-4b-it |
0.214 |
33.96 |
2.182 |
| DeepSeek-OCR |
0.196 |
21.98 |
1.213 |
Evaluated on [DharmaOCR-Benchmark](https://huggingface.co/datasets/dharma-ai/DharmaOCR-Benchmark) (instances covering printed, handwritten, and legal/administrative documents in Brazilian Portuguese). Time/page measured on NVIDIA L40S.
### Lowest text degeneration rate
Text degeneration — where models get stuck in repetitive loops — is a critical but underreported problem in OCR. It's not just a quality issue: **a single degenerate request can nearly double GPU time and cost** for a batch of concurrent requests, reducing throughput for the entire system.
DharmaOCR Lite achieves a **0.20% degeneration rate** ✨ — the lowest across all 22+ models evaluated (open-source and commercial).
| Model |
Degeneration Rate (%) |
vs DharmaOCR Lite |
| ✨ DharmaOCR Lite (3B, ours) |
0.20 |
— |
| DharmaOCR Full (7B, ours) |
0.40 |
2× |
| Qwen2.5-VL-3B-Instruct |
0.60 |
3× |
| olmOCR-2-7B |
1.41 |
7× |
| Qwen2.5-VL-7B-Instruct |
2.42 |
12× |
| Nanonets-OCR2-3B |
2.62 |
13× |
| Qwen3-VL-8B |
5.65 |
28× |
| Dots OCR |
6.85 |
34× |
| GLM-OCR |
11.69 |
58× |
| Qwen3-VL-2B-Instruct |
11.69 |
58× |
| DeepSeek-OCR |
21.98 |
110× |
| gemma-3-4b-it |
33.96 |
170× |
Degeneration rate measured on DharmaOCR-Benchmark. "vs DharmaOCR Lite" = how many times more degeneration than DharmaOCR Lite (0.20%).
### Competitive cost
| Model |
Score ↑ |
Relative Cost ↓ |
| 🥇 DharmaOCR Lite (3B, ours) |
0.911 |
34% |
| Nanonets-OCR2-3B |
0.791 |
44% |
| Dots OCR |
0.738 |
59% |
| GLM-OCR |
0.710 |
34% |
| Qwen3-VL-2B-Instruct |
0.623 |
83% |
| Qwen2.5-VL-3B-Instruct |
0.549 |
35% |
| olmOCR-2-7B |
0.823 |
100% (reference) |
| Qwen2.5-VL-7B-Instruct |
0.839 |
72% |
| Qwen3-VL-8B |
0.829 |
168% |
| DeepSeek-OCR |
0.196 |
28% |
| gemma-3-4b-it |
0.214 |
51% |
Relative cost computed against olmOCR-2-7B vanilla (100%) on NVIDIA L40S with identical vLLM configuration. Lower is better.
DharmaOCR Lite is **~3× cheaper** than olmOCR-2-7B while scoring ~10% higher. Among models with comparable cost (DeepSeek-OCR, GLM-OCR, Qwen2.5-VL-3B), DharmaOCR Lite scores **2× to 4.6× higher**. On an H200 GPU with optimized inference settings, cost drops even further.
## Quickstart
```python
from transformers import Qwen2_5_VLForConditionalGeneration, AutoProcessor
from qwen_vl_utils import process_vision_info
model_name = "dharma-ai/DharmaOCR-Lite"
model = Qwen2_5_VLForConditionalGeneration.from_pretrained(
model_name,
torch_dtype="auto",
device_map="auto",
)
processor = AutoProcessor.from_pretrained(model_name)
image_path = "document.png"
messages = [
{
"role": "user",
"content": [
{"type": "image", "image": image_path},
{"type": "text", "text": "Extract the text from this image."},
],
}
]
text = processor.apply_chat_template(messages, tokenize=False, add_generation_prompt=True)
image_inputs, video_inputs = process_vision_info(messages)
inputs = processor(
text=[text],
images=image_inputs,
videos=video_inputs,
padding=True,
return_tensors="pt",
).to(model.device)
generated_ids = model.generate(**inputs, max_new_tokens=8192)
generated_ids_trimmed = [
out_ids[len(in_ids):] for in_ids, out_ids in zip(inputs.input_ids, generated_ids)
]
output_text = processor.batch_decode(
generated_ids_trimmed, skip_special_tokens=True, clean_up_tokenization_spaces=False
)[0]
print(output_text)
```
### Output Format
```json
{
"header": "DOCUMENT TITLE | Page 1",
"margin": null,
"footer": "Journal Name, Vol. X, pp. 1-10, 2025.",
"text": "Full main body text extracted from the document..."
}
```
Fields not present in the original document are returned as `null`. This lets you decide whether to use auxiliary fields (header, footer, margins) depending on your application.
## Serving with vLLM
```bash
vllm serve dharma-ai/DharmaOCR-Lite \
--gpu-memory-utilization 0.90 \
--max-model-len 65536 \
--max-num-batched-tokens 32000
```
## Limitations
- **Language focus:** Primarily optimized for Brazilian Portuguese documents. Performance on other languages may vary.
- **Field repetition:** The model may occasionally repeat header/footer content within the `text` field. A post-processing step checking exact matches between fields resolves >80% of occurrences.
- **Domain scope:** Best results on printed, handwritten, and legal/administrative documents.
## Citation
```bibtex
@article{dharmaocr2026,
title={DharmaOCR: Specialized Small Language Models for Structured OCR that Outperform Open-Source and Commercial Baselines},
author={Cardoso, Gabriel Pimenta de Freitas and Chacon, Caio Lucas da Silva and Oliveira, Jonas Felipe da Fonseca and Araujo, Paulo Henrique de Medeiros},
year={2026},
journal={arXiv preprint}
}
```
## Contact
- Gabriel Pimenta — gabriel.pimenta@dharma-ai.com
- Caio Chacon — caio.chacon@dharma-ai.com
- Jonas Oliveira — jonas.oliveira@dharma-ai.com
- Paulo Araujo — paulo.araujo@dharma-ai.com