Sync from GitHub via hub-sync
Browse files
README.md
CHANGED
|
@@ -5,11 +5,11 @@ tags: [uv-script, ocr, vision-language-model, document-processing, hf-jobs]
|
|
| 5 |
|
| 6 |
# OCR UV Scripts
|
| 7 |
|
| 8 |
-
> Part of [uv-scripts](https://huggingface.co/uv-scripts)
|
| 9 |
|
| 10 |
-
|
| 11 |
|
| 12 |
-
##
|
| 13 |
|
| 14 |
Run OCR on any dataset without needing your own GPU:
|
| 15 |
|
|
@@ -22,14 +22,24 @@ hf jobs uv run --flavor l4x1 \
|
|
| 22 |
--max-samples 10
|
| 23 |
```
|
| 24 |
|
| 25 |
-
|
| 26 |
|
| 27 |
-
- Process first 10 images from your dataset
|
| 28 |
- Add OCR results as a new `markdown` column
|
| 29 |
- Push the results to a new dataset
|
| 30 |
- View results at: `https://huggingface.co/datasets/[your-output-dataset]`
|
| 31 |
|
| 32 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 33 |
|
| 34 |
| Script | Model | Size | Backend | Notes |
|
| 35 |
|--------|-------|------|---------|-------|
|
|
@@ -38,6 +48,7 @@ That's it! The script will:
|
|
| 38 |
| `glm-ocr.py` | [GLM-OCR](https://huggingface.co/zai-org/GLM-OCR) | 0.9B | vLLM | 94.62% OmniDocBench V1.5 |
|
| 39 |
| `paddleocr-vl.py` | [PaddleOCR-VL](https://huggingface.co/PaddlePaddle/PaddleOCR-VL) | 0.9B | Transformers | 4 task modes (ocr/table/formula/chart) |
|
| 40 |
| `paddleocr-vl-1.5.py` | [PaddleOCR-VL-1.5](https://huggingface.co/PaddlePaddle/PaddleOCR-VL-1.5) | 0.9B | Transformers | 94.5% OmniDocBench, 6 task modes |
|
|
|
|
| 41 |
| `lighton-ocr.py` | [LightOnOCR-1B](https://huggingface.co/lightonai/LightOnOCR-1B-1025) | 1B | vLLM | Fast, 3 vocab sizes |
|
| 42 |
| `lighton-ocr2.py` | [LightOnOCR-2-1B](https://huggingface.co/lightonai/LightOnOCR-2-1B) | 1B | vLLM | 7× faster than v1, RLVR trained |
|
| 43 |
| `hunyuan-ocr.py` | [HunyuanOCR](https://huggingface.co/tencent/HunyuanOCR) | 1B | vLLM | Lightweight VLM |
|
|
@@ -56,7 +67,7 @@ That's it! The script will:
|
|
| 56 |
| `rolm-ocr.py` | [RolmOCR](https://huggingface.co/reducto/RolmOCR) | 7B | vLLM | Qwen2.5-VL based, general-purpose |
|
| 57 |
| `numarkdown-ocr.py` | [NuMarkdown-8B](https://huggingface.co/numind/NuMarkdown-8B-Thinking) | 8B | vLLM | Reasoning-based OCR |
|
| 58 |
|
| 59 |
-
|
| 60 |
|
| 61 |
## Layout detection (not OCR)
|
| 62 |
|
|
@@ -76,7 +87,7 @@ Source/sink can be either an HF dataset repo OR an `hf://buckets/...` URL (auto-
|
|
| 76 |
|
| 77 |
## Common Options
|
| 78 |
|
| 79 |
-
|
| 80 |
|
| 81 |
| Option | Description |
|
| 82 |
|--------|-------------|
|
|
@@ -101,28 +112,7 @@ Every script supports `--help` to see all available options:
|
|
| 101 |
uv run glm-ocr.py --help
|
| 102 |
```
|
| 103 |
|
| 104 |
-
##
|
| 105 |
-
|
| 106 |
-
[GLM-OCR](https://huggingface.co/zai-org/GLM-OCR) (0.9B) scores 94.62% on OmniDocBench V1.5 and supports OCR, formula, and table extraction:
|
| 107 |
-
|
| 108 |
-
```bash
|
| 109 |
-
# Basic OCR
|
| 110 |
-
hf jobs uv run --flavor l4x1 -s HF_TOKEN \
|
| 111 |
-
https://huggingface.co/datasets/uv-scripts/ocr/raw/main/glm-ocr.py \
|
| 112 |
-
my-documents my-ocr-output
|
| 113 |
-
|
| 114 |
-
# Table extraction
|
| 115 |
-
hf jobs uv run --flavor l4x1 -s HF_TOKEN \
|
| 116 |
-
https://huggingface.co/datasets/uv-scripts/ocr/raw/main/glm-ocr.py \
|
| 117 |
-
my-documents my-tables --task table
|
| 118 |
-
|
| 119 |
-
# Test on 10 samples first
|
| 120 |
-
hf jobs uv run --flavor l4x1 -s HF_TOKEN \
|
| 121 |
-
https://huggingface.co/datasets/uv-scripts/ocr/raw/main/glm-ocr.py \
|
| 122 |
-
my-documents my-test --max-samples 10
|
| 123 |
-
```
|
| 124 |
-
|
| 125 |
-
## Example: NuExtract3 (markdown OCR **+ structured extraction**)
|
| 126 |
|
| 127 |
[NuExtract3](https://huggingface.co/numind/NuExtract3) (4B, Apache-2.0) is the one script here that does both document-to-markdown OCR *and* schema-guided JSON extraction. Give it a template (or a JSON Schema / Pydantic model) and it returns JSON shaped to match.
|
| 128 |
|
|
@@ -149,618 +139,61 @@ hf jobs uv run --flavor a100-large \
|
|
| 149 |
--template '{"store": "verbatim-string", "date": "date", "total": "number"}'
|
| 150 |
```
|
| 151 |
|
| 152 |
-
**Templates** (`--template`) and **JSON Schemas** (`--schema`) each accept **inline JSON, a URL, or a file path**
|
| 153 |
-
|
| 154 |
-
```bash
|
| 155 |
-
# From a URL (e.g. an HF dataset's raw file)
|
| 156 |
-
... nuextract3.py docs out --template https://huggingface.co/datasets/ORG/REPO/raw/main/card.json
|
| 157 |
-
|
| 158 |
-
# From a JSON Schema / Pydantic model — Model.model_json_schema() dumped to JSON,
|
| 159 |
-
# auto-converted via numind's convert_json_schema_to_nuextract_template
|
| 160 |
-
... nuextract3.py docs out --schema invoice-schema.json
|
| 161 |
-
|
| 162 |
-
# From a mounted bucket (host configs in a bucket, mount read-only)
|
| 163 |
-
hf jobs uv run --flavor a100-large \
|
| 164 |
-
--image vllm/vllm-openai:latest --python /usr/bin/python3 \
|
| 165 |
-
-e PYTHONPATH=/usr/local/lib/python3.12/dist-packages -s HF_TOKEN \
|
| 166 |
-
-v hf://buckets/USER/configs:/configs:ro \
|
| 167 |
-
https://huggingface.co/datasets/uv-scripts/ocr/raw/main/nuextract3.py \
|
| 168 |
-
docs out --template /configs/card.json
|
| 169 |
-
```
|
| 170 |
-
|
| 171 |
-
Add `--enable-thinking` for harder layouts (slower; reasoning trace stored in a `<output-column>_reasoning` column). Template field names act as the model's extraction instructions, so name them descriptively — but note that overly leading names can prompt over-generation, so verify against a few examples.
|
| 172 |
-
|
| 173 |
-
<details><summary>Detailed per-model documentation</summary>
|
| 174 |
-
|
| 175 |
-
### PaddleOCR-VL-1.5 (`paddleocr-vl-1.5.py`) — 6 task modes
|
| 176 |
-
|
| 177 |
-
OCR using [PaddlePaddle/PaddleOCR-VL-1.5](https://huggingface.co/PaddlePaddle/PaddleOCR-VL-1.5) with 94.5% accuracy:
|
| 178 |
-
|
| 179 |
-
- **94.5% on OmniDocBench v1.5** (0.9B parameters)
|
| 180 |
-
- 🧩 **Ultra-compact** - Only 0.9B parameters
|
| 181 |
-
- 📝 **OCR mode** - General text extraction to markdown
|
| 182 |
-
- 📊 **Table mode** - HTML table recognition
|
| 183 |
-
- 📐 **Formula mode** - LaTeX mathematical notation
|
| 184 |
-
- 📈 **Chart mode** - Chart and diagram analysis
|
| 185 |
-
- 🔍 **Spotting mode** - Text spotting with localization (higher resolution)
|
| 186 |
-
- 🔖 **Seal mode** - Seal and stamp recognition
|
| 187 |
-
- 🌍 **Multilingual** - Support for multiple languages
|
| 188 |
-
|
| 189 |
-
**Task Modes:**
|
| 190 |
-
|
| 191 |
-
- `ocr`: General text extraction (default)
|
| 192 |
-
- `table`: Table extraction to HTML
|
| 193 |
-
- `formula`: Mathematical formula to LaTeX
|
| 194 |
-
- `chart`: Chart and diagram analysis
|
| 195 |
-
- `spotting`: Text spotting with localization
|
| 196 |
-
- `seal`: Seal and stamp recognition
|
| 197 |
-
|
| 198 |
-
**Quick start:**
|
| 199 |
-
|
| 200 |
-
```bash
|
| 201 |
-
# Basic OCR mode
|
| 202 |
-
hf jobs uv run --flavor l4x1 \
|
| 203 |
-
-s HF_TOKEN \
|
| 204 |
-
https://huggingface.co/datasets/uv-scripts/ocr/raw/main/paddleocr-vl-1.5.py \
|
| 205 |
-
your-input-dataset your-output-dataset \
|
| 206 |
-
--max-samples 100
|
| 207 |
-
|
| 208 |
-
# Table extraction
|
| 209 |
-
hf jobs uv run --flavor l4x1 \
|
| 210 |
-
-s HF_TOKEN \
|
| 211 |
-
https://huggingface.co/datasets/uv-scripts/ocr/raw/main/paddleocr-vl-1.5.py \
|
| 212 |
-
documents tables-extracted \
|
| 213 |
-
--task-mode table
|
| 214 |
-
|
| 215 |
-
# Seal recognition
|
| 216 |
-
hf jobs uv run --flavor l4x1 \
|
| 217 |
-
-s HF_TOKEN \
|
| 218 |
-
https://huggingface.co/datasets/uv-scripts/ocr/raw/main/paddleocr-vl-1.5.py \
|
| 219 |
-
documents seals-extracted \
|
| 220 |
-
--task-mode seal
|
| 221 |
-
```
|
| 222 |
-
|
| 223 |
-
### PaddleOCR-VL (`paddleocr-vl.py`) 🎯 Smallest model with task-specific modes!
|
| 224 |
-
|
| 225 |
-
Ultra-compact OCR using [PaddlePaddle/PaddleOCR-VL](https://huggingface.co/PaddlePaddle/PaddleOCR-VL) with only 0.9B parameters:
|
| 226 |
-
|
| 227 |
-
- 🎯 **Smallest model** - Only 0.9B parameters (even smaller than LightOnOCR!)
|
| 228 |
-
- 📝 **OCR mode** - General text extraction to markdown
|
| 229 |
-
- 📊 **Table mode** - HTML table recognition and extraction
|
| 230 |
-
- 📐 **Formula mode** - LaTeX mathematical notation
|
| 231 |
-
- 📈 **Chart mode** - Structured chart and diagram analysis
|
| 232 |
-
- 🌍 **Multilingual** - Support for multiple languages
|
| 233 |
-
- ⚡ **Fast initialization** - Tiny model size for quick startup
|
| 234 |
-
- 🔧 **ERNIE-4.5 based** - Different architecture from Qwen models
|
| 235 |
-
|
| 236 |
-
**Task Modes:**
|
| 237 |
-
|
| 238 |
-
- `ocr`: General text extraction (default)
|
| 239 |
-
- `table`: Table extraction to HTML
|
| 240 |
-
- `formula`: Mathematical formula to LaTeX
|
| 241 |
-
- `chart`: Chart and diagram analysis
|
| 242 |
-
|
| 243 |
-
**Quick start:**
|
| 244 |
-
|
| 245 |
-
```bash
|
| 246 |
-
# Basic OCR mode
|
| 247 |
-
hf jobs uv run --flavor l4x1 \
|
| 248 |
-
-s HF_TOKEN \
|
| 249 |
-
https://huggingface.co/datasets/uv-scripts/ocr/raw/main/paddleocr-vl.py \
|
| 250 |
-
your-input-dataset your-output-dataset \
|
| 251 |
-
--max-samples 100
|
| 252 |
-
|
| 253 |
-
# Table extraction
|
| 254 |
-
hf jobs uv run --flavor l4x1 \
|
| 255 |
-
-s HF_TOKEN \
|
| 256 |
-
https://huggingface.co/datasets/uv-scripts/ocr/raw/main/paddleocr-vl.py \
|
| 257 |
-
documents tables-extracted \
|
| 258 |
-
--task-mode table \
|
| 259 |
-
--batch-size 32
|
| 260 |
-
```
|
| 261 |
-
|
| 262 |
-
### GLM-OCR (`glm-ocr.py`) 🏆 SOTA on OmniDocBench V1.5!
|
| 263 |
-
|
| 264 |
-
Compact high-performance OCR using [zai-org/GLM-OCR](https://huggingface.co/zai-org/GLM-OCR) with 0.9B parameters:
|
| 265 |
-
|
| 266 |
-
- 🏆 **94.62% on OmniDocBench V1.5** - #1 overall ranking
|
| 267 |
-
- 🧠 **Multi-Token Prediction** - MTP loss + stable full-task RL for quality
|
| 268 |
-
- 📝 **Text recognition** - Clean markdown output
|
| 269 |
-
- 📐 **Formula recognition** - LaTeX mathematical notation
|
| 270 |
-
- 📊 **Table recognition** - Structured table extraction
|
| 271 |
-
- 🌍 **Multilingual** - zh, en, fr, es, ru, de, ja, ko
|
| 272 |
-
- ⚡ **Compact** - Only 0.9B parameters, MIT licensed
|
| 273 |
-
- 🔧 **CogViT + GLM** - Visual encoder with efficient token downsampling
|
| 274 |
-
|
| 275 |
-
**Task Modes:**
|
| 276 |
-
|
| 277 |
-
- `ocr`: Text recognition (default)
|
| 278 |
-
- `formula`: LaTeX formula recognition
|
| 279 |
-
- `table`: Table extraction
|
| 280 |
-
|
| 281 |
-
**Quick start:**
|
| 282 |
-
|
| 283 |
-
```bash
|
| 284 |
-
# Basic OCR
|
| 285 |
-
hf jobs uv run --flavor l4x1 \
|
| 286 |
-
-s HF_TOKEN \
|
| 287 |
-
https://huggingface.co/datasets/uv-scripts/ocr/raw/main/glm-ocr.py \
|
| 288 |
-
your-input-dataset your-output-dataset \
|
| 289 |
-
--max-samples 100
|
| 290 |
-
|
| 291 |
-
# Formula recognition
|
| 292 |
-
hf jobs uv run --flavor l4x1 \
|
| 293 |
-
-s HF_TOKEN \
|
| 294 |
-
https://huggingface.co/datasets/uv-scripts/ocr/raw/main/glm-ocr.py \
|
| 295 |
-
scientific-papers formulas-extracted \
|
| 296 |
-
--task formula
|
| 297 |
-
|
| 298 |
-
# Table extraction
|
| 299 |
-
hf jobs uv run --flavor l4x1 \
|
| 300 |
-
-s HF_TOKEN \
|
| 301 |
-
https://huggingface.co/datasets/uv-scripts/ocr/raw/main/glm-ocr.py \
|
| 302 |
-
documents tables-extracted \
|
| 303 |
-
--task table
|
| 304 |
-
```
|
| 305 |
-
|
| 306 |
-
### LightOnOCR (`lighton-ocr.py`) ⚡ Good one to test first since it's small and fast!
|
| 307 |
-
|
| 308 |
-
Fast and compact OCR using [lightonai/LightOnOCR-1B-1025](https://huggingface.co/lightonai/LightOnOCR-1B-1025):
|
| 309 |
-
|
| 310 |
-
- ⚡ **Fastest**: 5.71 pages/sec on H100, ~6.25 images/sec on A100 with batch_size=4096
|
| 311 |
-
- 🎯 **Compact**: Only 1B parameters - quick to download and initialize
|
| 312 |
-
- 🌍 **Multilingual**: 3 vocabulary sizes for different use cases
|
| 313 |
-
- 📐 **LaTeX formulas**: Mathematical notation in LaTeX format
|
| 314 |
-
- 📊 **Table extraction**: Markdown table format
|
| 315 |
-
- 📝 **Document structure**: Preserves hierarchy and layout
|
| 316 |
-
- 🚀 **Production-ready**: 76.1% benchmark score, used in production
|
| 317 |
-
|
| 318 |
-
**Vocabulary sizes:**
|
| 319 |
-
|
| 320 |
-
- `151k`: Full vocabulary, all languages (default)
|
| 321 |
-
- `32k`: European languages, ~12% faster decoding
|
| 322 |
-
- `16k`: European languages, ~12% faster decoding
|
| 323 |
-
|
| 324 |
-
**Quick start:**
|
| 325 |
-
|
| 326 |
-
```bash
|
| 327 |
-
# Test on 100 samples with English text (32k vocab is fastest for European languages)
|
| 328 |
-
hf jobs uv run --flavor l4x1 \
|
| 329 |
-
-s HF_TOKEN \
|
| 330 |
-
https://huggingface.co/datasets/uv-scripts/ocr/raw/main/lighton-ocr.py \
|
| 331 |
-
your-input-dataset your-output-dataset \
|
| 332 |
-
--vocab-size 32k \
|
| 333 |
-
--batch-size 32 \
|
| 334 |
-
--max-samples 100
|
| 335 |
-
|
| 336 |
-
# Full production run on A100 (can handle huge batches!)
|
| 337 |
-
hf jobs uv run --flavor a100-large \
|
| 338 |
-
-s HF_TOKEN \
|
| 339 |
-
https://huggingface.co/datasets/uv-scripts/ocr/raw/main/lighton-ocr.py \
|
| 340 |
-
your-input-dataset your-output-dataset \
|
| 341 |
-
--vocab-size 32k \
|
| 342 |
-
--batch-size 4096 \
|
| 343 |
-
--temperature 0.0
|
| 344 |
-
```
|
| 345 |
-
|
| 346 |
-
### LightOnOCR-2 (`lighton-ocr2.py`) ⚡ Fastest OCR model!
|
| 347 |
-
|
| 348 |
-
Next-generation fast OCR using [lightonai/LightOnOCR-2-1B](https://huggingface.co/lightonai/LightOnOCR-2-1B) with RLVR training:
|
| 349 |
-
|
| 350 |
-
- ⚡ **7× faster than v1**: 42.8 pages/sec on H100 (vs 5.71 for v1)
|
| 351 |
-
- 🎯 **Higher accuracy**: 83.2% on OlmOCR-Bench (+7.1% vs v1)
|
| 352 |
-
- 🧠 **RLVR trained**: Eliminates repetition loops and formatting errors
|
| 353 |
-
- 📚 **Better dataset**: 2.5× larger training data with cleaner annotations
|
| 354 |
-
- 🌍 **Multilingual**: Optimized for European languages
|
| 355 |
-
- 📐 **LaTeX formulas**: Mathematical notation support
|
| 356 |
-
- 📊 **Table extraction**: Markdown table format
|
| 357 |
-
- 💪 **Production-ready**: Outperforms models 9× larger
|
| 358 |
-
|
| 359 |
-
**Quick start:**
|
| 360 |
-
|
| 361 |
-
```bash
|
| 362 |
-
# Test on 100 samples
|
| 363 |
-
hf jobs uv run --flavor a100-large \
|
| 364 |
-
-s HF_TOKEN \
|
| 365 |
-
https://huggingface.co/datasets/uv-scripts/ocr/raw/main/lighton-ocr2.py \
|
| 366 |
-
your-input-dataset your-output-dataset \
|
| 367 |
-
--batch-size 32 \
|
| 368 |
-
--max-samples 100
|
| 369 |
-
|
| 370 |
-
# Full production run
|
| 371 |
-
hf jobs uv run --flavor a100-large \
|
| 372 |
-
-s HF_TOKEN \
|
| 373 |
-
https://huggingface.co/datasets/uv-scripts/ocr/raw/main/lighton-ocr2.py \
|
| 374 |
-
your-input-dataset your-output-dataset \
|
| 375 |
-
--batch-size 32
|
| 376 |
-
```
|
| 377 |
-
|
| 378 |
-
### DeepSeek-OCR (`deepseek-ocr-vllm.py`)
|
| 379 |
-
|
| 380 |
-
Advanced document OCR using [deepseek-ai/DeepSeek-OCR](https://huggingface.co/deepseek-ai/DeepSeek-OCR) with visual-text compression:
|
| 381 |
-
|
| 382 |
-
- 📐 **LaTeX equations** - Mathematical formulas in LaTeX format
|
| 383 |
-
- 📊 **Tables** - Extracted as HTML/markdown
|
| 384 |
-
- 📝 **Document structure** - Headers, lists, formatting preserved
|
| 385 |
-
- 🖼️ **Image grounding** - Spatial layout with bounding boxes
|
| 386 |
-
- 🔍 **Complex layouts** - Multi-column and hierarchical structures
|
| 387 |
-
- 🌍 **Multilingual** - Multiple language support
|
| 388 |
-
- 🎚️ **Resolution modes** - 5 presets for speed/quality trade-offs
|
| 389 |
-
- 💬 **Prompt modes** - 5 presets for different OCR tasks
|
| 390 |
-
- ⚡ **Fast batch processing** - vLLM acceleration
|
| 391 |
-
|
| 392 |
-
**Resolution Modes:**
|
| 393 |
-
|
| 394 |
-
- `tiny` (512×512): Fast, 64 vision tokens
|
| 395 |
-
- `small` (640×640): Balanced, 100 vision tokens
|
| 396 |
-
- `base` (1024×1024): High quality, 256 vision tokens
|
| 397 |
-
- `large` (1280×1280): Maximum quality, 400 vision tokens
|
| 398 |
-
- `gundam` (dynamic): Adaptive multi-tile (default)
|
| 399 |
-
|
| 400 |
-
**Prompt Modes:**
|
| 401 |
-
|
| 402 |
-
- `document`: Convert to markdown with grounding (default)
|
| 403 |
-
- `image`: OCR any image with grounding
|
| 404 |
-
- `free`: Fast OCR without layout
|
| 405 |
-
- `figure`: Parse figures from documents
|
| 406 |
-
- `describe`: Detailed image descriptions
|
| 407 |
-
|
| 408 |
-
### RolmOCR (`rolm-ocr.py`)
|
| 409 |
-
|
| 410 |
-
Fast general-purpose OCR using [reducto/RolmOCR](https://huggingface.co/reducto/RolmOCR) based on Qwen2.5-VL-7B:
|
| 411 |
-
|
| 412 |
-
- 🚀 **Fast extraction** - Optimized for speed and efficiency
|
| 413 |
-
- 📄 **Plain text output** - Clean, natural text representation
|
| 414 |
-
- 💪 **General-purpose** - Works well on various document types
|
| 415 |
-
- 🔥 **Large context** - Handles up to 16K tokens
|
| 416 |
-
- ⚡ **Batch optimized** - Efficient processing with vLLM
|
| 417 |
-
|
| 418 |
-
### Nanonets OCR (`nanonets-ocr.py`)
|
| 419 |
-
|
| 420 |
-
State-of-the-art document OCR using [nanonets/Nanonets-OCR-s](https://huggingface.co/nanonets/Nanonets-OCR-s) that handles:
|
| 421 |
-
|
| 422 |
-
- 📐 **LaTeX equations** - Mathematical formulas preserved
|
| 423 |
-
- 📊 **Tables** - Extracted as HTML format
|
| 424 |
-
- 📝 **Document structure** - Headers, lists, formatting maintained
|
| 425 |
-
- 🖼️ **Images** - Captions and descriptions included
|
| 426 |
-
- ☑️ **Forms** - Checkboxes rendered as ☐/☑
|
| 427 |
-
|
| 428 |
-
### Nanonets OCR2 (`nanonets-ocr2.py`)
|
| 429 |
|
| 430 |
-
|
| 431 |
|
| 432 |
-
|
| 433 |
-
- 📐 **LaTeX equations** - Mathematical formulas preserved in LaTeX format
|
| 434 |
-
- 📊 **Advanced tables** - Improved HTML table extraction
|
| 435 |
-
- 📝 **Document structure** - Headers, lists, formatting maintained
|
| 436 |
-
- 🖼️ **Smart image captions** - Intelligent descriptions and captions
|
| 437 |
-
- ☑️ **Forms** - Checkboxes rendered as ☐/☑
|
| 438 |
-
- 🌍 **Multilingual** - Enhanced language support
|
| 439 |
-
- 🔧 **Based on Qwen2.5-VL** - Built on state-of-the-art vision-language model
|
| 440 |
|
| 441 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 442 |
|
| 443 |
-
|
| 444 |
|
| 445 |
-
|
| 446 |
-
- 💻 **Code blocks** - Preserves indentation and syntax
|
| 447 |
-
- 🔢 **Formulas** - Mathematical expressions with layout
|
| 448 |
-
- 📊 **Tables & charts** - Structured data extraction
|
| 449 |
-
- 📐 **Layout preservation** - Bounding boxes and spatial info
|
| 450 |
-
- ⚡ **Ultra-fast** - Tiny model size for quick inference
|
| 451 |
|
| 452 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 453 |
|
| 454 |
-
|
| 455 |
-
|
| 456 |
-
- 🧠 **Reasoning Process** - Thinks through document layout before generation
|
| 457 |
-
- 📊 **Complex Tables** - Superior table extraction and formatting
|
| 458 |
-
- 📐 **Mathematical Formulas** - Accurate LaTeX/math notation preservation
|
| 459 |
-
- 🔍 **Multi-column Layouts** - Handles complex document structures
|
| 460 |
-
- ✨ **Thinking Traces** - Optional inclusion of reasoning process with `--include-thinking`
|
| 461 |
-
|
| 462 |
-
### dots.mocr (`dots-mocr.py`) — SVG generation + SOTA OCR
|
| 463 |
-
|
| 464 |
-
Advanced multilingual OCR and SVG generation using [rednote-hilab/dots.mocr](https://huggingface.co/rednote-hilab/dots.mocr) with 3B parameters:
|
| 465 |
-
|
| 466 |
-
- 🌍 **100+ Languages** - Extensive multilingual support
|
| 467 |
-
- 📝 **Document OCR** - Clean text extraction (default mode)
|
| 468 |
-
- 📊 **Layout Analysis** - Structured output with bboxes and categories
|
| 469 |
-
- 📐 **Formula recognition** - LaTeX format support
|
| 470 |
-
- 🖼️ **SVG generation** - Convert charts, UI layouts, figures to editable SVG code
|
| 471 |
-
- 🔀 **8 prompt modes** - OCR, layout-all, layout-only, web-parsing, scene-spotting, grounding-ocr, svg, general
|
| 472 |
-
- 📄 **[Paper](https://arxiv.org/abs/2603.13032)** - 83.9% on olmOCR-Bench
|
| 473 |
-
|
| 474 |
-
**SVG variant:** Use `--model rednote-hilab/dots.mocr-svg` with `--prompt-mode svg` for best SVG results.
|
| 475 |
-
|
| 476 |
-
**Quick start:**
|
| 477 |
|
| 478 |
```bash
|
| 479 |
-
#
|
| 480 |
-
hf jobs uv run --flavor
|
| 481 |
-
-
|
| 482 |
-
|
| 483 |
-
|
| 484 |
-
--max-samples 100
|
| 485 |
-
|
| 486 |
-
# SVG generation from charts/figures
|
| 487 |
-
hf jobs uv run --flavor l4x1 \
|
| 488 |
-
-s HF_TOKEN \
|
| 489 |
-
https://huggingface.co/datasets/uv-scripts/ocr/raw/main/dots-mocr.py \
|
| 490 |
-
your-charts svg-output \
|
| 491 |
-
--prompt-mode svg --model rednote-hilab/dots.mocr-svg
|
| 492 |
|
| 493 |
-
#
|
| 494 |
-
hf jobs uv run --flavor l4x1 \
|
| 495 |
-
-s HF_TOKEN \
|
| 496 |
https://huggingface.co/datasets/uv-scripts/ocr/raw/main/dots-mocr.py \
|
| 497 |
-
your-
|
| 498 |
-
--prompt-mode layout-all
|
| 499 |
-
```
|
| 500 |
-
|
| 501 |
-
### DoTS.ocr v1 (`dots-ocr.py`)
|
| 502 |
-
|
| 503 |
-
Compact multilingual OCR using [rednote-hilab/dots.ocr](https://huggingface.co/rednote-hilab/dots.ocr) with only 1.7B parameters:
|
| 504 |
-
|
| 505 |
-
- 🌍 **100+ Languages** - Extensive multilingual support
|
| 506 |
-
- 📝 **Simple OCR** - Clean text extraction (default mode)
|
| 507 |
-
- 📊 **Layout Analysis** - Optional structured output with bboxes and categories
|
| 508 |
-
- 📐 **Formula recognition** - LaTeX format support
|
| 509 |
-
- 🎯 **Compact** - Only 1.7B parameters, efficient on smaller GPUs
|
| 510 |
-
- 🔀 **Flexible prompts** - Switch between OCR, layout-all, and layout-only modes
|
| 511 |
-
|
| 512 |
-
### FireRed-OCR (`firered-ocr.py`)
|
| 513 |
-
|
| 514 |
-
Document OCR using [FireRedTeam/FireRed-OCR](https://huggingface.co/FireRedTeam/FireRed-OCR), a 2.1B model fine-tuned from Qwen3-VL-2B-Instruct:
|
| 515 |
-
|
| 516 |
-
- 📝 **Structured Markdown** - Preserves headings, paragraphs, lists
|
| 517 |
-
- 📐 **LaTeX formulas** - Inline and block math support
|
| 518 |
-
- 📊 **HTML tables** - Table extraction with `<table>` tags
|
| 519 |
-
- 🪶 **Lightweight** - 2.1B parameters, runs on L4 GPU
|
| 520 |
-
- 📜 **Apache 2.0** - Permissive license
|
| 521 |
-
|
| 522 |
-
**Quick start:**
|
| 523 |
-
|
| 524 |
-
```bash
|
| 525 |
-
hf jobs uv run --flavor l4x1 \
|
| 526 |
-
-s HF_TOKEN \
|
| 527 |
-
https://huggingface.co/datasets/uv-scripts/ocr/raw/main/firered-ocr.py \
|
| 528 |
-
your-input-dataset your-output-dataset \
|
| 529 |
-
--max-samples 100
|
| 530 |
-
```
|
| 531 |
|
| 532 |
-
#
|
| 533 |
-
|
| 534 |
-
End-to-end document intelligence using [baidu/Qianfan-OCR](https://huggingface.co/baidu/Qianfan-OCR) with 4.7B parameters:
|
| 535 |
-
|
| 536 |
-
- **93.12 on OmniDocBench v1.5** — #1 end-to-end model
|
| 537 |
-
- **79.8 on OlmOCR Bench** — #1 end-to-end model
|
| 538 |
-
- 🧠 **Layout-as-Thought** — Optional reasoning phase for complex layouts (`--think`)
|
| 539 |
-
- 🌍 **192 languages** — Latin, CJK, Arabic, Cyrillic, and more
|
| 540 |
-
- 📝 **OCR mode** — Document parsing to markdown (default)
|
| 541 |
-
- 📊 **Table mode** — HTML table extraction
|
| 542 |
-
- 📐 **Formula mode** — LaTeX recognition
|
| 543 |
-
- 📈 **Chart mode** — Chart understanding and analysis
|
| 544 |
-
- 🔍 **Scene mode** — Scene text extraction
|
| 545 |
-
- 🔑 **KIE mode** — Key information extraction with custom prompts
|
| 546 |
-
|
| 547 |
-
**Prompt Modes:**
|
| 548 |
-
|
| 549 |
-
- `ocr`: Document parsing to markdown (default)
|
| 550 |
-
- `table`: Table extraction to HTML
|
| 551 |
-
- `formula`: Formula recognition to LaTeX
|
| 552 |
-
- `chart`: Chart understanding
|
| 553 |
-
- `scene`: Scene text extraction
|
| 554 |
-
- `kie`: Key information extraction (requires `--custom-prompt`)
|
| 555 |
-
|
| 556 |
-
**Quick start:**
|
| 557 |
-
|
| 558 |
-
```bash
|
| 559 |
-
# Basic OCR
|
| 560 |
-
hf jobs uv run --flavor l4x1 \
|
| 561 |
-
-s HF_TOKEN \
|
| 562 |
-
https://huggingface.co/datasets/uv-scripts/ocr/raw/main/qianfan-ocr.py \
|
| 563 |
-
your-input-dataset your-output-dataset \
|
| 564 |
-
--max-samples 100
|
| 565 |
-
|
| 566 |
-
# Layout-as-Thought for complex documents
|
| 567 |
-
hf jobs uv run --flavor l4x1 \
|
| 568 |
-
-s HF_TOKEN \
|
| 569 |
-
https://huggingface.co/datasets/uv-scripts/ocr/raw/main/qianfan-ocr.py \
|
| 570 |
-
your-input-dataset your-output-dataset \
|
| 571 |
-
--think --max-samples 50
|
| 572 |
-
|
| 573 |
-
# Key information extraction
|
| 574 |
-
hf jobs uv run --flavor l4x1 \
|
| 575 |
-
-s HF_TOKEN \
|
| 576 |
https://huggingface.co/datasets/uv-scripts/ocr/raw/main/qianfan-ocr.py \
|
| 577 |
invoices extracted-fields \
|
| 578 |
--prompt-mode kie --custom-prompt "Extract: name, date, total. Output as JSON."
|
| 579 |
```
|
| 580 |
|
| 581 |
-
|
| 582 |
-
|
| 583 |
-
High-quality document OCR using [allenai/olmOCR-2-7B-1025-FP8](https://huggingface.co/allenai/olmOCR-2-7B-1025-FP8) optimized with GRPO reinforcement learning:
|
| 584 |
-
|
| 585 |
-
- 🎯 **High accuracy** - 82.4 ± 1.1 on olmOCR-Bench (84.9% on math)
|
| 586 |
-
- 📐 **LaTeX equations** - Mathematical formulas in LaTeX format
|
| 587 |
-
- 📊 **Table extraction** - Structured table recognition
|
| 588 |
-
- 📑 **Multi-column layouts** - Complex document structures
|
| 589 |
-
- 🗜️ **FP8 quantized** - Efficient 8B model for faster inference
|
| 590 |
-
- 📜 **Degraded scans** - Works well on old/historical documents
|
| 591 |
-
- 📝 **Long text extraction** - Headers, footers, and full document content
|
| 592 |
-
- 🧩 **YAML metadata** - Structured front matter (language, rotation, content type)
|
| 593 |
-
- 🚀 **Based on Qwen2.5-VL-7B** - Fine-tuned with reinforcement learning
|
| 594 |
-
|
| 595 |
-
## 🆕 New Features
|
| 596 |
-
|
| 597 |
-
### Multi-Model Comparison Support
|
| 598 |
-
|
| 599 |
-
All scripts now include `inference_info` tracking for comparing multiple OCR models:
|
| 600 |
-
|
| 601 |
-
```bash
|
| 602 |
-
# First model
|
| 603 |
-
uv run rolm-ocr.py my-dataset my-dataset --max-samples 100
|
| 604 |
-
|
| 605 |
-
# Second model (appends to same dataset)
|
| 606 |
-
uv run nanonets-ocr.py my-dataset my-dataset --max-samples 100
|
| 607 |
-
|
| 608 |
-
# View all models used
|
| 609 |
-
python -c "import json; from datasets import load_dataset; ds = load_dataset('my-dataset'); print(json.loads(ds[0]['inference_info']))"
|
| 610 |
-
```
|
| 611 |
-
|
| 612 |
-
### Random Sampling
|
| 613 |
-
|
| 614 |
-
Get representative samples with the new `--shuffle` flag:
|
| 615 |
-
|
| 616 |
-
```bash
|
| 617 |
-
# Random 50 samples instead of first 50
|
| 618 |
-
uv run rolm-ocr.py ordered-dataset output --max-samples 50 --shuffle
|
| 619 |
-
|
| 620 |
-
# Reproducible random sampling
|
| 621 |
-
uv run nanonets-ocr.py dataset output --max-samples 100 --shuffle --seed 42
|
| 622 |
-
```
|
| 623 |
-
|
| 624 |
-
### Automatic Dataset Cards
|
| 625 |
-
|
| 626 |
-
Every OCR run now generates comprehensive dataset documentation including:
|
| 627 |
-
|
| 628 |
-
- Model configuration and parameters
|
| 629 |
-
- Processing statistics
|
| 630 |
-
- Column descriptions
|
| 631 |
-
- Reproduction instructions
|
| 632 |
-
|
| 633 |
-
## 💻 Usage Examples
|
| 634 |
-
|
| 635 |
-
### Run on HuggingFace Jobs (Recommended)
|
| 636 |
-
|
| 637 |
-
No GPU? No problem! Run on HF infrastructure:
|
| 638 |
-
|
| 639 |
-
```bash
|
| 640 |
-
# PaddleOCR-VL - Smallest model (0.9B) with task modes
|
| 641 |
-
hf jobs uv run --flavor l4x1 \
|
| 642 |
-
--secrets HF_TOKEN \
|
| 643 |
-
https://huggingface.co/datasets/uv-scripts/ocr/raw/main/paddleocr-vl.py \
|
| 644 |
-
your-input-dataset your-output-dataset \
|
| 645 |
-
--task-mode ocr \
|
| 646 |
-
--max-samples 100
|
| 647 |
-
|
| 648 |
-
# PaddleOCR-VL - Extract tables from documents
|
| 649 |
-
hf jobs uv run --flavor l4x1 \
|
| 650 |
-
--secrets HF_TOKEN \
|
| 651 |
-
https://huggingface.co/datasets/uv-scripts/ocr/raw/main/paddleocr-vl.py \
|
| 652 |
-
documents tables-dataset \
|
| 653 |
-
--task-mode table
|
| 654 |
-
|
| 655 |
-
# PaddleOCR-VL - Formula recognition
|
| 656 |
-
hf jobs uv run --flavor l4x1 \
|
| 657 |
-
--secrets HF_TOKEN \
|
| 658 |
-
https://huggingface.co/datasets/uv-scripts/ocr/raw/main/paddleocr-vl.py \
|
| 659 |
-
scientific-papers formulas-extracted \
|
| 660 |
-
--task-mode formula \
|
| 661 |
-
--batch-size 32
|
| 662 |
-
|
| 663 |
-
# GLM-OCR - SOTA 0.9B model (94.62% OmniDocBench)
|
| 664 |
-
hf jobs uv run --flavor l4x1 \
|
| 665 |
-
-s HF_TOKEN \
|
| 666 |
-
https://huggingface.co/datasets/uv-scripts/ocr/raw/main/glm-ocr.py \
|
| 667 |
-
your-input-dataset your-output-dataset \
|
| 668 |
-
--batch-size 16 \
|
| 669 |
-
--max-samples 100
|
| 670 |
-
|
| 671 |
-
# DeepSeek-OCR - Real-world example (National Library of Scotland handbooks)
|
| 672 |
-
hf jobs uv run --flavor a100-large \
|
| 673 |
-
-s HF_TOKEN \
|
| 674 |
-
-e UV_TORCH_BACKEND=auto \
|
| 675 |
-
https://huggingface.co/datasets/uv-scripts/ocr/raw/main/deepseek-ocr-vllm.py \
|
| 676 |
-
NationalLibraryOfScotland/Britain-and-UK-Handbooks-Dataset \
|
| 677 |
-
davanstrien/handbooks-deep-ocr \
|
| 678 |
-
--max-samples 100 \
|
| 679 |
-
--shuffle \
|
| 680 |
-
--resolution-mode large
|
| 681 |
-
|
| 682 |
-
# DeepSeek-OCR - Fast testing with tiny mode
|
| 683 |
-
hf jobs uv run --flavor l4x1 \
|
| 684 |
-
-s HF_TOKEN \
|
| 685 |
-
-e UV_TORCH_BACKEND=auto \
|
| 686 |
-
https://huggingface.co/datasets/uv-scripts/ocr/raw/main/deepseek-ocr-vllm.py \
|
| 687 |
-
your-input-dataset your-output-dataset \
|
| 688 |
-
--max-samples 10 \
|
| 689 |
-
--resolution-mode tiny
|
| 690 |
-
|
| 691 |
-
# DeepSeek-OCR - Parse figures from scientific papers
|
| 692 |
-
hf jobs uv run --flavor a100-large \
|
| 693 |
-
-s HF_TOKEN \
|
| 694 |
-
-e UV_TORCH_BACKEND=auto \
|
| 695 |
-
https://huggingface.co/datasets/uv-scripts/ocr/raw/main/deepseek-ocr-vllm.py \
|
| 696 |
-
scientific-papers figures-extracted \
|
| 697 |
-
--prompt-mode figure
|
| 698 |
-
|
| 699 |
-
# Basic OCR job with Nanonets
|
| 700 |
-
hf jobs uv run --flavor l4x1 \
|
| 701 |
-
--secrets HF_TOKEN \
|
| 702 |
-
https://huggingface.co/datasets/uv-scripts/ocr/raw/main/nanonets-ocr.py \
|
| 703 |
-
your-input-dataset your-output-dataset
|
| 704 |
-
|
| 705 |
-
# DoTS.ocr - Multilingual OCR with compact 1.7B model
|
| 706 |
-
hf jobs uv run --flavor a100-large \
|
| 707 |
-
--secrets HF_TOKEN \
|
| 708 |
-
https://huggingface.co/datasets/uv-scripts/ocr/raw/main/dots-ocr.py \
|
| 709 |
-
davanstrien/ufo-ColPali \
|
| 710 |
-
your-username/ufo-ocr \
|
| 711 |
-
--batch-size 256 \
|
| 712 |
-
--max-samples 1000 \
|
| 713 |
-
--shuffle
|
| 714 |
-
|
| 715 |
-
# Real example with UFO dataset 🛸
|
| 716 |
-
hf jobs uv run \
|
| 717 |
-
--flavor a10g-large \
|
| 718 |
-
--secrets HF_TOKEN \
|
| 719 |
-
https://huggingface.co/datasets/uv-scripts/ocr/raw/main/nanonets-ocr.py \
|
| 720 |
-
davanstrien/ufo-ColPali \
|
| 721 |
-
your-username/ufo-ocr \
|
| 722 |
-
--image-column image \
|
| 723 |
-
--max-model-len 16384 \
|
| 724 |
-
--batch-size 128
|
| 725 |
-
|
| 726 |
-
# Nanonets OCR2 - Next-gen quality with 3B model
|
| 727 |
-
hf jobs uv run \
|
| 728 |
-
--flavor l4x1 \
|
| 729 |
-
--secrets HF_TOKEN \
|
| 730 |
-
https://huggingface.co/datasets/uv-scripts/ocr/raw/main/nanonets-ocr2.py \
|
| 731 |
-
your-input-dataset \
|
| 732 |
-
your-output-dataset \
|
| 733 |
-
--batch-size 16
|
| 734 |
-
|
| 735 |
-
# NuMarkdown with reasoning traces for complex documents
|
| 736 |
-
hf jobs uv run \
|
| 737 |
-
--flavor l4x4 \
|
| 738 |
-
--secrets HF_TOKEN \
|
| 739 |
-
https://huggingface.co/datasets/uv-scripts/ocr/raw/main/numarkdown-ocr.py \
|
| 740 |
-
your-input-dataset your-output-dataset \
|
| 741 |
-
--max-samples 50 \
|
| 742 |
-
--include-thinking \
|
| 743 |
-
--shuffle
|
| 744 |
-
|
| 745 |
-
# olmOCR2 - High-quality OCR with YAML metadata
|
| 746 |
-
hf jobs uv run \
|
| 747 |
-
--flavor a100-large \
|
| 748 |
-
--secrets HF_TOKEN \
|
| 749 |
-
https://huggingface.co/datasets/uv-scripts/ocr/raw/main/olmocr2-vllm.py \
|
| 750 |
-
your-input-dataset your-output-dataset \
|
| 751 |
-
--batch-size 16 \
|
| 752 |
-
--max-samples 100
|
| 753 |
-
|
| 754 |
-
# Private dataset with custom settings
|
| 755 |
-
hf jobs uv run --flavor l40sx1 \
|
| 756 |
-
--secrets HF_TOKEN \
|
| 757 |
-
https://huggingface.co/datasets/uv-scripts/ocr/raw/main/nanonets-ocr.py \
|
| 758 |
-
private-input private-output \
|
| 759 |
-
--private \
|
| 760 |
-
--batch-size 32
|
| 761 |
-
```
|
| 762 |
-
|
| 763 |
-
### Python API
|
| 764 |
|
| 765 |
```python
|
| 766 |
from huggingface_hub import run_uv_job
|
|
@@ -768,36 +201,17 @@ from huggingface_hub import run_uv_job
|
|
| 768 |
job = run_uv_job(
|
| 769 |
"https://huggingface.co/datasets/uv-scripts/ocr/raw/main/nanonets-ocr.py",
|
| 770 |
args=["input-dataset", "output-dataset", "--batch-size", "16"],
|
| 771 |
-
flavor="l4x1"
|
| 772 |
)
|
| 773 |
```
|
| 774 |
|
| 775 |
-
|
| 776 |
|
| 777 |
```bash
|
| 778 |
-
|
| 779 |
-
git clone https://huggingface.co/datasets/uv-scripts/ocr
|
| 780 |
-
cd ocr
|
| 781 |
-
uv run nanonets-ocr.py input-dataset output-dataset
|
| 782 |
-
|
| 783 |
-
# Or run directly from URL
|
| 784 |
-
uv run https://huggingface.co/datasets/uv-scripts/ocr/raw/main/nanonets-ocr.py \
|
| 785 |
input-dataset output-dataset
|
| 786 |
-
|
| 787 |
-
# PaddleOCR-VL for task-specific OCR (smallest model!)
|
| 788 |
-
uv run paddleocr-vl.py documents extracted --task-mode ocr
|
| 789 |
-
uv run paddleocr-vl.py papers tables --task-mode table # Extract tables
|
| 790 |
-
uv run paddleocr-vl.py textbooks formulas --task-mode formula # LaTeX formulas
|
| 791 |
-
|
| 792 |
-
# RolmOCR for fast text extraction
|
| 793 |
-
uv run rolm-ocr.py documents extracted-text
|
| 794 |
-
uv run rolm-ocr.py images texts --shuffle --max-samples 100 # Random sample
|
| 795 |
-
|
| 796 |
-
# Nanonets OCR2 for highest quality
|
| 797 |
-
uv run nanonets-ocr2.py documents ocr-results
|
| 798 |
-
|
| 799 |
```
|
| 800 |
|
| 801 |
-
|
| 802 |
|
| 803 |
-
Works with any
|
|
|
|
| 5 |
|
| 6 |
# OCR UV Scripts
|
| 7 |
|
| 8 |
+
> Part of [uv-scripts](https://huggingface.co/uv-scripts) — self-contained UV scripts you run on Hugging Face Jobs in one command.
|
| 9 |
|
| 10 |
+
A model zoo of OCR scripts — one per model — that add a `markdown` column to an image dataset. Pick a model from the table below, point it at your dataset, and run it on a GPU with one command. Two companions sit alongside: `pp-doclayout.py` detects layout regions (bboxes for text/title/table/figure/…) instead of text, and `ocr-vllm-judge.py` compares model outputs head-to-head.
|
| 11 |
|
| 12 |
+
## Quick Start
|
| 13 |
|
| 14 |
Run OCR on any dataset without needing your own GPU:
|
| 15 |
|
|
|
|
| 22 |
--max-samples 10
|
| 23 |
```
|
| 24 |
|
| 25 |
+
This will:
|
| 26 |
|
| 27 |
+
- Process the first 10 images from your dataset
|
| 28 |
- Add OCR results as a new `markdown` column
|
| 29 |
- Push the results to a new dataset
|
| 30 |
- View results at: `https://huggingface.co/datasets/[your-output-dataset]`
|
| 31 |
|
| 32 |
+
## Models at a glance
|
| 33 |
+
|
| 34 |
+
**Start here:** for a quick first run, try **`lighton-ocr2.py`** (1B, very fast) or **`paddleocr-vl-1.6.py`** (0.9B, current OmniDocBench SOTA); for the smallest footprint, **`falcon-ocr.py`** (0.3B, strong on tables). Reach for a 7–8B model only when quality demands it. Several of these models sit on the public [olmOCR-Bench](https://huggingface.co/datasets/allenai/olmOCR-bench) — pull the live ranking from your terminal in one command:
|
| 35 |
+
|
| 36 |
+
```bash
|
| 37 |
+
hf datasets leaderboard allenai/olmOCR-bench
|
| 38 |
+
```
|
| 39 |
+
|
| 40 |
+
But which model wins on *your* documents is still document-dependent — so [ocr-bench](https://github.com/davanstrien/ocr-bench) builds a **per-collection leaderboard** for your own data (pairwise VLM-as-judge, optionally human-validated), using these scripts under the hood.
|
| 41 |
+
|
| 42 |
+
_Sorted by model size:_
|
| 43 |
|
| 44 |
| Script | Model | Size | Backend | Notes |
|
| 45 |
|--------|-------|------|---------|-------|
|
|
|
|
| 48 |
| `glm-ocr.py` | [GLM-OCR](https://huggingface.co/zai-org/GLM-OCR) | 0.9B | vLLM | 94.62% OmniDocBench V1.5 |
|
| 49 |
| `paddleocr-vl.py` | [PaddleOCR-VL](https://huggingface.co/PaddlePaddle/PaddleOCR-VL) | 0.9B | Transformers | 4 task modes (ocr/table/formula/chart) |
|
| 50 |
| `paddleocr-vl-1.5.py` | [PaddleOCR-VL-1.5](https://huggingface.co/PaddlePaddle/PaddleOCR-VL-1.5) | 0.9B | Transformers | 94.5% OmniDocBench, 6 task modes |
|
| 51 |
+
| `paddleocr-vl-1.6.py` | [PaddleOCR-VL-1.6](https://huggingface.co/PaddlePaddle/PaddleOCR-VL-1.6) | 0.9B | vLLM | **96.33% OmniDocBench v1.6** (SOTA), drop-in upgrade of 1.5 |
|
| 52 |
| `lighton-ocr.py` | [LightOnOCR-1B](https://huggingface.co/lightonai/LightOnOCR-1B-1025) | 1B | vLLM | Fast, 3 vocab sizes |
|
| 53 |
| `lighton-ocr2.py` | [LightOnOCR-2-1B](https://huggingface.co/lightonai/LightOnOCR-2-1B) | 1B | vLLM | 7× faster than v1, RLVR trained |
|
| 54 |
| `hunyuan-ocr.py` | [HunyuanOCR](https://huggingface.co/tencent/HunyuanOCR) | 1B | vLLM | Lightweight VLM |
|
|
|
|
| 67 |
| `rolm-ocr.py` | [RolmOCR](https://huggingface.co/reducto/RolmOCR) | 7B | vLLM | Qwen2.5-VL based, general-purpose |
|
| 68 |
| `numarkdown-ocr.py` | [NuMarkdown-8B](https://huggingface.co/numind/NuMarkdown-8B-Thinking) | 8B | vLLM | Reasoning-based OCR |
|
| 69 |
|
| 70 |
+
**Variants & tools** (same models, different I/O): `glm-ocr-v2.py` adds checkpoint/resume for very large jobs · `glm-ocr-bucket.py` and `falcon-ocr-bucket.py` read images/PDFs from a mounted bucket and write one `.md` per page · `ocr-vllm-judge.py` runs pairwise OCR-quality comparisons.
|
| 71 |
|
| 72 |
## Layout detection (not OCR)
|
| 73 |
|
|
|
|
| 87 |
|
| 88 |
## Common Options
|
| 89 |
|
| 90 |
+
The scripts aim to expose a **consistent interface**: every OCR model script takes `input-dataset output-dataset` as positional arguments, accepts the shared core flags below, and writes a `markdown` column — so switching models is usually just swapping the script URL. Models differ where they need to, though: some add their own flags (task modes, resolution presets, `--think`, vocab sizes), a few need a specific Docker image, and per-model defaults (batch size, context length, temperature) are tuned to each model card. Always check a script's `--help` for its specifics.
|
| 91 |
|
| 92 |
| Option | Description |
|
| 93 |
|--------|-------------|
|
|
|
|
| 112 |
uv run glm-ocr.py --help
|
| 113 |
```
|
| 114 |
|
| 115 |
+
## NuExtract3: markdown OCR + structured extraction
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 116 |
|
| 117 |
[NuExtract3](https://huggingface.co/numind/NuExtract3) (4B, Apache-2.0) is the one script here that does both document-to-markdown OCR *and* schema-guided JSON extraction. Give it a template (or a JSON Schema / Pydantic model) and it returns JSON shaped to match.
|
| 118 |
|
|
|
|
| 139 |
--template '{"store": "verbatim-string", "date": "date", "total": "number"}'
|
| 140 |
```
|
| 141 |
|
| 142 |
+
**Templates** (`--template`) and **JSON Schemas** (`--schema`) each accept **inline JSON, a URL, or a file path**, so a schema can be hosted once and reused. Add `--enable-thinking` for harder layouts (slower; reasoning trace stored in a `<output-column>_reasoning` column). Template field names act as the model's extraction instructions, so name them descriptively — overly leading names can prompt over-generation, so verify against a few examples.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 143 |
|
| 144 |
+
## Model-specific modes & flags
|
| 145 |
|
| 146 |
+
Beyond the shared flags, some models add their own. Run `--help` on any script for the full list; the common ones:
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 147 |
|
| 148 |
+
| Script | Extra options |
|
| 149 |
+
|--------|---------------|
|
| 150 |
+
| `glm-ocr.py` | `--task ocr\|formula\|table` |
|
| 151 |
+
| `paddleocr-vl.py` | `--task-mode ocr\|table\|formula\|chart` |
|
| 152 |
+
| `paddleocr-vl-1.5.py` | `--task-mode ocr\|table\|formula\|chart\|spotting\|seal` |
|
| 153 |
+
| `paddleocr-vl-1.6.py` | `--task-mode ocr\|table\|formula` |
|
| 154 |
+
| `lighton-ocr.py` | `--vocab-size 151k\|32k\|16k` (smaller = faster on European languages) |
|
| 155 |
+
| `deepseek-ocr-vllm.py` | `--resolution-mode tiny\|small\|base\|large\|gundam`, `--prompt-mode document\|image\|free\|figure\|describe`; pass `-e UV_TORCH_BACKEND=auto` |
|
| 156 |
+
| `dots-ocr.py` | `--prompt-mode ocr\|layout-all\|layout-only` |
|
| 157 |
+
| `dots-mocr.py` | `--prompt-mode` (8: ocr, layout-all, layout-only, web-parsing, scene-spotting, grounding-ocr, svg, general); SVG: `--model rednote-hilab/dots.mocr-svg --prompt-mode svg` |
|
| 158 |
+
| `qianfan-ocr.py` | `--prompt-mode ocr\|table\|formula\|chart\|scene\|kie`, `--think` (Layout-as-Thought); `kie` needs `--custom-prompt` |
|
| 159 |
+
| `numarkdown-ocr.py` | `--include-thinking` (store the reasoning trace) |
|
| 160 |
+
| `nuextract3.py` | `--template` / `--schema` / `--enable-thinking` — see the NuExtract3 section above |
|
| 161 |
|
| 162 |
+
**Image-mode models** — `abot-ocr.py` and `nuextract3.py` (Qwen3.5 architecture) need the `vllm/vllm-openai` image because the default uv-script image lacks `nvcc`. Add `--image vllm/vllm-openai:latest --python /usr/bin/python3 -e PYTHONPATH=/usr/local/lib/python3.12/dist-packages` (see the NuExtract3 example above for the full command).
|
| 163 |
|
| 164 |
+
## Output & features
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 165 |
|
| 166 |
+
- **Markdown column** — each run adds an `--output-column` (default `markdown`) with the OCR result.
|
| 167 |
+
- **Multi-model comparison** — every script records `inference_info`, so you can run several models into the *same* dataset and compare. Point a second model at the same output repo:
|
| 168 |
+
```bash
|
| 169 |
+
uv run rolm-ocr.py my-dataset my-dataset --max-samples 100
|
| 170 |
+
uv run nanonets-ocr.py my-dataset my-dataset --max-samples 100 # appends
|
| 171 |
+
```
|
| 172 |
+
- **Reproducible sampling** — `--shuffle` (with `--seed`, default 42) draws a representative sample instead of the first N rows.
|
| 173 |
+
- **Automatic dataset cards** — every run writes a card with the model config, processing stats, column descriptions, and a reproduction command.
|
| 174 |
|
| 175 |
+
## More examples
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 176 |
|
| 177 |
```bash
|
| 178 |
+
# DeepSeek-OCR on historical scans, large resolution mode
|
| 179 |
+
hf jobs uv run --flavor a100-large -s HF_TOKEN -e UV_TORCH_BACKEND=auto \
|
| 180 |
+
https://huggingface.co/datasets/uv-scripts/ocr/raw/main/deepseek-ocr-vllm.py \
|
| 181 |
+
NationalLibraryOfScotland/Britain-and-UK-Handbooks-Dataset out \
|
| 182 |
+
--max-samples 100 --shuffle --resolution-mode large
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 183 |
|
| 184 |
+
# dots.mocr — SVG generation from charts/figures
|
| 185 |
+
hf jobs uv run --flavor l4x1 -s HF_TOKEN \
|
|
|
|
| 186 |
https://huggingface.co/datasets/uv-scripts/ocr/raw/main/dots-mocr.py \
|
| 187 |
+
your-charts svg-output --prompt-mode svg --model rednote-hilab/dots.mocr-svg
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 188 |
|
| 189 |
+
# Qianfan — key-information extraction
|
| 190 |
+
hf jobs uv run --flavor l4x1 -s HF_TOKEN \
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 191 |
https://huggingface.co/datasets/uv-scripts/ocr/raw/main/qianfan-ocr.py \
|
| 192 |
invoices extracted-fields \
|
| 193 |
--prompt-mode kie --custom-prompt "Extract: name, date, total. Output as JSON."
|
| 194 |
```
|
| 195 |
|
| 196 |
+
**Python API:**
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 197 |
|
| 198 |
```python
|
| 199 |
from huggingface_hub import run_uv_job
|
|
|
|
| 201 |
job = run_uv_job(
|
| 202 |
"https://huggingface.co/datasets/uv-scripts/ocr/raw/main/nanonets-ocr.py",
|
| 203 |
args=["input-dataset", "output-dataset", "--batch-size", "16"],
|
| 204 |
+
flavor="l4x1",
|
| 205 |
)
|
| 206 |
```
|
| 207 |
|
| 208 |
+
**Run locally** (needs your own GPU) — same scripts, run directly from the URL:
|
| 209 |
|
| 210 |
```bash
|
| 211 |
+
uv run https://huggingface.co/datasets/uv-scripts/ocr/raw/main/glm-ocr.py \
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 212 |
input-dataset output-dataset
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 213 |
```
|
| 214 |
|
| 215 |
+
---
|
| 216 |
|
| 217 |
+
Works with any Hugging Face dataset containing images — documents, forms, receipts, books, handwriting.
|