DharmaOCR: Specialized Small Language Models for Structured OCR that outperform Open-Source and Commercial Baselines
Organizations: Dharma-AI
Abstract
This manuscript introduces DharmaOCR Full and Lite, a pair of specialized small language models (SSLMs) for structured OCR that jointly optimize transcription quality, generation stability, and inference cost. It also presents DharmaOCR-Benchmark, a benchmark that covers printed, handwritten, and legal/administrative documents, and proposes a unified evaluation protocol that measures fidelity and structure while explicitly tracking text degeneration as a first-class benchmark metric (alongside unit cost). Beyond reporting degeneration rates, the manuscript empirically shows degeneration is not merely a quality failure, since it materially worsens production performance by increasing response time, reducing throughput, and inflating computational cost due to abnormally long generations. To the best of the author's knowledge, as a methodological contribution, this is the first application of Direct Preference Optimization (DPO) for OCR, explicitly using degenerate generations as rejected examples to penalize looping behavior. Combined with Supervised Fine-Tuning (SFT) for enforcing a strict JSON schema (header, margin, footer, and text), DPO consistently reduces degeneration rate across model families (up to 87.6% relative) while preserving or improving extraction quality. The resulting models, namely, DharmaOCR Full (7B) and DharmaOCR Lite (3B), set a new state-of-the-art on DharmaOCR-Benchmark, outperforming each open-source and commercial baseline model evaluated regarding extraction quality, reaching 0.925 and 0.911 scores with 0.40% and 0.20% degeneration rates. AWQ quantization reduced up to 22% per-page cost with negligible quality loss, enabling a strong quality-cost trade-off in comparison to proprietary OCR APIs and open-source alternatives.
Figures & tables
| Model / Technique | Score | Degeneration rate (%) | Time per page (s) | Relative cost (%) |
| Fine-tuned models | ||||
| olmOCR-2-7B (SFT) | 0.928 | 1.01 | 2.717 | 63.09% |
| olmOCR-2-7B (SFT + DPO) | 0.927 | 0.40 | 2.730 | 63.40% |
| olmOCR-2-7B (LoRA SFT) | 0.926 | 0.60 | 2.997 | 69.60% |
| olmOCR-2-7B (SFT + DPO + Quant) | 0.925 | 0.40 | 2.132 | 49.50% |
| olmOCR-2-7B (Vanilla) | 0.823 | 1.41 | 4.306 | 100.00% |
| Model rate (%) | SFT degeneration rate (%) | SFT+DPO degeneration rate (%) | Relative reduction |
|---|---|---|---|
| olmOCR-2-7B | 1.01 | 0.60 | 40.6% |
| Nanonets-OCR2-3B | 1.61 | 0.20 | 87.6% |
| Qwen2.5-VL-7B | 1.61 | 1.01 | 37.3% |
| Qwen2.5-VL-3B | 3.23 | 1.41 | 56.4% |
| gemma-3-4b-it | 16.13 | 4.03 | 75.0% |
Appendix figures & tables8 assets
Supplementary material from the paper’s appendix.
Appendix
| Parameter | Value |
|---|---|
| gpu_memory_utilization | 0.90 |
| tensor_parallel_size | 1 |
| max_num_batched_tokens | 32000 |
| max_model_len | 65536 |
| temperature | 0 |
| max_tokens | 8192 |
| Dataset | Observed time | No-degeneration time | time | Relative reduction |
|---|---|---|---|---|
| 1 | 21.7 min | 19.5 min | 2.2 min | 10.14 % |
| 2 | 11.2 min | 10.8 min | 0.4 min | 3.57 % |
| 3 | 7.3 min | 4.2 min | 3.1 min | 42.47 % |
| Criterion | Prompt |
|---|---|
| Completeness | Is the extraction complete?, i.e., did the model detect and extract all text present in the image without omitting characters, words, lines, or text blocks? Does the extraction cover all textual elements visible in the original image? |
| Precision | Is the extraction precise?, i.e., does the extracted text exactly match the original text with no typos, character substitutions, letter inversions, or hallucinated words that are not present in the image? |
| Formatting | Does the extraction preserve the appropriate formatting?, i.e., did the model maintain the original text’s visual structure, respecting line breaks, paragraphs, spacing, alignment, and the overall layout of the content as it appears in the image? |
| Structure Adherence | Does the extraction adhere to the expected json structure? The expected structure is {"text": "extracted_text", "header": "header_contet", "margin": "margin_contet", "footer": "footer_contet"} . If json format is respected, does the extraction correctly assign values to the corresponding fields, assigning null values to fields absent from the image? |
| Condition | Requirement | Motivation | Action |
|---|---|---|---|
| and | — | Unreliable signal | Discard |
| and ) | Avoid small margins in mid-quality regime | Include | |
| Informative pair with a guaranteed minimum margin | Include |
| Model | Technique | Benchmark Score | Degeneration Rate (%) | Time per page (s) |
|---|---|---|---|---|
| olmOCR-2-7B (SFT + DPO) | AWQ W8A8 | 0.926 | 0.60 | 2.122 |
| olmOCR-2-7B (SFT + DPO) | AWQ FP8 | 0.925 | 1.21 | 2.187 |
| olmOCR-2-7B (SFT + DPO) | AWQ W4A16 | 0.903 | 1.61 | 2.004 |
| Nanonets-OCR2-3B (SFT + DPO) | AWQ FP8 | 0.912 | 0.20 | 1.463 |
| Nanonets-OCR2-3B (SFT + DPO) | AWQ W8A8 | 0.903 | 1.81 | 1.500 |
| Nanonets-OCR2-3B (SFT + DPO) | AWQ W4A16 | 0.831 | 11.09 | 1.821 |
| ID | Criterion | Guiding Question |
|---|---|---|
| C1 | Comprehensibility | Which text enables information to be extracted more easily? |
| C2 | Precision | Which text exhibits the lowest rate of extraction errors? |
| C3 | Completeness | Which model extracted the largest amount of relevant information? |
| C4 | Fidelity | Which text is more faithful, avoiding hallucinated words that are not present? |
| C5 | General Adequacy | Which model is more robust for deployment in production systems? |
| C6 | Formatting | Which model better preserves the structure? |