Instructions to use tusharislampure29/byt5-sanskrit-ocr with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use tusharislampure29/byt5-sanskrit-ocr with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("text-generation", model="tusharislampure29/byt5-sanskrit-ocr")# pip install -U transformers accelerate # Load model directly from transformers import AutoTokenizer, AutoModelForSeq2SeqLM tokenizer = AutoTokenizer.from_pretrained("tusharislampure29/byt5-sanskrit-ocr") model = AutoModelForSeq2SeqLM.from_pretrained("tusharislampure29/byt5-sanskrit-ocr", device_map="auto") - Notebooks
- Google Colab
- Kaggle
- Local Apps Settings
- vLLM
How to use tusharislampure29/byt5-sanskrit-ocr with vLLM:
Install from pip and serve model
# Install vLLM from pip: pip install vllm # Start the vLLM server: vllm serve "tusharislampure29/byt5-sanskrit-ocr" # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:8000/v1/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "tusharislampure29/byt5-sanskrit-ocr", "prompt": "Once upon a time,", "max_tokens": 512, "temperature": 0.5 }'Use Docker
docker model run hf.co/tusharislampure29/byt5-sanskrit-ocr
- SGLang
How to use tusharislampure29/byt5-sanskrit-ocr with SGLang:
Install from pip and serve model
# Install SGLang from pip: pip install sglang # Start the SGLang server: python3 -m sglang.launch_server \ --model-path "tusharislampure29/byt5-sanskrit-ocr" \ --host 0.0.0.0 \ --port 30000 # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:30000/v1/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "tusharislampure29/byt5-sanskrit-ocr", "prompt": "Once upon a time,", "max_tokens": 512, "temperature": 0.5 }'Use Docker images
docker run --gpus all \ --shm-size 32g \ -p 30000:30000 \ -v ~/.cache/huggingface:/root/.cache/huggingface \ --env "HF_TOKEN=<secret>" \ --ipc=host \ lmsysorg/sglang:latest \ python3 -m sglang.launch_server \ --model-path "tusharislampure29/byt5-sanskrit-ocr" \ --host 0.0.0.0 \ --port 30000 # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:30000/v1/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "tusharislampure29/byt5-sanskrit-ocr", "prompt": "Once upon a time,", "max_tokens": 512, "temperature": 0.5 }' - Docker Model Runner
How to use tusharislampure29/byt5-sanskrit-ocr with Docker Model Runner:
docker model run hf.co/tusharislampure29/byt5-sanskrit-ocr
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.
- Input: noisy OCR Sanskrit, prefixed with
correct: - Output: corrected Devanagari Unicode
- Base:
google/byt5-small(Apache 2.0) - Code & report: https://github.com/tusharislampure29/sanskrit-ocr-correction
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
Model tree for tusharislampure29/byt5-sanskrit-ocr
Base model
google/byt5-small