File size: 16,782 Bytes
cf8c8d4
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
# OCR architectures: how they differ and how to choose

This guide explains the architectures in this toolkit: how each one reads an image, how it writes text,
how it is trained, and where it is strong or weak. Paper numbers are as reported by the authors;
benchmark versions differ between papers, so compare scores only within the same benchmark version.

**Contents**
1. [Building blocks every OCR model shares](#1-building-blocks)
2. [The four families](#2-the-four-families)
3. [Side-by-side comparison](#3-side-by-side-comparison)
4. [Architecture by architecture](#4-architecture-by-architecture)
5. [Training recipes](#5-training-recipes)
6. [Choosing an architecture](#6-choosing-an-architecture)

---

## 1. Building blocks

### 1.1 How a model sees the page
Modern OCR models cut the image into square **patches** (14 or 16 px), turn each patch into a vector, and
let a **vision encoder** (usually a Vision Transformer) mix information between patches. Most then **merge**
neighbouring patches (typically 2×2) into one **vision token**. One token therefore covers 28×28 px
(patch 14) or 32×32 px (patch 16).

The number of vision tokens is the central trade-off:
- **More tokens** keep small glyphs, accents, subscripts and dense tables legible, but cost memory and time
  (attention cost grows with sequence length).
- **Fewer tokens** (heavy compression) are fast and cheap, but fine detail can be lost before the decoder ever sees it.

Three resolution strategies appear in this toolkit:

| Strategy | Used by | Effect |
|---|---|---|
| Native / dynamic resolution, token budget | OvisOCR, Qwen-VL family, MinerU-Diffusion, PaddleOCR-VL, dots.ocr | Page keeps its aspect ratio; token count scales with pixels up to a cap |
| Fixed input size | Nougat (896×672), GOT-OCR (1024×1024 → 256 tokens) | Simple and predictable; long or wide pages are squashed or tiled |
| Learned compression | DeepSeek-OCR (16× compressor), GOT-OCR | Very few tokens per page; accuracy drops as compression rises |

### 1.2 How a model writes text

| Decoder type | How it works | Used by | Trade-off |
|---|---|---|---|
| **Autoregressive LLM** | Writes one token at a time, each conditioned on all previous tokens | Families A | Best accuracy and structure; slow for long pages; can loop |
| **Block diffusion** | Fills a block of masked tokens (e.g. 32) over a few parallel passes, block after block | Family B | Fewer decoding steps; less mature tooling |
| **CTC** | Predicts a character or blank per horizontal position of a line, then collapses repeats | Family C | Very fast and small; one line at a time, no structure |
| **Attention (seq2seq) head** | Small decoder over line features | PP-OCRv6 (NRTR head), Nougat | Handles longer dependencies than CTC; slower |

### 1.3 Tokenizers
An LLM decoder writes **tokens**, not characters. A larger vocabulary usually means fewer tokens per page,
which means faster decoding, less memory and fewer chances to drift on long pages. In this toolkit the
Qwen3.5 tokenizer (248,320 entries, OvisOCR) is the largest; most other Qwen-based models use 151,936.
When comparing models on your data, measure tokens per character on your own labels: the difference can be 15–25%.

### 1.4 Learning objectives

| Objective | What is optimised | Where |
|---|---|---|
| **Next-token cross-entropy (SFT)** | Probability of each correct target token given image + previous tokens; prompt and image tokens are masked out | Every family A model, `common.vlm_sft` |
| **CTC loss** | Sum over all alignments of predicted characters/blanks to the target string | PP-OCRv6 recognizer |
| **Masked-token loss** | Recover masked tokens inside a block | Block-diffusion models (family B) |
| **Segmentation losses** (Dice, focal) | Pixel maps of text regions | PP-OCRv6 detector |
| **Distillation** (forward / reverse KL) | Match a teacher's token distribution, not just the final text | OvisOCR3 (on-policy, from 4B teachers) |
| **RL (GRPO)** | Sample several outputs per page, score them with a reward, reinforce the above-average ones | FD-RL, OvisOCR3, olmOCR 2 |

Typical OCR rewards for RL: edit distance to the ground truth, **TEDS** (table tree-edit similarity),
**CDM** (formula similarity), format checks, and unit tests on synthetic pages (olmOCR 2). RL fixes what
cross-entropy is blind to: decoding loops, broken table markup, wrong reading order. It needs an SFT model to start from.

---

## 2. The four families

**A. Autoregressive end-to-end VLMs.** One model reads the whole page and writes the whole page as
Markdown (tables as HTML, formulas as LaTeX). Current state of the art. Members: OvisOCR2/3, FD-RL,
olmOCR 2, GOT-OCR 2.0, Nougat, PaddleOCR-VL, dots.ocr, DeepSeek-OCR.

**B. Block-diffusion VLMs.** Same input and output as A, but the decoder generates blocks of tokens in
parallel. Research stage. Members: MinerU-Diffusion, DODO.

**C. Detector + recognizer pipelines.** A detector finds text lines, a recognizer reads each line. No
language model. Tiny and fast; no document structure. Member: PP-OCRv6.

**D. Wrappers.** Not a model: combine several models' outputs. Member: Consensus Entropy.

---

## 3. Side-by-side comparison

| | Vision encoder | px per token | Decoder | Vocab | Output | Train code | Weights |
|---|---|---|---|---|---|---|---|
| **OvisOCR3** | ViT 12 layers, patch 16, merge 2 | 32×32 | Qwen3.5-0.8B (hybrid linear + full attention) | 248k | Markdown, HTML tables, LaTeX, boxes, JSON by prompt | No | Yes |
| **FD-RL** | Qwen3-VL ViT 24 layers, DeepStack | 32×32 | Qwen3-VL-4B | 152k | Markdown, HTML, LaTeX | SFT cmd only | Yes |
| **olmOCR 2** | Qwen2.5-VL ViT 32 layers, windowed attention | 28×28 | Qwen2.5-VL-7B | 152k | Markdown + YAML front matter | Yes | Yes |
| **GOT-OCR 2.0** | ViTDet-style, high compression | 1024² → 256 tokens | Qwen-0.5B | 152k | Text, Markdown, LaTeX, TikZ | Yes | Yes |
| **Nougat** | Swin Transformer | fixed 896×672 | mBART 10 layers (from scratch) | 50k | Markdown + LaTeX | Yes | Yes |
| **MinerU-Diffusion** | Qwen2-VL ViT 32 layers | 28×28, ≤2,048 tokens | SDAR-1.7B block diffusion (block 32) | 152k | Layout boxes, text, LaTeX, OTSL tables | No | Yes |
| **DODO** | Qwen2.5-VL ViT | 28×28 | Qwen2.5-VL-3B converted to block diffusion | 152k | Text | No | No |
| **PP-OCRv6** | LCNetV4 CNN + SVTR neck | line crops 32–64 px tall | CTC + NRTR heads | per dictionary | Polygons + strings | Yes | Yes |
| **PaddleOCR-VL** | NaViT-style dynamic resolution | native | ERNIE-4.5-0.3B (+ separate layout model) | — | Per-region text, tables, formulas | Not verified | Yes |
| **dots.ocr** | Encoder trained from scratch | native | ~1.5B LLM | — | Layout JSON + text | No | Yes |
| **DeepSeek-OCR** | DeepEncoder: local attn → 16× compressor → global attn | 64–400+ tokens by mode | DeepSeek-3B MoE (~0.57B active) | — | Markdown, text | No | Yes |

---

## 4. Architecture by architecture

### OvisOCR2 / OvisOCR3 — smallest strong end-to-end model
- **Design.** 0.85B parameters. Vision tower of 12 layers (patch 16, merge 2) feeding Qwen3.5-0.8B
  (24 layers, linear attention mixed with full attention, which keeps long outputs cheap). Pages from
  448² to 2,880² px, about 200 to 8,100 vision tokens.
- **Training (OvisOCR3 report).** (1) Continued pretraining on ~72M examples, all modules trained.
  (2) Mid-training on ~8.8M examples balanced across five domains. (3) On-policy distillation from five
  domain-specific 4B teachers (top-K reverse KL: the student writes, the teachers score each token).
  (4) GRPO with edit-distance, TEDS and CDM rewards.
- **Strengths.** Top of OmniDocBench v1.6 (~96.7) at under 1B parameters; largest vocabulary; one model
  for parsing, plain OCR, layout JSON and key-information extraction by prompt; LoRA fits an 8 GB GPU.
- **Limitations.** No training code or data released; our SFT is not the authors' recipe. Can loop on
  long repetitive lists. Linear-attention fast kernels are Linux-only.

### FD-RL — the clearest published training recipe
- **Design.** Qwen3-VL-4B: 24-layer vision encoder with DeepStack (vision features injected into several decoder layers).
- **Training.** SFT on 566k pages (240k open, 208k real PDF, 118k synthetic), 1 epoch, lr 1e-5, vision
  frozen, 8,192 tokens, via LLaMA-Factory. Then GRPO on only ~8k format-heavy samples: 16k candidates,
  keep the half where the model is most uncertain (highest entropy).
- **Strengths.** Simple, reproducible SFT; shows that a small, uncertainty-selected RL set gives large gains on structure.
- **Limitations.** RL code and data not released. 4B is too large for full fine-tuning on small GPUs. OmniDocBench ~90.4 (older version).

### olmOCR 2 — the most open recipe
- **Design.** Qwen2.5-VL-7B; pages rendered from PDF at 1,288 px longest side; output Markdown with YAML front matter.
- **Training.** SFT on the open olmOCR-mix data (labels produced by a stronger model), then RL with
  verifiable rewards: synthetic pages with known content and unit tests per page (reading order, table cells, presence of text).
- **Strengths.** Code, data and weights all open; unit-test rewards catch errors that edit distance misses.
- **Limitations.** 7B needs ≥40 GB for LoRA at 8k context; Linux + flash-attn; pseudo-labels in the SFT data; English-centric.

### Qwen-VL official trainer — the shared base
Most family A models are fine-tuned Qwen VL models (Qwen3.5 for OvisOCR, Qwen3-VL for FD-RL, Qwen2.5-VL
for olmOCR and DODO). Qwen's own `qwen-vl-finetune` trains any of these bases the same way. Use it to
build your own OCR model from a general base with full control.

### GOT-OCR 2.0 — compact unified OCR
- **Design.** 560M: high-compression encoder (1024×1024 → 256 tokens) + Qwen-0.5B decoder.
- **Training.** Three stages: pretrain the encoder with a tiny decoder on text images; connect the real
  decoder and train jointly; post-train for fine-grained regions, multi-page and dynamic resolution.
- **Strengths.** Open training code, small, handles text, formulas, sheet music, charts.
- **Limitations.** 256 tokens per crop limits dense pages and very small glyphs; behind current leaders.

### Nougat — the original page-to-Markdown model
- **Design.** Swin encoder + mBART decoder trained from scratch on scientific PDFs; no pretrained LLM.
- **Strengths.** Fully open trainer, small enough to train completely on one GPU.
- **Limitations.** Prone to repetition loops; fixed input squashes pages; tokenizer targets English and
  LaTeX (other scripts need a new tokenizer); domain limited to academic papers.

### MinerU-Diffusion — block-diffusion decoding
- **Design.** Qwen2-VL vision tower (≤2,048 tokens) + SDAR-1.7B decoder that generates 32-token blocks by iterative unmasking.
- **Training.** 550k image-caption alignment → 739k VQA → 6.9M layout/OCR samples for 9 epochs →
  630k hard samples (chosen by inconsistent model outputs) for 4 epochs.
- **Strengths.** Parallel decoding inside a block; the hard-sample stage is a reusable idea for any model.
- **Limitations.** No training code; OmniDocBench v1.5 88.9, below autoregressive leaders; immature tooling.

### DODO — converting an autoregressive VLM to diffusion
Qwen2.5-VL-3B converted to block diffusion with ~270k olmOCR-mix pages over 200k steps. Shows the
conversion works with modest data. No code or weights released.

### PP-OCRv6 — detector + recognizer
- **Design.** Detector: LCNetV4 + RepLKPAN + DB head, trained on 640² crops (500 epochs, Dice + focal).
  Recognizer: LCNetV4 + light SVTR neck + CTC and NRTR heads on 32–64 px-tall lines (100 epochs). 1–19M parameters.
- **Strengths.** Very fast, runs on CPU or edge devices, full training code; ideal for line-level data.
- **Limitations.** The released dictionary covers a fixed character set and `max_text_length` is 25, so
  new scripts or long lines require a new dictionary and retraining (handled by `make_config.py`).
  No tables, Markdown or page reading order.

### PaddleOCR-VL — layout model + compact VLM
A layout model first finds regions (text, tables, formulas, figures); a 0.9B VLM (dynamic-resolution
encoder + ERNIE-4.5-0.3B) reads each region. Robust on complex layouts and broadly multilingual, but two
models to tune, and reading-order errors in the layout step propagate.

### dots.ocr — layout and text in one pass
A ~3B model that outputs layout boxes, categories and text in one generation. Strong multilingual
parsing; no training code.

### DeepSeek-OCR — optical compression
DeepEncoder (local windowed attention → 16× convolutional compressor → global attention) feeding a
DeepSeek-3B mixture-of-experts decoder (~0.57B active). Shows a page can be represented with ~10× fewer
vision tokens than its text tokens at high precision. Efficient for large batches; compression hurts
small glyphs and marks; MoE is awkward to fine-tune on small GPUs; no training code.

### Consensus Entropy — agreement as a quality signal
Run several models on the same page and measure agreement. High agreement → likely correct; low →
hard page or wrong output. Use it to filter pseudo-labels, select hard samples, or route pages to a
stronger model. Costs several inferences per page; shared blind spots still pass.

---

## 5. Training recipes

Runnable versions of the data-efficient recipes below (self-play, GRPO with format rewards, hard-case
selection, merging) are described in [finetuning_recipes.md](finetuning_recipes.md).

The leading models share one shape. Each stage is optional; later stages need earlier ones.

| Stage | Data | Objective | Examples |
|---|---|---|---|
| 1. Alignment / pretraining | Millions of mixed image–text pairs | Cross-entropy | OvisOCR3 (~72M), MinerU (550k + 739k) |
| 2. Main SFT | Page images + exact Markdown | Cross-entropy on answer tokens | FD-RL (566k), MinerU (6.9M), olmOCR |
| 3. Hard samples / mid-training | Pages the model gets wrong or disagrees on | Cross-entropy | MinerU (630k), OvisOCR3 (8.8M balanced) |
| 4. Distillation | Teacher scores on the student's own outputs | Reverse KL | OvisOCR3 |
| 5. Reinforcement learning | A few thousand format-heavy pages | GRPO with edit distance / TEDS / CDM / unit tests | FD-RL (~8k), OvisOCR3, olmOCR 2 |

Practical points:
- **Start from the strongest small model and fine-tune**, rather than training from a general base, unless you have millions of pages.
- **LoRA vs full fine-tuning.** LoRA trains small adapter matrices and keeps the base frozen: far less
  memory and less forgetting. Full fine-tuning adapts more but needs much more memory and data.
- **Forgetting.** Mix 10–20% replay data the model already handles (other layouts, tables), and/or add a
  KL term to the frozen base model on replay pages. Training repeatedly on a model's own outputs without
  ground truth leads to collapse; always keep ground-truth labels in the loop.
- **Hard samples.** After a first SFT pass, run the model on its training set and up-weight the pages
  with the highest error or lowest agreement (see Consensus Entropy).
- **Evaluate on real pages kept out of training** (`eval` split), not only on rendered or synthetic ones.

---

## 6. Choosing an architecture

Answer four questions:

1. **Pages with structure, or single lines?** Pages → family A. Lines only, or speed matters most → PP-OCRv6.
2. **What hardware?** ≤8–12 GB: OvisOCR3 (LoRA), GOT-OCR, Nougat, PP-OCRv6. 24 GB: FD-RL LoRA,
   Qwen2.5-VL-3B. ≥40 GB or multi-GPU: olmOCR 2, full FD-RL SFT.
3. **Do you need the official recipe?** Open trainers: olmOCR, GOT-OCR, Nougat, PaddleOCR, Qwen-VL,
   LLaMA-Factory (FD-RL SFT). Otherwise `common.vlm_sft` trains any Qwen-family model.
4. **How dense is the text?** Small glyphs, marks or dense tables need many vision tokens: avoid heavily
   compressed encoders (DeepSeek-OCR, GOT-OCR) and give native-resolution models a generous pixel budget.

| Situation | Recommended start |
|---|---|
| General document parsing, small GPU | **OvisOCR3** + LoRA (`01_ovisocr`) |
| Reproducible end-to-end recipe, larger GPUs | **FD-RL** SFT via LLaMA-Factory, then a small GRPO stage |
| Fully open pipeline including RL | **olmOCR 2** |
| Line-level text, edge deployment, new character sets | **PP-OCRv6** with a custom dictionary |
| Complex multi-column layouts | **PaddleOCR-VL** or **dots.ocr** (evaluate first) |
| Cleaning or selecting training data | **Consensus Entropy** over two or three of the above |
| Research on decoding speed | **MinerU-Diffusion** (inference) |

A sound default plan: baseline OvisOCR3 on your eval split → LoRA SFT → hard-sample round → (optional)
small GRPO stage on a larger GPU, comparing every step with `common.score` on the same eval split.