mitra-sanskrit-ocr
A full fine-tune of datalab-to/surya-ocr-2 for printed Sanskrit. The fine-tuning targets Devanagari; romanized Sanskrit (IAST), English and Japanese are read as well as by the base model. Architecture, prompt and output format are unchanged (full-page HTML with layout blocks), so it is a drop-in replacement for Surya-OCR-2.
This is a derivative of Surya-OCR-2 and is distributed under the same modified AI Pubs OpenRAIL-M license
(see LICENSE), including its use-based restrictions (Attachment A). Changes made: all weights except the MTP head
were fine-tuned as described below; the MTP head is copied unchanged from the base model.
Training data
About 37,000 pages of printed Sanskrit editions (346 editions scanned on archive.org), labelled without manual transcription:
- Each page was read by base Surya-OCR-2 (the label skeleton, in Surya's own HTML format).
- A human-typed e-text of the same work, aligned to the page, corrects Surya's reading where an independent second OCR agrees with the e-text (three-way vote: Surya / second OCR / e-text).
- Spans where the sources disagree and no majority exists are masked out of the loss (about 4% of letters); editorial conventions of the e-text (nasal assimilation, avagraha, gemination conventions) never override the print.
Plus about 10,000 Japanese academic pages labelled by base Surya (replay), to keep CJK performance. One epoch, lr 1e-5 (vision tower 2e-6), effective batch 16.
Results
Character error rate (%) of base Surya-OCR-2 and this model, against reference transcriptions of the same pages:
| test set | base Surya-OCR-2 | this model |
|---|---|---|
| 60 pages from 3 held-out editions | 2.63 | 1.89 |
| IAST-heavy pages (7 pages, Latin-script CER) | 6.10 | 6.10 |
| English / Japanese pages | unchanged | unchanged |
Against an independent human-typed reference of a 1971 letterpress edition (24 pages, 7,824 phonemes; errors counted on the phoneme stream; edits made identically by every engine are attributed to the reference and set aside):
| engine | own errors | adjusted error % |
|---|---|---|
| mitra-sanskrit-ocr (this model) | 70 | 2.40 |
| Surya-OCR-2 (surya CLI) | 93 | 2.49 |
| Surya-OCR-2 (same vLLM pipeline as this model) | 82 | 2.56 |
| Google Cloud Vision (document text detection) | 116 | 3.23 |
| Chandra-OCR-2 | 169 | 3.92 |
Limitations
- Heavily degraded scans (broken type, very low resolution) remain hard: the model can drop lines it cannot read.
- It transcribes the print literally (misprints are kept), which is intended.
- Sideways (rotated) Devanagari is not improved.
Usage
Serve it like Surya-OCR-2, e.g. with vLLM, and point the surya-ocr client at it:
vllm serve buddhist-nlp/mitra-sanskrit-ocr --served-model-name datalab-to/surya-ocr-2 --trust-remote-code
SURYA_INFERENCE_BACKEND=vllm SURYA_INFERENCE_URL=http://localhost:8000/v1 surya_ocr page.png
Attribution
Base model: Surya-OCR-2 by Datalab (https://huggingface.co/datalab-to/surya-ocr-2). This fine-tune is not endorsed by Datalab. Commercial use is restricted as stated in the license; broader licences for the base model are available from Datalab.