MIDF Sanskrit OCR: v0.4

The default pipeline pairs PP-OCRv6 Sanskrit line recognition with our Kraken BLLA v0.3 line segmenter. The segmenter was fine-tuned on reviewed curved toplines and improves line F1 from 92.7% to 95.8% on its 22-page development panel. PP-OCRv6 remains the best evaluated recognizer.

Use

With Python 3.12 and uv:

uvx --from huggingface-hub hf download tadad/midf-sanskrit-ocr --revision v0.4 --local-dir sanskrit-ocr
uv run sanskrit-ocr/ocr.py page.jpg -o page.txt --json-output page.json

The command runs locally on CPU by default. --device cuda or --device mps selects a supported accelerator. JSON includes detected boundaries, toplines, reading order, and recognized text so crops can be inspected. The runner applies EXIF orientation, passes the full image to Kraken, and uses each model's internal resizing. PP-OCRv6's saved input height is 96 pixels. No API key is needed after download. Runtime dependencies are pinned in ocr.py.

To reproduce the complete-pipeline evaluation against the dataset's reviewed, evaluation-only panel:

uv run sanskrit-ocr/evaluate_pipeline.py \
  /path/to/midf-egangotri-sanskrit/data/segmentation/evaluation/v0.1 \
  --output pipeline-evaluation

Complete pipeline comparison

Same nine reviewed development pages and 5,041 reference characters; NFC normalization with whitespace removed.

Input and model CER ↓ Character accuracy ↑
PP-OCRv6 with human line geometry 8.91% 91.09%
Gemini 3.1 Pro Preview, whole page 10.49% 89.51%
BLLA v0.3 + PP-OCRv6, whole page 14.98% 85.02%
Qwen3.5-0.8B fine-tune, whole page 20.71% 79.29%

Automatic segmentation and crop construction add 306 edits over the human-line PP-OCRv6 run. The complete pipeline detects the exact number of body lines on five of nine pages. One page, M00664-p0010, contributes 194 of the 306 added edits even though its detected line count is correct, showing that line count alone does not measure crop quality. Two pages improve slightly with automatic crops, so the 306-edit difference is a net pipeline penalty rather than a strict error attribution.

Complete-pipeline results and page predictions. The panel is small, manuscript styles overlap training, and two pages also occur in recognition validation. It is useful for development comparisons, not a claim of corpus-wide generalization.

Recognition comparison

Same nine reviewed development pages, 5,041 reference characters; NFC normalization with whitespace removed. Character accuracy means 1 minus corpus-micro CER.

Model CER ↓ Character accuracy ↑
PP-OCRv6, epoch 59 8.91% 91.09%
Gemini 3.1 Pro Preview 10.49% 89.51%
Qwen3.5-0.8B fine-tune 20.71% 79.29%

PP-OCRv6 makes 449 edits versus Gemini's 529 (15.1% fewer). In this table's PP-OCRv6 row, the recognizer receives human-reviewed line geometry; the VLMs receive whole pages. These are not scores for the automatic segmentation pipeline. The panel is small, manuscripts overlap training, and some pages also serve as validation. It supports recognition development, not a claim of corpus-wide superiority.

Evaluation details and predictions.

Training and selection

  • Fine-tuned Benjamin Kiessling's PP-OCRv6 small pretrain with Kraken 7.1.1, using 67 pages / 748 reviewed training lines and 21 pages / 232 validation lines from segmentation data v0.2, dataset revision f6f007ee4196d38bf62e26cd8186464aa8ced078.
  • Learning rate 0.0005, AdamW+Muon, cosine schedule, 200 warmup steps, batch 4, augmentation, NFC, no bidi reordering, maximum normalized width 4096.
  • Selected epoch 59 by validation. Training stopped at its 45-minute training budget; the successful job took about 47 minutes ($0.78 A10G compute).
  • The checkpoint-selection metric reported 5.70% CER. The separate saved-weight ketos test run reported 6.14% CER (791 / 12,889 characters); these runner results differ and are preserved separately, not treated as interchangeable.
  • This recognizer does not include the seven newer training pages from v0.3. Job and checkpoint provenance.

Limitations and next steps

Segmentation and crop construction are the main integration limitations. Margins, crossed-out writing, diagrams, water damage, slanted lines, and dense layouts need review. Body-text transcriptions do not consistently represent every visible mark. Recognition improvements do not fix missed text or incorrect crops.

Next: target pages where line counts look correct but crop geometry loses text, add reviewed examples from failing styles, and keep complete-page evaluation separate from recognition with reviewed segments.

Earlier models

Current segmentation details, earlier segmentation details, and Qwen training/decoding history remain available. The root Qwen adapter files, transcribe.py, and evaluation.json are retained for compatibility; ocr.py is the v0.4 default runner. Older release tags preserve the earlier models.

Attribution and terms

The PP-OCRv6 base weights are by Benjamin Kiessling / Inria and released under Apache-2.0; see upstream attribution and the included license. This fine-tune modifies those weights for Sanskrit recognition. Kraken supplies segmentation, recognition, and training software under its upstream terms. MIDF/eGangotri images and scholarly transcriptions retain the provenance and usage terms in the dataset card, which lists its license as other. This release grants no additional source-data rights and is not an official MIDF, Inria, PaddlePaddle, Google, or Qwen release.

Downloads last month

-

Downloads are not tracked for this model. How to track
Inference Providers NEW
This model isn't deployed by any Inference Provider. 🙋 Ask for provider support

Dataset used to train tadad/midf-sanskrit-ocr