Image-Text-to-Text
Transformers
Safetensors
qwen3_5
decision-model
system-one
flide
ocr
pdf
document-understanding
hf_jobs
conversational
ocr-decision-0.8b / README.md
davanstrien's picture
davanstrien HF Staff
Split README figures into full-width native-scale hero_examples.png + case_study_finepdfs.png and link FinePDFs
2d11e11 verified
|
Raw History Blame Contribute Delete
21.2 kB
---
license: apache-2.0
library_name: transformers
base_model: OmniJev/OneJev1.6-0.8B
base_model_relation: finetune
pipeline_tag: image-text-to-text
tags:
- decision-model
- system-one
- flide
- ocr
- pdf
- document-understanding
- hf_jobs
- qwen3_5
language:
- en
- de
- fr
- es
- it
- nl
- pt
- la
- uk
- ru
- zh
- ja
- ar
datasets:
- allenai/olmOCR-mix-1025
- docling-project/DocLayNet-v1.2
- JustQuiteMadMax/ukrainian-handwritten-text-full-pages
---
# ocr-decision-0.8b
**`ocr-decision-0.8b`** is a 0.8B Apache-2.0 multimodal [decision model](https://huggingface.co/blog/decision) for pre-OCR page triage, PDF text-layer auditing, and post-OCR verification.
Fine-tuned from [OmniJev/OneJev1.6-0.8B](https://huggingface.co/OmniJev/OneJev1.6-0.8B) (`Qwen3.5-0.8B`), it scores yes/no and multiple-choice questions over a page image (and optional transcription) in one forward pass without generating text (~20–27 ms/page on an RTX PRO 6000; no custom head — loads directly in [flide](https://github.com/OmniJev/Flide) or `transformers`).
![Pre-OCR triage and broken PDF text-layer detection examples with ocr-decision-0.8b](./hero_examples.png)
## Why & what it is for
Running a generative VLM OCR model on every page of a large PDF or archival collection is expensive, while cheap character-count heuristics miss broken embedded text layers (garbled encodings / mojibake) and VLM OCR outputs still fail silently with repetition loops, hallucinations, or dropped blocks. A small decision model lets you run multiple routing and verification checks on a page in ~22–27 ms — or label a few thousand pages in 90 seconds to distil a pure-CPU router:
- **Pre-OCR triage & routing:** detect blank pages, rotation, tables, figures, equations, handwriting, blackletter/Fraktur, script, and document type before choosing an OCR or extraction pipeline.
- **PDF text-layer auditing:** check whether a PDF's free embedded text layer (e.g. from `pypdfium2`) is usable, missing, garbled (mojibake), or partial before paying for GPU OCR.
- **Post-OCR verification:** check an existing transcription against the page image for hallucinated or wrong-page text (`extra`), missing text blocks (`omission`), and repetition loops (`loop`).
- **Text-only loop detection:** flag degenerate repetitive OCR outputs without loading an image.
## Headline results
All figures below are strictly out-of-distribution (zero source or volume overlap with training), evaluated through `flide serve` at `max_side=1024`:
| Task (out-of-distribution) | Base `OneJev1.6-0.8B` | `ocr-decision-0.8b` |
|---|---:|---:|
| Blank vs. printed text (19th-c. BHL books, AUROC) | 0.967 | **1.000** |
| Hallucinated / wrong-page OCR (`extra`, BHL / 2026 PDFs / OmniDocBench, AUROC) | 0.29–0.56 | **0.985–1.000** |
| Stuck repetition loops (`loop`, BHL / OmniDocBench / newspapers, AUROC) | 0.92–0.98 | **0.998–1.000** |
| Missing PDF text layer vs. clean (Common Crawl 2026 PDFs, AUROC) | 0.679 | **0.998** |
| Partial PDF text layer vs. clean (Common Crawl 2026 PDFs, AUROC) | 0.472 | **0.658** |
| Modern pre-OCR layout triage (`OmniDocBench` EN+ZH: tables, figures, equations, script, AUROC) | 0.75–0.99 | **0.85–0.996** |
| Throughput (`flide serve`, BF16, 1024px, RTX PRO 6000 / L4) | same (0.8B) | **~73–107 / ~13–21 pages/s** |
> [!NOTE]
> **Omission is the weakest of the four OCR checks.** It reliably catches missing text layers (`0.998` AUROC) and large dropped blocks (`0.82–0.84` AUROC across BHL books and EN/ZH OmniDocBench), but struggles when only 1–2 lines are missing from a dense page (`0.658` AUROC on partial PDF layers). Default `0.50` thresholding is also miscalibrated on dense prose (`0.585` acc on BHL vs. `0.708` tuned), so set your threshold on a small validation sample of your own pages.
## Quickstart
### Recommended: `flide serve` (`/v1/systemone`)
[flide](https://github.com/OmniJev/Flide) automatically loads `decision_config.json` and `calibration.json` (`T = 2.5` for yes/no questions, `T = 1.0` for multiple-choice) and encodes the page image once across all questions in a request.
```bash
pip install flide torchvision
flide serve --model davanstrien/ocr-decision-0.8b --port 8000
```
```python
import base64, io, httpx
from PIL import Image
# Resize to max_side=1024 (matches training & eval resolution)
img = Image.open("page.jpg").convert("RGB")
img.thumbnail((1024, 1024))
buf = io.BytesIO()
img.save(buf, format="JPEG", quality=90)
data_url = "data:image/jpeg;base64," + base64.b64encode(buf.getvalue()).decode()
# Verify an existing OCR/PDF transcription and triage page layout in one pass
resp = httpx.post(
"http://127.0.0.1:8000/v1/systemone",
json={
"state": {
"page": "<image:1>",
"ocr_transcription": "Existing OCR or PDF text layer goes here...",
},
"media": [{"type": "image", "data": data_url}],
"questions": {
"has_text": {
"type": "noul", # yes/no
"instructions": "Is there printed text on this page?",
},
"has_equation": {
"type": "noul",
"instructions": "The page contains mathematical or chemical equations.",
},
"has_extra": {
"type": "noul",
"instructions": "Does this transcription contain text that is not printed on the page?",
},
"has_omission": {
"type": "noul",
"instructions": "Is a block of printed text on this page missing from the transcription?",
},
"has_loop": {
"type": "noul",
"instructions": "Is this transcription stuck in a loop, repeating a pattern again and again instead of reading new text?",
},
},
},
timeout=60.0,
)
print(resp.json()["answers"])
# {
# "has_text": {"noul": 0.837},
# "has_equation": {"noul": 0.772},
# "has_extra": {"noul": 0.181},
# "has_omission": {"noul": 0.237},
# "has_loop": {"noul": 0.162}
# }
```
**Practical tips:**
- **Resolution & text length:** resize images to `max_side=1024` before sending; training and throughput benchmarks used up to ~4,000–12,000 characters of `ocr_transcription` (averaging ~2,100 chars on modern PDFs).
- **Calibrated score range:** because `calibration.json` applies `T = 2.5` (and training used `0.05` label smoothing), strong yes/no predictions sit around `~0.80–0.85` / `~0.15–0.20` rather than saturating at `0.999` / `0.001`.
- **Omission phrasing:** natural and flipped-polarity phrasings all work (`0.80–0.84` AUROC), but avoid phrasing omission questions around *"readable printed content"* (which drops AUROC to `0.62–0.67`).
### One-command local PDF audit (`uv run`)
Audit any local PDF's embedded text layer and layout directly from the command line (uses `transformers` out of the box, or pass `--flide-url http://127.0.0.1:8000` for higher throughput):
```bash
uv run https://huggingface.co/davanstrien/ocr-decision-0.8b/resolve/main/audit_pdf.py sample.pdf --max-pages 10
```
<details>
<summary>Direct <code>transformers</code> usage (no <code>flide</code> required)</summary>
Outside `flide`, divide the `A`/`B` yes/no logits by `T = 2.5` before softmax (matching `calibration.json`) so probabilities remain well-spread.
```python
import torch
from PIL import Image
from transformers import AutoModelForImageTextToText, AutoProcessor
model_id = "davanstrien/ocr-decision-0.8b"
processor = AutoProcessor.from_pretrained(model_id)
model = AutoModelForImageTextToText.from_pretrained(
model_id, dtype=torch.bfloat16, device_map="auto"
).eval()
image = Image.open("page.jpg").convert("RGB")
image.thumbnail((1024, 1024))
messages = [
{
"role": "system",
"content": (
"Apply the question to the state. Choose exactly one of the listed options. "
"Respond with only its uppercase letter, with no explanation or reasoning."
),
},
{
"role": "user",
"content": [
{"type": "text", "text": '<state>\n{\n "page": "'},
{"type": "image"},
{
"type": "text",
"text": (
'"\n}\n</state>\n\n'
"Question: Is there printed text on this page?\n\n"
"Options:\n"
"A. yes: the statement is true / the answer is yes\n"
"B. no: the statement is false / the answer is no\n\n"
"Answer with one letter: A, B."
),
},
],
},
]
prompt = processor.apply_chat_template(
messages, tokenize=False, add_generation_prompt=True, enable_thinking=False
)
inputs = processor(text=[prompt], images=[image], return_tensors="pt").to(model.device)
slot_ids = [processor.tokenizer.encode(c, add_special_tokens=False)[0] for c in ("A", "B")]
with torch.inference_mode():
logits = model(**inputs).logits[0, -1, slot_ids].float()
probs = torch.softmax(logits / 2.5, dim=-1).tolist() # T=2.5 matches calibration.json
print({"yes": round(probs[0], 4), "no": round(probs[1], 4)})
```
</details>
## Case study: distilling a CPU-only PDF router for $0.28
You do not necessarily need to run a 0.8B vision model on every page in production. To test routing on real 2026 Common Crawl PDFs (`CC-MAIN-2026-43`, never seen during training), running `ocr-decision-0.8b` for **90 seconds on one RTX PRO 6000 on [Hugging Face Jobs](https://huggingface.co/docs/huggingface_hub/guides/jobs) (~$0.28)** labelled 6,560 pages from 2,400 PDFs, which were then distilled into a pure-CPU XGBoost page classifier using only cheap `pypdfium2` page statistics.
Evaluated on an untouched 200-PDF / 865-page test set (silver ground truth from `LightOnOCR-3` comparing embedded text layers against VLM OCR) and weighted across 44,335 crawl pages:
![FinePDFs-2026 $0.28 CPU router distillation results](./case_study_finepdfs.png)
| Router | Hardware | Needs-OCR F1 | Missing-layer recall | Pages sent to VLM OCR | Relative OCR GPU spend (`2048px`) |
|---|---|---:|---:|---:|---:|
| Production [FinePDFs](https://huggingface.co/datasets/HuggingFaceFW/finepdfs) doc-level XGBoost | CPU | 0.595 | 84% | 19.0% | 1.00× (baseline) |
| **Distilled page-level XGBoost (`$0.28` teacher run)** | **CPU** | **0.777** | **97%** | **13.8%** | **0.63× (-37%)** |
| `ocr-decision-0.8b` direct | GPU | **0.800** | 97% | — | (also catches 4/7 mojibake pages vs. 0/7 for CPU XGB) |
*Why `-37%` GPU spend from `-27%` fewer OCR pages (`19.0% → 13.8%`):* in addition to skipping 27% more digital pages, the cleaner page-level routed subset averaged fewer output tokens per page under `LightOnOCR-3` at 2048px (`$0.110/1k → $0.0955/1k`), combining to `0.727 × 0.868 ≈ 0.63×` (`-37%`) GPU spend.
## Full evaluation
All benchmarks below are strictly out-of-distribution (zero source or volume overlap with training). Base `OneJev1.6-0.8B` and `ocr-decision-0.8b` were evaluated identically through `flide serve` at `max_side=1024`.
### 1. Pre-OCR page facts (held-out historical & modern collections, 1,088 pages)
| Metric | `OneJev1.6-0.8B` (base) | `ocr-decision-0.8b` | Delta (95% page bootstrap CI) |
|---|---:|---:|---:|
| Binary page facts (all 1,047 pages, incl. synthetic rotations) BalAcc / Med AUROC | 0.740 / 0.839 | **0.781 / 0.933** | `+0.042 [+0.024, +0.058]` |
| Binary page facts (real 946 pages only) BalAcc / Med AUROC | 0.741 / 0.831 | **0.822 / 0.999** | `+0.080 [+0.062, +0.097]` |
| Multiple-choice (1,040 question sets) Top-1 | 0.649 | **0.793** | `+0.144 [+0.114, +0.171]` |
| — known option / `"other"` fallback option | 0.652 / 0.642 | **0.817 / 0.745** | `+0.165 / +0.103` |
| — `colour_mode` / `orientation` / `script` | 0.549 / 0.834 / 0.547 | **0.969 / 0.902 / 0.771** | `+0.420 / +0.068 / +0.224` |
| — `handwriting / script hand` / `document_type` | 0.666 / 0.645 | **0.642 / 0.717** | `-0.024 / +0.072` |
| Held-out unseen visual questions (`music`, `stamp_seal`, `catchword`, 203 pairs) | 0.852 | **0.858** | `+0.006` (no forgetting) |
### 2. Full-page OCR verification on real 19th-century books (533 page–OCR pairs, held-out BHL volumes)
Evaluated against real multi-engine OCR failures (not synthetic corruptions) on 6 held-out [Biodiversity Heritage Library](https://www.biodiversitylibrary.org/) volumes:
| Criterion | `OneJev1.6-0.8B` AUROC | `ocr-decision-0.8b` AUROC | Delta (95% bootstrap CI) | Acc @ 0.50 |
|---|---:|---:|---:|---:|
| `blank` (is there printed text?) | 0.967 | **1.000** (0.9998) | `+0.033 [+0.000, +0.074]` | 0.987 |
| `extra` (hallucinated / wrong-page text) | 0.564 | **0.985** | `+0.421 [+0.321, +0.522]` | 0.892 |
| `loop` (stuck repetition loop) | 0.921 | **0.998** | `+0.077 [+0.035, +0.122]` | 0.984 |
| `omission` (missing printed text block) | 0.409 | **0.823** | `+0.414 [+0.291, +0.533]` | 0.585 (best 0.708) |
### 3. Modern 2026 PDF text-layer verification (300 page–layer pairs, Common Crawl 2026 PDFs)
Evaluated on real embedded `pypdfium2` text layers compared against VLM OCR (`LightOnOCR-3`) silver ground truth (`missing`: `<20` embedded chars on a real text page; `partial`: `<45%` of page text present in the embedded layer):
| Criterion | `OneJev1.6-0.8B` AUROC | `ocr-decision-0.8b` AUROC | Acc @ 0.50 |
|---|---:|---:|---:|
| `extra` (wrong-page or injected text vs. clean text layer) | 0.376 | **1.000** | 1.000 |
| `omission` (overall: missing + partial vs. clean) | 0.576 | **0.828** | 0.733 |
| — `missing` text layer vs. clean | 0.679 | **0.998** | — |
| — `partial` text layer vs. clean | 0.472 | **0.658** | — |
### 4. Modern pre-OCR triage & multilingual OCR ([OmniDocBench](https://huggingface.co/datasets/opendatalab/OmniDocBench), 240 OOD pages, EN + ZH)
Evaluated zero-shot on unseen modern layout schemas (English & Chinese academic papers, slides, exams, textbooks, reports, magazines, and newspapers):
| Unseen modern triage question | Pos / N | `OneJev1.6-0.8B` AUROC / BalAcc | `ocr-decision-0.8b` AUROC / BalAcc |
|---|---:|---:|---:|
| `has_table` | 65 / 240 | 0.992 / 0.961 | **0.996 / 0.959** |
| `is_chinese` | 133 / 240 | 0.979 / 0.945 | **0.994 / 0.959** |
| `is_slide` | 30 / 240 | 0.996 / 0.957 | **0.992 / 0.914** |
| `has_equation` | 40 / 240 | 0.983 / 0.965 | **0.982 / 0.968** |
| `has_figure` | 105 / 240 | 0.968 / 0.897 | **0.980 / 0.952** |
| `is_exam_paper` | 30 / 240 | 0.886 / 0.764 | **0.886 / 0.764** |
| `is_multi_column` | 50 / 240 | 0.748 / 0.682 | **0.852 / 0.781** |
| `has_footnote` | 46 / 240 | 0.840 / 0.672 | **0.831 / 0.598** |
OCR verification on `OmniDocBench` (EN + ZH human-annotated blocks) and harder historic domains (**Chronicling America** dense multi-column newspapers & **BPL Archival Catalogue Cards**):
| Domain (OOD) | `extra` AUROC (base → tuned) | `loop` AUROC (base → tuned) | `omission` AUROC (base → tuned) |
|---|---:|---:|---:|
| `OmniDocBench` — English | 0.290 → **1.000** | 0.957 → **1.000** | 0.519 → **0.837** |
| `OmniDocBench` — Chinese | 0.452 → **1.000** | 0.978 → **1.000** | 0.568 → **0.816** |
| BPL Archival Catalogue Cards (57 cards) | 0.163 → **1.000** | 1.000 → **1.000** | 0.438 → **1.000** |
| Chronicling America Newspapers (48 dense pages) | 0.919 → **1.000** | 0.926 → **1.000** | 0.568 → **0.726** |
### 5. Prompt phrasing robustness
Tested across 3–4 unseen natural user phrasings per criterion (including flipped-polarity questions) on BHL and 2026 PDFs:
- **`extra`:** `0.980–0.989` AUROC on BHL (`Δ = 0.009`), `1.000` across all 4 phrasings on 2026 PDFs.
- **`loop`:** `1.000` across all 3 phrasings (including flipped polarity).
- **`omission`:** `0.820–0.838` on BHL and `0.800–0.826` on 2026 PDFs across casual, standard, and flipped-polarity phrasings (except phrasing around *"readable printed content"*, which drops to `0.62–0.67`).
### 6. Throughput & cost
Measured on [Hugging Face Jobs](https://huggingface.co/docs/huggingface_hub/guides/jobs) via `flide serve` (BF16, `max_side=1024`, pre-encoded real 2026 PDF pages with an average OCR text length of ~2,100 chars; actual throughput depends on image resolution and transcription length). Because `flide` encodes the page image once and shares the KV prefix across every question on that page, asking 9 triage questions instead of 1 adds only **~2.6 ms** single-stream on an RTX PRO 6000:
| Workload (`flide serve`, BF16, `1024px`) | NVIDIA L4 (24 GB, ~$0.80/hr) | NVIDIA RTX PRO 6000 (96 GB, ~$2.75/hr) |
|---|---:|---:|
| **Pre-OCR triage (1 question)** | ~21 pages/s (~$11 / 1M pages) | ~107 pages/s (~$7 / 1M pages) |
| **Pre-OCR triage (9 questions: 8 yes/no + 1 choice)** | ~15 pages/s (~$14 / 1M pages) | ~87 pages/s (~$9 / 1M pages) |
| **OCR verification (3 questions: `extra` + `omission` + `loop`)** | ~13 pages/s (~$17 / 1M pages) | ~73 pages/s (~$10 / 1M pages) |
| **Single-stream median latency (1q / 9q / 3q-OCR)** | 51 / 69 / 75 ms | 20 / 22 / 27 ms |
Default **BF16 is recommended**: `--quantize fp8` adds only ~5–6% on RTX PRO 6000 with a slight dip on partial omissions (`0.655 → 0.642`), and is ~25% slower than BF16 on L4 due to quantization overhead at 0.8B scale.
## Training & provenance
- **Base model:** [OmniJev/OneJev1.6-0.8B](https://huggingface.co/OmniJev/OneJev1.6-0.8B) (Apache-2.0, `Qwen3_5ForConditionalGeneration`).
- **Training data:** 97,392 decisions across 18,454 unique pages, trained only on commercially permissive datasets (no NC or restricted corpora; zero Common Crawl 2026 PDFs in training):
- Full-page document & OCR verification pairs from [allenai/olmOCR-mix-1025](https://huggingface.co/datasets/allenai/olmOCR-mix-1025) (ODC-BY: modern PDFs, scanned books, Library of Congress transcripts, National Archives records, with non-English pages oversampled), [docling-project/DocLayNet-v1.2](https://huggingface.co/datasets/docling-project/DocLayNet-v1.2) (CDLA-Permissive: surgical single-layout-box omissions via `pdf_cells`), and [JustQuiteMadMax/ukrainian-handwritten-text-full-pages](https://huggingface.co/datasets/JustQuiteMadMax/ukrainian-handwritten-text-full-pages) (CC-BY-4.0: full-page handwritten Cyrillic manuscripts).
- Pre-OCR page-attribute yes/no and multiple-choice annotations curated from public-domain and CC-licensed archival/document collections (explicitly filtered to exclude any non-commercial or restricted sources; real pages only, no synthetic blur/crop distortions), plus lossless 90°/180°/270° page rotations and permissive text-NLI replay pairs (6,361 pairs) to prevent forgetting on general decision prompts.
- **Method:** Two independent LoRA runs (`seed=42`, `seed=137`; `r=32, alpha=64` across all LM full-attention, Gated DeltaNet, MLP, and vision encoder/projector linear layers; `max_side=1024`; `lr=8e-5`; valid-slot label smoothing `0.05`; 1 epoch each), merged as a 2-seed WiSE-FT model soup at `0.60×` delta scale with base `OneJev1.6-0.8B`, plus `calibration.json` (`T=2.5` for yes/no) and `decision_config.json`.
- **Compute:** ~7.1 GPU-hours total on [Hugging Face Jobs](https://huggingface.co/docs/huggingface_hub/guides/jobs) (NVIDIA RTX PRO 6000, ~$20 for the two final training runs).
## Limitations
- **Single-page scope:** evaluates one page image (plus optional transcription) at a time; it does not compare across pages or generate transcriptions/bounding boxes.
- **Partial omissions on dense pages:** detects missing text layers (`0.998`) and large dropped blocks across English and Chinese (`0.837` / `0.816`), but subtle 5–15% partial omissions remain harder — especially on dense multi-column historical newspapers (`0.726`), long 19th-century prose pages (`0.823`), and modern tables/spec sheets (`0.658`).
- **Custom multiple-choice taxonomies vs. yes/no questions:** on brand-new document-type taxonomies far from training (e.g. a 6-way `OmniDocBench` split), zero-shot multiple-choice accuracy (`0.600`) trails targeted yes/no questions (`0.85–0.996`). For custom modern routing schemas, split them into crisp yes/no checks.
- **Language & handwriting coverage:** quantitative held-out evaluations cover English, Chinese (`OmniDocBench`), historical European Latin-script books, and Ukrainian Cyrillic. Other languages listed in metadata (including Japanese and Arabic) appeared via `olmOCR-mix-1025` multilingual oversampling without dedicated held-out evals. Historical manuscript training data is weighted toward 19th-century Latin-script archival letters and Ukrainian Cyrillic (`handwriting / script hand` top-1 is `0.642`), and Greek/Hebrew/Devanagari coverage is thin.
## Credits & licence
Weights are released under the **Apache-2.0** licence, building on [OmniJev/OneJev1.6-0.8B](https://huggingface.co/OmniJev/OneJev1.6-0.8B) and [Qwen3.5](https://huggingface.co/Qwen) and trained on permissive datasets from Ai2 (`olmOCR-mix-1025`), Docling (`DocLayNet-v1.2`), and open archival collections. Fine-tuned and evaluated by [Daniel van Strien](https://huggingface.co/davanstrien).