Commit ·
0bc9b0a
1
Parent(s): 6c13a40
Update nanonets-ocr.py HF Jobs syntax and add smoke test notes
Browse files- Replace deprecated `hfjobs run` with current `hf jobs uv run` syntax
- Add OCR smoke test dataset design notes to CLAUDE.md
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Files changed (2)
- CLAUDE.md+88-20
- nanonets-ocr.py+16-15
8 unmodified lines910111212131414151617181920161718192021222324252223242526272829303132272829303137323334353 unmodified lines39404142434445464748495051525354555657585960616263646566676869707172737475767778798089 unmodified lines1701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092101422112122131458 unmodified lines- Tested and working on HF Jobs
### LightOnOCR-2-1B (`lighton-ocr2.py`)⚠️ **Temporarily Broken** (2026-01-29)✅ **Production Ready** (Fixed 2026-01-29)
**Status:** vLLM nightly regression - image processor loading fails**Status:** Working with vLLM nightly
**What happened:**- Script was working with vLLM nightly `v0.15.0rc2.dev73`- Nightly updated to `v0.15.0rc2.dev81` and broke- Error: `OSError: Can't load image processor for 'lightonai/LightOnOCR-2-1B'`- Both nightly and stable vLLM 0.14.x have this issue now**What was fixed:**- Root cause was NOT vLLM - it was the deprecated `HF_HUB_ENABLE_HF_TRANSFER=1` env var- The script was setting this env var but `hf_transfer` package no longer exists- This caused download failures that manifested as "Can't load image processor" errors- Fix: Removed the `HF_HUB_ENABLE_HF_TRANSFER=1` setting from the script
**Initial test results (before breakage):**- 8/10 samples had good OCR output- 2/10 samples showed repetition loops (likely due to max_tokens=6144)- Changed max_tokens default from 6144 → 4096 (per model card recommendation)**Test results (2026-01-29):**- 10/10 samples processed successfully- Clean markdown output with proper headers and paragraphs- Output dataset: `davanstrien/lighton-ocr2-test-v4`
**Fixes applied:**- `max_tokens`: 6144 → 4096 (model card recommends 4096 for arXiv papers)- Fixed pyarrow compatibility (>=17.0.0,<18.0.0)- Replaced deprecated `huggingface-hub[hf_transfer]` with `hf-xet`
**To verify when vLLM is fixed:****Example usage:**```bashhf jobs uv run --flavor a100-large \ -s HF_TOKEN \ https://huggingface.co/datasets/uv-scripts/ocr/raw/main/lighton-ocr2.py \ davanstrien/ufo-ColPali davanstrien/lighton-ocr2-test-v3 \ davanstrien/ufo-ColPali output-dataset \ --max-samples 10 --shuffle --seed 42```
3 unmodified lines- Training: RLVR (Reinforcement Learning with Verifiable Rewards)- Performance: 83.2% on OlmOCR-Bench, 42.8 pages/sec on H100
### PaddleOCR-VL-1.5 (`paddleocr-vl-1.5.py`)✅ **Production Ready** (Added 2026-01-30)
**Status:** Working with transformers
**Note:** Uses transformers backend (not vLLM) because PaddleOCR-VL only supports vLLM in server mode, which doesn't fit the single-command UV script pattern. Images are processed one at a time for stability.
**Test results (2026-01-30):**- 10/10 samples processed successfully- Processing time: ~50s per image on L4 GPU- Output dataset: `davanstrien/paddleocr-vl15-final-test`
**Example usage:**```bashhf jobs uv run --flavor l4x1 \ -s HF_TOKEN \ https://huggingface.co/datasets/uv-scripts/ocr/raw/main/paddleocr-vl-1.5.py \ davanstrien/ufo-ColPali output-dataset \ --max-samples 10 --shuffle --seed 42```
**Task modes:**- `ocr` (default): General text extraction to markdown- `table`: Table extraction to HTML format- `formula`: Mathematical formula recognition to LaTeX- `chart`: Chart and diagram analysis- `spotting`: Text spotting with localization (uses higher resolution)- `seal`: Seal and stamp recognition
**Model Info:**- Model: `PaddlePaddle/PaddleOCR-VL-1.5`- Size: 0.9B parameters (ultra-compact)- Performance: 94.5% SOTA on OmniDocBench v1.5- Backend: Transformers (single image processing)- Requires: `transformers>=5.0.0`
## Pending Development
### DeepSeek-OCR-2 (Visual Causal Flow Architecture)89 unmodified lines
---
## Future: OCR Smoke Test Dataset
**Status:** Idea (noted 2026-02-12)
Build a small curated dataset (`uv-scripts/ocr-smoke-test`?) with ~2-5 samples from diverse sources. Purpose: fast CI-style verification that scripts still work after dep updates, without downloading full datasets.
**Design goals:**- Tiny (~20-30 images total) so download is seconds not minutes- Covers the axes that break things: document type, image quality, language, layout complexity- Has ground truth text where possible for quality regression checks- All permissively licensed (CC0/CC-BY preferred)
**Candidate sources:**
| Source | What it covers | Why ||--------|---------------|-----|| `NationalLibraryOfScotland/medical-history-of-british-india` | Historical English, degraded scans | Has hand-corrected `text` column for comparison. CC0. Already tested with GLM-OCR. || `davanstrien/ufo-ColPali` | Mixed modern documents | Already used as our go-to test set. Varied layouts. || Something with **tables** | Structured data extraction | Tests `--task table` modes. Maybe a financial report or census page. || Something with **formulas/LaTeX** | Math notation | Tests `--task formula`. arXiv pages or textbook scans. || Something **multilingual** (CJK, Arabic, etc.) | Non-Latin scripts | GLM-OCR claims zh/ja/ko support. Good to verify. || Something **handwritten** | Handwriting recognition | Edge case that reveals model limits. |
**How it would work:**```bash# Quick smoke test for any scriptuv run glm-ocr.py uv-scripts/ocr-smoke-test smoke-out --max-samples 5# Or a dedicated test runner that checks all scripts against it```
**Open questions:**- Build as a proper HF dataset, or just a folder of images in the repo?- Should we include expected output for regression testing (fragile if models change)?- Could we add a `--smoke-test` flag to each script that auto-uses this dataset?- Worth adding to HF Jobs scheduled runs for ongoing monitoring?
---
**Last Updated:** 2026-01-29**Last Updated:** 2026-02-12**Watch PRs:**- DeepSeek-OCR-2: https://github.com/vllm-project/vllm/pull/33165- LightOnOCR-2 regression: Check https://github.com/vllm-project/vllm/issues?q=LightOnOCR102 unmodified lines103104105106106107108109108 unmodified lines21821922022122122222322474 unmodified lines2993003013023023033043053053063073087 unmodified lines3163173183193193203213225 unmodified lines3283293303313313323333343343353363371 unmodified line3393403413423423433443453463473473483493508 unmodified lines35936036136236236336436528 unmodified lines394395396397397398399400399400401401402403403404405406407102 unmodified lines) -> str: """Create a dataset card documenting the OCR process.""" model_name = model.split("/")[-1]
return f"""---viewer: falsetags:108 unmodified lines
# Check CUDA availability first check_cuda_availability()
# Track processing start time start_time = datetime.now()
74 unmodified lines # Add markdown column to dataset logger.info("Adding markdown column to dataset") dataset = dataset.add_column("markdown", all_markdown)
# Handle inference_info tracking logger.info("Updating inference_info...")
# Check for existing inference_info if "inference_info" in dataset.column_names: # Parse existing info from first row (all rows have same info)7 unmodified lines dataset = dataset.remove_columns(["inference_info"]) else: existing_info = []
# Add new inference info new_info = { "column_name": "markdown",5 unmodified lines "max_model_len": max_model_len, "script": "nanonets-ocr.py", "script_version": "1.0.0", "script_url": "https://huggingface.co/datasets/uv-scripts/ocr/raw/main/nanonets-ocr.py" "script_url": "https://huggingface.co/datasets/uv-scripts/ocr/raw/main/nanonets-ocr.py", } existing_info.append(new_info)
# Add updated inference_info column info_json = json.dumps(existing_info, ensure_ascii=False) dataset = dataset.add_column("inference_info", [info_json] * len(dataset))1 unmodified line # Push to hub logger.info(f"Pushing to {output_dataset}") dataset.push_to_hub(output_dataset, private=private, token=HF_TOKEN)
# Calculate processing time end_time = datetime.now() processing_duration = end_time - start_time processing_time = f"{processing_duration.total_seconds() / 60:.1f} minutes"
# Create and push dataset card logger.info("Creating dataset card...") card_content = create_dataset_card(8 unmodified lines image_column=image_column, split=split, )
card = DatasetCard(card_content) card.push_to_hub(output_dataset, token=HF_TOKEN) logger.info("✅ Dataset card created and pushed!")28 unmodified lines print("\n3. Process a subset for testing:") print(" uv run nanonets-ocr.py large-dataset test-output --max-samples 10") print("\n4. Random sample from ordered dataset:") print(" uv run nanonets-ocr.py ordered-dataset random-test --max-samples 50 --shuffle") print( " uv run nanonets-ocr.py ordered-dataset random-test --max-samples 50 --shuffle" ) print("\n5. Running on HF Jobs:") print(" hfjobs run \\") print(" --flavor l4x1 \\") print(" --secret HF_TOKEN=... \\") print(" hf jobs uv run --flavor l4x1 \\") print(" -s HF_TOKEN \\") print( " uv run https://huggingface.co/datasets/uv-scripts/ocr/raw/main/nanonets-ocr.py \\" " https://huggingface.co/datasets/uv-scripts/ocr/raw/main/nanonets-ocr.py \\" ) print(" your-document-dataset \\") print(" your-markdown-output")CLAUDE.md+88-20
nanonets-ocr.py+16-15