YAML Metadata Warning:The pipeline tag "text2text-generation" is not in the official list: text-classification, token-classification, table-question-answering, question-answering, zero-shot-classification, translation, summarization, feature-extraction, text-generation, fill-mask, sentence-similarity, text-to-speech, text-to-audio, automatic-speech-recognition, audio-to-audio, audio-classification, audio-text-to-text, voice-activity-detection, depth-estimation, image-classification, object-detection, image-segmentation, text-to-image, image-to-text, image-to-image, image-to-video, unconditional-image-generation, video-classification, reinforcement-learning, robotics, tabular-classification, tabular-regression, tabular-to-text, table-to-text, multiple-choice, text-ranking, text-retrieval, time-series-forecasting, text-to-video, image-text-to-text, image-text-to-image, image-text-to-video, visual-question-answering, document-question-answering, zero-shot-image-classification, graph-ml, mask-generation, zero-shot-object-detection, text-to-3d, image-to-3d, image-feature-extraction, video-text-to-text, keypoint-detection, visual-document-retrieval, any-to-any, video-to-video, other

ByT5-Sanskrit-OCR — Post-OCR Correction for Sanskrit/Devanagari

A byte-level ByT5-small fine-tuned to correct OCR'd Sanskrit/Devanagari text — dropped vowel signs, confused nasals (anusvara vs chandrabindu), split conjuncts, visually-similar consonants (व/ब, श/ष/स), and danda errors (॥ becoming a plain |). Trained on synthetic OCR noise from a linguistically-grounded Devanagari corruption engine. Built on a free Colab T4.

Why byte-level (ByT5)?

mT5's subword tokenizer fragments 89.9% of Sanskrit words and fragments more as the input degrades. ByT5 is byte-level: no Devanagari input can produce an <unk> and the decoder can emit any Unicode sequence — exactly what a corrector of broken glyphs needs. The cost is ~3× longer sequences, acceptable for short verses. (Full analysis in the repo.)

Usage

from transformers import AutoTokenizer, AutoModelForSeq2SeqLM
tok = AutoTokenizer.from_pretrained("tusharislampure29/byt5-sanskrit-ocr")
model = AutoModelForSeq2SeqLM.from_pretrained("tusharislampure29/byt5-sanskrit-ocr")

noisy = "कर्मण्येवाधिकारस्त मा फलषु कदाचन |"   # dropped matras + danda-as-pipe
ids = tok("correct: " + noisy, return_tensors="pt").input_ids
print(tok.decode(model.generate(ids, max_length=256, num_beams=4)[0], skip_special_tokens=True))

Results

Held-out test set (1,800 lines; split by clean line, zero overlap with training), before vs after:

Metric OCR output (before) ByT5-corrected (after) Δ
WER ↓ 0.556 0.240 −57%
Exact-match ↑ 0.000 0.252 +0.25
CER ↓ 0.084 0.065 −22%

A strong word-level corrector: it more than halves the word error rate and returns 25% of lines exactly correct. CER improves most on heavily-degraded input (0.122 → 0.074, −40%); on already-light noise it can over-correct at the character level (CER 0.047 → 0.057) while still cutting WER (0.363 → 0.192). Plus a per-error-family taxonomy eval (which error types it fixes best) — see the repo.

Training

ByT5-small, seq2seq, prefix correct:, max len 384, lr 3e-4, effective batch 16 (4 × grad-accum 4), 3 epochs, bf16 on T4 (fp16 is NaN-unstable for T5/ByT5), best-by-validation-CER checkpoint (val CER 0.033). Dataset: tusharislampure29/sanskrit-ocr-correction.

Limitations

Trained on synthetic OCR noise — strongest on the modelled error families; novel scanner artifacts are out-of-distribution. Coverage is classical Sanskrit (Ayurveda/Yoga/Gita/subhashitas). For production manuscript pipelines, pair with a human-review/abstain step.

License & citation

Apache 2.0. Built for the ImmverseAI AI/ML assignment and released openly. Author: Tushar Islampure (github.com/tusharislampure29).

Downloads last month
22
Safetensors
Model size
0.3B params
Tensor type
F32
·
Inference Providers NEW
This model isn't deployed by any Inference Provider. 🙋 Ask for provider support

Model tree for tusharislampure29/byt5-sanskrit-ocr

Finetuned
(343)
this model

Dataset used to train tusharislampure29/byt5-sanskrit-ocr