Commit ·
dafc1a9
1
Parent(s): 6786450
Rename dots-ocr-1.5 → dots-mocr (final release name)
Browse files- dots.mocr is the official final name for what was dots.ocr-1.5
- Model now on HF directly: rednote-hilab/dots.mocr (no ModelScope mirror needed)
- Added SVG prompt mode (--prompt-mode svg) with auto temperature/top_p
- SVG-optimized variant: rednote-hilab/dots.mocr-svg
- Updated README with new model entry and detailed docs
- Tested: OCR mode 3/3 on L4, SVG mode 3/3 on L4
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Files changed (2)
- README.md+42-3
- dots-ocr-1.5.py → dots-mocr.pyRenamed+85-59
6 unmodified lines789101011121329 unmodified lines4344454646474849342 unmodified lines3923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324333954344354364376 unmodified lines
> Part of [uv-scripts](https://huggingface.co/uv-scripts) - ready-to-run ML tools powered by UV and HuggingFace Jobs.
15 OCR models from 0.9B to 8B parameters. Pick a model, point at your dataset, get markdown — no setup required.19 OCR scripts covering models from 0.9B to 8B parameters. Pick a model, point at your dataset, get markdown — no setup required.
## 🚀 Quick Start
29 unmodified lines| `dots-ocr.py` | [DoTS.ocr](https://huggingface.co/Tencent/DoTS.ocr) | 1.7B | vLLM | 100+ languages || `firered-ocr.py` | [FireRed-OCR](https://huggingface.co/FireRedTeam/FireRed-OCR) | 2.1B | vLLM | Qwen3-VL fine-tune, Apache 2.0 || `nanonets-ocr.py` | [Nanonets-OCR-s](https://huggingface.co/nanonets/Nanonets-OCR-s) | 2B | vLLM | LaTeX, tables, forms || `dots-ocr-1.5.py` | [DoTS.ocr-1.5](https://huggingface.co/davanstrien/dots.ocr-1.5) | 3B | vLLM | 7 prompt modes, layout + bbox, 100+ languages || `dots-mocr.py` | [dots.mocr](https://huggingface.co/rednote-hilab/dots.mocr) | 3B | vLLM | 8 prompt modes incl. SVG generation, layout + bbox, 100+ languages || `nanonets-ocr2.py` | [Nanonets-OCR2-3B](https://huggingface.co/nanonets/Nanonets-OCR2-s) | 3B | vLLM | Next-gen, Qwen2.5-VL base || `deepseek-ocr-vllm.py` | [DeepSeek-OCR](https://huggingface.co/deepseek-ai/DeepSeek-OCR) | 4B | vLLM | 5 resolution + 5 prompt modes || `deepseek-ocr.py` | [DeepSeek-OCR](https://huggingface.co/deepseek-ai/DeepSeek-OCR) | 4B | Transformers | Same model, Transformers backend |342 unmodified lines- 🔍 **Multi-column Layouts** - Handles complex document structures- ✨ **Thinking Traces** - Optional inclusion of reasoning process with `--include-thinking`
### dots.mocr (`dots-mocr.py`) — SVG generation + SOTA OCR
Advanced multilingual OCR and SVG generation using [rednote-hilab/dots.mocr](https://huggingface.co/rednote-hilab/dots.mocr) with 3B parameters:
- 🌍 **100+ Languages** - Extensive multilingual support- 📝 **Document OCR** - Clean text extraction (default mode)- 📊 **Layout Analysis** - Structured output with bboxes and categories- 📐 **Formula recognition** - LaTeX format support- 🖼️ **SVG generation** - Convert charts, UI layouts, figures to editable SVG code- 🔀 **8 prompt modes** - OCR, layout-all, layout-only, web-parsing, scene-spotting, grounding-ocr, svg, general- 📄 **[Paper](https://arxiv.org/abs/2603.13032)** - 83.9% on olmOCR-Bench
**SVG variant:** Use `--model rednote-hilab/dots.mocr-svg` with `--prompt-mode svg` for best SVG results.
**Quick start:**
```bash# Basic OCRhf jobs uv run --flavor l4x1 \ -s HF_TOKEN \ https://huggingface.co/datasets/uv-scripts/ocr/raw/main/dots-mocr.py \ your-input-dataset your-output-dataset \ --max-samples 100
# SVG generation from charts/figureshf jobs uv run --flavor l4x1 \ -s HF_TOKEN \ https://huggingface.co/datasets/uv-scripts/ocr/raw/main/dots-mocr.py \ your-charts svg-output \ --prompt-mode svg --model rednote-hilab/dots.mocr-svg
# Layout analysis with bounding boxeshf jobs uv run --flavor l4x1 \ -s HF_TOKEN \ https://huggingface.co/datasets/uv-scripts/ocr/raw/main/dots-mocr.py \ your-documents layout-output \ --prompt-mode layout-all```
### DoTS.ocr (`dots-ocr.py`)### DoTS.ocr v1 (`dots-ocr.py`)
Compact multilingual OCR using [rednote-hilab/dots.ocr](https://huggingface.co/rednote-hilab/dots.ocr) with only 1.7B parameters:
12 unmodified lines1314151616171819201819202122232425262727282930313228293031323334353637383920 unmodified lines6061625960636465666722 unmodified lines909192899394959697989910010110226 unmodified lines12913013113213313413513613713813914031 unmodified lines1721731741621751761771782 unmodified lines18118218317118418518618716 unmodified lines20420520619420720820921021121221321421521621723 unmodified lines24124224323024424524623324724824925013 unmodified lines26426526625326726826927012 unmodified lines28328428527228628728828944 unmodified lines3343353363373383393403413423433443459 unmodified lines3553563573383583593603612 unmodified lines36436536634736736836937021 unmodified lines39239339437539539639739874 unmodified lines47347447545647647747847915 unmodified lines49549649747849849948050050150250350450550648748850750850951049049149249351151251351451549549651651751851952049950050150250352152252352452552652752850552953053153253351053453553653751453853954054151854254354452154554654754852552652752854955055155255355455553153255655755855956056153656256353853956456556654154256756856957054557157257354857457557657712 unmodified lines59059159256756859359459559659712 unmodified lines# ///
"""Convert document images to markdown using DoTS.ocr-1.5 with vLLM.Convert document images to markdown using dots.mocr with vLLM.
DoTS.ocr-1.5 is a 3B multilingual document parsing model with SOTA performanceon 100+ languages. Compared to v1 (1.7B), it adds web screen parsing, scene textspotting, SVG code generation, and stronger multilingual document parsing.dots.mocr is a 3B multilingual document parsing model with SOTA performanceon 100+ languages. It excels at converting structured graphics (charts, UIlayouts, scientific figures) directly into SVG code. Core capabilities includegrounding, recognition, semantic understanding, and interactive dialogue.
Features:- Multilingual support (100+ languages)- Table extraction and formatting- Formula recognition- Layout-aware text extraction- Web screen parsing (NEW in v1.5)- Scene text spotting (NEW in v1.5)- SVG code generation (requires dots.ocr-1.5-svg variant)
Model: rednote-hilab/dots.ocr-1.5vLLM: Officially supported (same DotsOCRForCausalLM architecture as v1)- Web screen parsing- Scene text spotting- SVG code generation (use --prompt-mode svg, or --model rednote-hilab/dots.mocr-svg for best results)
Model: rednote-hilab/dots.mocrSVG variant: rednote-hilab/dots.mocr-svgvLLM: Officially integrated since v0.11.0GitHub: https://github.com/rednote-hilab/dots.mocrPaper: https://arxiv.org/abs/2603.13032"""
import argparse20 unmodified lines
# ────────────────────────────────────────────────────────────────# DoTS OCR 1.5 Prompt Templates (from official dots.ocr repo)# Source: https://github.com/rednote-hilab/dots.ocr/blob/master/dots_ocr/utils/prompts.py# dots.mocr Prompt Templates# Source: https://github.com/rednote-hilab/dots.mocr/blob/master/dots_mocr/utils/prompts.py# ────────────────────────────────────────────────────────────────
PROMPT_TEMPLATES = {22 unmodified lines # resized_h, resized_w = smart_resize(orig_h, orig_w) # scale_x, scale_y = orig_w / resized_w, orig_h / resized_h "layout-only": """Please output the layout information from this PDF image, including each layout's bbox and its category. The bbox should be in the format [x1, y1, x2, y2]. The layout categories for the PDF document include ['Caption', 'Footnote', 'Formula', 'List-item', 'Page-footer', 'Page-header', 'Picture', 'Section-header', 'Table', 'Text', 'Title']. Do not output the corresponding text. The layout result should be in JSON format.""", # NEW in v1.5: "web-parsing": """Parsing the layout info of this webpage image with format json:\n""", "scene-spotting": """Detect and recognize the text in the image.""", "grounding-ocr": """Extract text from the given bounding box on the image (format: [x1, y1, x2, y2]).\nBounding Box:\n""", # SVG code generation — {width} and {height} are replaced with actual image dimensions. # For best results, use --model rednote-hilab/dots.mocr-svg # Uses higher temperature (0.9) and top_p (1.0) per official recommendation. "svg": """Please generate the SVG code based on the image. viewBox="0 0 {width} {height}" """, "general": """ """,}
26 unmodified lines # Convert to RGB pil_img = pil_img.convert("RGB")
# For SVG mode, inject actual image dimensions into the prompt if "{width}" in prompt and "{height}" in prompt: prompt = prompt.replace("{width}", str(pil_img.width)).replace( "{height}", str(pil_img.height) )
# Convert to base64 data URI buf = io.BytesIO() pil_img.save(buf, format="PNG")31 unmodified linestags:- ocr- document-processing- dots-ocr-1.5- dots-mocr- multilingual- markdown- uv-script2 unmodified lines
# Document OCR using {model_name}
This dataset contains OCR results from images in [{source_dataset}](https://huggingface.co/datasets/{source_dataset}) using DoTS.ocr-1.5, a 3B multilingual model with SOTA document parsing.This dataset contains OCR results from images in [{source_dataset}](https://huggingface.co/datasets/{source_dataset}) using dots.mocr, a 3B multilingual model with SOTA document parsing and SVG generation.
## Processing Details
16 unmodified lines
## Model Information
DoTS.ocr-1.5 is a 3B multilingual document parsing model that excels at:dots.mocr is a 3B multilingual document parsing model that excels at:- 100+ Languages — Multilingual document support- Table extraction — Structured data recognition- Formulas — Mathematical notation preservation- Layout-aware — Reading order and structure preservation- Web screen parsing — Webpage layout analysis- Scene text spotting — Text detection in natural scenes- SVG code generation — Charts, UI layouts, scientific figures to SVG
## Dataset Structure
23 unmodified lines
## Reproduction
This dataset was generated using the [uv-scripts/ocr](https://huggingface.co/datasets/uv-scripts/ocr) DoTS OCR 1.5 script:This dataset was generated using the [uv-scripts/ocr](https://huggingface.co/datasets/uv-scripts/ocr) dots.mocr script:
```bashuv run https://huggingface.co/datasets/uv-scripts/ocr/raw/main/dots-ocr-1.5.py \\uv run https://huggingface.co/datasets/uv-scripts/ocr/raw/main/dots-mocr.py \\ {source_dataset} \\ <output-dataset> \\ --image-column {image_column} \\13 unmodified lines output_dataset: str, image_column: str = "image", batch_size: int = 16, model: str = "rednote-hilab/dots.ocr-1.5", model: str = "rednote-hilab/dots.mocr", max_model_len: int = 24000, max_tokens: int = 24000, gpu_memory_utilization: float = 0.9,12 unmodified lines top_p: float = 0.9, verbose: bool = False,): """Process images from HF dataset through DoTS.ocr-1.5 model.""" """Process images from HF dataset through dots.mocr model."""
# Check CUDA availability first check_cuda_availability()44 unmodified lines gpu_memory_utilization=gpu_memory_utilization, )
# SVG mode uses higher temperature/top_p per official recommendation if prompt_mode == "svg" and temperature == 0.1 and top_p == 0.9: logger.info("SVG mode: using recommended temperature=0.9, top_p=1.0") temperature = 0.9 top_p = 1.0
sampling_params = SamplingParams( temperature=temperature, top_p=top_p,9 unmodified lines for batch_indices in tqdm( partition_all(batch_size, range(len(dataset))), total=(len(dataset) + batch_size - 1) // batch_size, desc="DoTS.ocr-1.5 processing", desc="dots.mocr processing", ): batch_indices = list(batch_indices) batch_images = [dataset[i][image_column] for i in batch_indices]2 unmodified lines # Create messages for batch batch_messages = [make_ocr_message(img, prompt) for img in batch_images]
# Process with vLLM (dots.ocr-1.5 needs "string" content format) # Process with vLLM (dots.mocr needs "string" content format) outputs = llm.chat( batch_messages, sampling_params,21 unmodified lines # Handle inference_info tracking (for multi-model comparisons) inference_entry = { "model_id": model, "model_name": "DoTS.ocr-1.5", "model_name": "dots.mocr", "column_name": output_column, "timestamp": datetime.now().isoformat(), "prompt_mode": prompt_mode if not custom_prompt else "custom",74 unmodified lines card = DatasetCard(card_content) card.push_to_hub(output_dataset, token=HF_TOKEN)
logger.info("DoTS.ocr-1.5 processing complete!") logger.info("dots.mocr processing complete!") logger.info( f"Dataset available at: https://huggingface.co/datasets/{output_dataset}" )15 unmodified lines # Show example usage if no arguments if len(sys.argv) == 1: print("=" * 80) print("DoTS.ocr-1.5 Document Processing") print("dots.mocr Document Processing") print("=" * 80) print("\n3B multilingual OCR model supporting 100+ languages") print("\n3B multilingual OCR model with SVG generation") print("\nFeatures:") print("- Multilingual support (100+ languages)") print("- Fast processing with vLLM") print("- Table extraction and formatting") print("- Formula recognition") print("- Layout-aware text extraction") print("- Web screen parsing (NEW in v1.5)") print("- Scene text spotting (NEW in v1.5)") print("- Web screen parsing") print("- Scene text spotting") print("- SVG code generation (charts, UI, figures)") print("\nPrompt modes:") print(" ocr - Text extraction (default)") print(" layout-all - Layout + bboxes + text (JSON)") print(" layout-only - Layout + bboxes only (JSON)") print(" web-parsing - Webpage layout analysis (JSON)") print(" ocr - Text extraction (default)") print(" layout-all - Layout + bboxes + text (JSON)") print(" layout-only - Layout + bboxes only (JSON)") print(" web-parsing - Webpage layout analysis (JSON)") print(" scene-spotting - Scene text detection") print(" grounding-ocr - Text from bounding box region") print(" general - Free-form (use with --custom-prompt)") print(" grounding-ocr - Text from bounding box region") print(" svg - SVG code generation") print(" general - Free-form (use with --custom-prompt)") print("\nExample usage:") print("\n1. Basic OCR:") print(" uv run dots-ocr-1.5.py input-dataset output-dataset") print("\n2. Web screen parsing:") print(" uv run dots-ocr-1.5.py screenshots parsed --prompt-mode web-parsing") print("\n3. Scene text spotting:") print(" uv run dots-ocr-1.5.py photos detected --prompt-mode scene-spotting") print(" uv run dots-mocr.py input-dataset output-dataset") print("\n2. SVG generation:") print( " uv run dots-mocr.py charts svg-output --prompt-mode svg --model rednote-hilab/dots.mocr-svg" ) print("\n3. Web screen parsing:") print(" uv run dots-mocr.py screenshots parsed --prompt-mode web-parsing") print("\n4. Layout analysis with structure:") print(" uv run dots-ocr-1.5.py papers analyzed --prompt-mode layout-all") print(" uv run dots-mocr.py papers analyzed --prompt-mode layout-all") print("\n5. Running on HF Jobs:") print(" hf jobs uv run --flavor l4x1 \\") print(" -s HF_TOKEN \\") print( " https://huggingface.co/datasets/uv-scripts/ocr/raw/main/dots-ocr-1.5.py \\" " https://huggingface.co/datasets/uv-scripts/ocr/raw/main/dots-mocr.py \\" ) print(" input-dataset output-dataset") print("\n" + "=" * 80) print("\nFor full help, run: uv run dots-ocr-1.5.py --help") print("\nFor full help, run: uv run dots-mocr.py --help") sys.exit(0)
parser = argparse.ArgumentParser( description="Document OCR using DoTS.ocr-1.5 (3B multilingual model)", description="Document OCR using dots.mocr (3B multilingual model with SVG generation)", formatter_class=argparse.RawDescriptionHelpFormatter, epilog="""Prompt Modes (official DoTS.ocr-1.5 prompts):Prompt Modes (official dots.mocr prompts): ocr - Simple text extraction (default) layout-all - Layout analysis with bboxes, categories, and text (JSON output) layout-only - Layout detection with bboxes and categories only (JSON output) web-parsing - Webpage layout analysis (JSON output) [NEW in v1.5] scene-spotting - Scene text detection and recognition [NEW in v1.5] grounding-ocr - Extract text from bounding box region [NEW in v1.5] general - Free-form QA (use with --custom-prompt) [NEW in v1.5] web-parsing - Webpage layout analysis (JSON output) scene-spotting - Scene text detection and recognition grounding-ocr - Extract text from bounding box region svg - SVG code generation (auto-injects image dimensions into viewBox) general - Free-form QA (use with --custom-prompt)
SVG Code Generation: For SVG output, use --model rednote-hilab/dots.ocr-1.5-svg with: --custom-prompt 'Please generate the SVG code based on the image.' Use --prompt-mode svg for SVG output. For best results, combine with --model rednote-hilab/dots.mocr-svg (the SVG-optimized variant). SVG mode automatically uses temperature=0.9, top_p=1.0 unless overridden.
Examples: # Basic text OCR (default) uv run dots-ocr-1.5.py my-docs analyzed-docs uv run dots-mocr.py my-docs analyzed-docs
# Web screen parsing uv run dots-ocr-1.5.py screenshots parsed --prompt-mode web-parsing # SVG generation with optimized variant uv run dots-mocr.py charts svg-out --prompt-mode svg --model rednote-hilab/dots.mocr-svg
# Scene text spotting uv run dots-ocr-1.5.py photos spotted --prompt-mode scene-spotting # Web screen parsing uv run dots-mocr.py screenshots parsed --prompt-mode web-parsing
# Full layout analysis with structure uv run dots-ocr-1.5.py papers structured --prompt-mode layout-all uv run dots-mocr.py papers structured --prompt-mode layout-all
# Random sampling for testing uv run dots-ocr-1.5.py large-dataset test --max-samples 50 --shuffle uv run dots-mocr.py large-dataset test --max-samples 50 --shuffle """, )
12 unmodified lines ) parser.add_argument( "--model", default="rednote-hilab/dots.ocr-1.5", help="Model to use (default: rednote-hilab/dots.ocr-1.5)", default="rednote-hilab/dots.mocr", help="Model to use (default: rednote-hilab/dots.mocr, or rednote-hilab/dots.mocr-svg for SVG)", ) parser.add_argument( "--max-model-len",README.md+42-3
dots-ocr-1.5.py → dots-mocr.pyRenamed+85-59