Dharma-OCR-LITE / README.md
GabrielPimenta99's picture
Update README.md
2d90c84 verified
|
Raw
History Blame
6.06 kB
metadata
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

Dharma-AI Logo

Introduction

DharmaOCR Lite is a 3B-parameter Specialized Small Language Model (SSLM) for structured OCR, developed by Dharma-AI. 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, 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.

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.

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
Claude Opus 4.6 0.833 β€” β€”
Qwen3-VL-8B 0.829 5.65 7.250
olmOCR-2-7B 0.823 1.41 4.306
Gemini 3.1 Pro 0.820 β€” β€”
Nanonets-OCR2-3B 0.791 2.62 1.911
GPT-5.4 0.750 β€” β€”
GPT-4o 0.635 β€” β€”
Google Document AI 0.640 β€” β€”
Amazon Textract 0.618 β€” β€”
Mistral OCR 3 0.574 β€” β€”

Score = (LevenshteinRatio + BLEU) / 2, evaluated on DharmaOCR-Benchmark (496 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).

Competitive cost

Model Score Relative Cost
DharmaOCR Lite (3B) 0.911 34%
olmOCR-2-7B 0.823 100% (reference)
Qwen3-VL-8B 0.829 168%
Nanonets-OCR2-3B 0.791 44%

DharmaOCR Lite is ~3Γ— cheaper than olmOCR-2-7B while scoring ~10% higher. On an H200 GPU with optimized inference settings, cost drops even further.

Quickstart

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

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

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

@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