Sanskrit OCR: the free model that reads it best
92.2%
of letters, with Tesseract's Devanagari model
Tesseract's Sanskrit model came last
We ran Tesseract 5.5.4 on 30 proofread pages from 10 printed books on sa.wikisource.
| Model | Letters | Words |
|---|---|---|
| script/Devanagari best | 92.2% | 63.0% |
| script/Devanagari | 89.9% | 59.5% |
| Our Actor's code, Hindi | 89.1% | 51.4% |
| hin | 88.6% | 48.9% |
| san+hin | 88.5% | 56.4% |
| san | 85.8% | 49.4% |
| san best | 85.7% | 49.1% |
Of the Tesseract models, script/Devanagari best came first on all 10 books. It is also the slowest: 3.9 s a page, against 1.7 s for san.
Letters are proofread letters found in order. Sanskrit joins words, so our pages average 8 letters a word, and one wrong letter spoils the word.
The command: one model file
curl -LO https://raw.githubusercontent.com/tesseract-ocr/tessdata_best/4.1.0/script/Devanagari.traineddata
mkdir -p tessdata && mv Devanagari.traineddata tessdata/
tesseract page.png page --tessdata-dir tessdata -l Devanagari
It writes page.txt. The model is one of Tesseract's script models, made for a writing system, not one language.
Homebrew's brew install tesseract-lang has the fast
version. Use -l script/Devanagari (89.9% here).
A scanned PDF: OCRmyPDF
cp -r "$(brew --prefix)/share/tessdata/configs" tessdata/
TESSDATA_PREFIX=$PWD/tessdata ocrmypdf -l Devanagari --jobs 2 \
--sidecar book.txt scan.pdf book.pdf
On a 30-page PDF of the same scans it found 92.5% of letters in 75 s. It wrote book.txt and a searchable PDF/A.
Skip the first line and OCRmyPDF stops with
TesseractConfigError. Tesseract looks for its
configs/hocr file next to the model.
Gemma 4 read fewer letters
We ran Gemma 4 12b in Ollama on one test page from each book, thinking off. It took 140 s for the 10 pages.
| Model | Letters | Words |
|---|---|---|
| script/Devanagari best | 91.6% | 61.7% |
| san | 85.8% | 49.9% |
| Gemma 4 12b | 84.5% | 51.4% |
Gemma's output changes from run to run: this time one of the 10 replies ran to the 4,096-token limit.
| Printed | प्रहारप्रोषितप्राणसुभटस्थपुटक्षिति |
| script/Devanagari best | प्रहारमोषितमाणसुभटस्थपुटक्षिति |
| san | प्रहारमोषितमराणदभरखधुरक्षिति |
| Gemma 4 12b | प्रहारेयोमित्प्राणमुतस्यपुतश्चिति |
Four things that tripped us
- English on the page: san and hin have no Latin letters. On a book with English notes they wrote none of its 2,385 Latin letters. script/Devanagari best wrote 2,271.
-
Two flags for the word list changed nothing for san best.
-c load_system_dawg=0 -c load_freq_dawg=0gave the same text, byte for byte, on all 30 pages. They did nothing in our dictionary test either. -
Every Tesseract model put an invisible U+200C after a virama: 272
times for the best one. The proofread text has none. Remove them
with
perl -CSD -pi -e 's/\x{200C}//g' page.txt. - Apple Vision on macOS 26.6 lists 30 languages. None is written in Devanagari.
How we ran it
- Pages marked proofread or validated on sa.wikisource, from a seeded shuffle of books, 3 a book. Pages with footnotes, tables or running heads in the text were left out. Verse was kept.
- 15 pages came from PDFs, 15 from DjVu files. 12 of the DjVu pages are only 1,500 px tall.
- Models from tessdata_fast and tessdata_best at tag 4.1.0. The tessdata repo's san has the same network as tessdata_fast's, so we left it out.
- One thread a page, 2 pages at a time, at low priority, while other jobs ran. Times are rough.
- Our Actor's code is build 0.1.66 with its Hindi setting and its other defaults.
- Gemma 4 12b ran in Ollama 0.40.16 on the Mac GPU, temperature 0, with the prompt from our Gemma 4 page. The 140 s includes the model load.
- OCRmyPDF 17.13.0. The PDF holds the 30 scans as JPEGs, one a page.
- Licenses: Tesseract, tessdata and Gemma 4 are Apache-2.0, OCRmyPDF is MPL-2.0. Scan files: 8 public domain, 1 CC BY 3.0, 1 with no tag. We show no page images.
Scanned pages to text, no install
Run it yourself. Our Apify Actor turns a scanned PDF into Markdown or text. $0.006 a scanned page. It has Hindi, not Sanskrit.
Or send us the scan. Tack, our AI, does the job for $29, up to 50 pages. First page free.
Questions people ask
Does Tesseract support Sanskrit?
Yes, with the san model. On our 30 pages, Tesseract's Devanagari script model read more: 92.2% of letters against 85.8%.
Is there a free Sanskrit OCR?
Tesseract and its models are free (Apache-2.0) and run offline. OCRmyPDF (MPL-2.0) adds a text layer to a scanned PDF.
Can I OCR a Sanskrit PDF?
Yes. OCRmyPDF with -l Devanagari found 92.5% of letters on our 30-page PDF and wrote a searchable PDF/A.
Is an AI model better at Sanskrit?
Not the one we tried. Gemma 4 12b found 84.5% of letters on 10 pages. Tesseract's Devanagari model found 91.6% on the same pages.
Why are so many words wrong?
Sanskrit joins words, so our pages average 8 letters a word. One wrong letter spoils the whole word.