Urdu Nastaliq OCR: Qwen3-VL-2B (v3), GGUF
Files
| File | Size | Purpose |
|---|---|---|
urdu-ocr-2b-v3-Q8_0.gguf | 1.83 GB | Recommended language model (8-bit) |
urdu-ocr-2b-v3-Q4_K_M.gguf | 1.11 GB | Smaller language model (4-bit) |
urdu-ocr-2b-v3-mmproj-f16.gguf | 0.82 GB | Vision projector, required by both |
lora-adapter/ | 0.20 GB | v3 LoRA adapter (r=32, alpha=64) for Qwen3-VL-2B-Instruct (continues from v1 and v2 rounds) |
Download:
hf download OmgItsAmmer/urdu-nastaliq-ocr-qwen3vl-2b-GGUF urdu-ocr-2b-v3-Q8_0.gguf urdu-ocr-2b-v3-mmproj-f16.gguf --local-dir .
What it does
You give it a photo or scan of Urdu text: a printed line, a page, or handwriting. It gives back the text in Urdu script. It runs entirely on a CPU, with no internet and no API key. The model is Qwen3-VL-2B fine-tuned with LoRA and shipped as GGUF for llama.cpp (Q8_0 1.8 GB, Q4_K_M 1.1 GB).
Why we built it
Urdu is read by about 230 million people and is mostly written in Nastaliq, where letters join and words slope down to the left. That breaks most OCR tools:
- Tesseract's Urdu model is far off on our handwriting and printed-line tests (see the table).
- Base Qwen3-VL-2B often doesn't stop: it loops until the token limit, so its error rate is over 100% on pages.
- The released Urdu OCR model we compared against (Qaari 0.1) fails on photos unlike its training fonts: it over-writes badly on typeset pages.
A small model taught this one task can beat all three and is cheap enough to run locally, which keeps private documents on the device.
How it was built: three rounds
| Round | Added | Examples | Time on 1x RTX 3090 | Peak VRAM (reserved) |
|---|---|---|---|---|
| v1 | synthetic Nastaliq lines (one font), news pages, tablet handwriting | 82,670 | 5.4 h | 18.0 GB |
| v2 | the same data re-rendered as photos: handwriting on ruled notebook paper, lines stacked into multi-line pages; continues from v1 | 22,366 | 2.6 h | 17.8 GB |
| v3 | a second typeface (Noto Nastaliq Urdu, OFL) as lines and pages; continues from v2 | 25,569 | 1.9 h | 11.4 GB |
Common setup: Qwen/Qwen3-VL-2B-Instruct, LoRA r=32 / alpha=64 on all linear layers (language model and
vision), bf16, batches packed by token budget, max length 2,560 tokens, transformers 5.24, PEFT 0.22,
torch 2.14. v3 final eval loss 0.127 (v2: 0.146). Configs are in configs/.
Two findings did most of the work:
- Letter size. Qwen-VL reads images in 32-pixel patches, and Nastaliq letters in small images are too small to see. On one 13-line typeset page CER went from 163% (a repeating loop) to about 12%, and on one notebook handwriting photo from 54% to 8% (single images, scored against our own transcriptions), just by enlarging the image until letters are about 48 px tall. We measure letter height from the connected ink blobs (ruled lines removed) and enlarge only when needed. No training involved.
- Broken letters teach guessing. About a third of the synthetic source lines are eroded, with missing letter pieces, while their labels list every letter. Training on them taught the model to guess common words for letters it could not see ("آسمان" became "آسان"). The page data in v2 and v3 keeps only solid-ink lines.
Output cleanup: repeated words (4+ times in a row) or characters (30+ times) are collapsed to one copy. It changes 0 of 651 reference texts, so it does not touch normal text.
Data and credits
All training data is openly licensed. Please credit the sources:
| Source | Licence | Used for |
|---|---|---|
| PuristanLabs1/urdu-ocr-1M (Nastaliq part) | MIT | synthetic lines; their texts also rendered by us in Noto Nastaliq Urdu |
| oddadmix Qaari 0.1 news | MIT | news pages |
| OUHD-L online Urdu handwriting, DOI 10.5281/zenodo.20642162 | CC BY 4.0 | tablet handwriting (311 writers, split by writer), re-rendered as notebook photos |
| Noto Nastaliq Urdu | SIL OFL 1.1 | second typeface |
| 1908 book sample | evaluation only | never trained on; tests old print |
Baselines: Qaari 0.1 (oddadmix/Qaari-0.1-Urdu-OCR-VL-2B-Instruct),
Tesseract 5 with urd. Base model Qwen3-VL (Apache 2.0). Tools: Hugging Face transformers and PEFT,
llama.cpp. Background reading that shaped our approach: Naz et al. 2017; Ul-Hasan et al. 2013; Sabbour and
Shafait 2013 (UPTI); Maqsood et al. (unified printed and handwritten Urdu OCR); Riaz et al. (Conv-Transformer).
Run it locally
llama-server -m urdu-ocr-2b-v3-Q8_0.gguf --mmproj urdu-ocr-2b-v3-mmproj-f16.gguf -c 8192 -ngl 0 --jinja
Send an image to /v1/chat/completions with the prompt: Read the Urdu text in this image and write
it out exactly, in Urdu script. Keep the original words and punctuation. Output only the text, nothing
else. with temperature 0 and repeat_penalty 1.05. For best results enlarge small images first so
letters are about 48 px tall (uocr.pages.prepare_for_reading in the code repo). The repo also has a web app that compares
models side by side: make demo.
Measured on CPU only (Intel i7-13700KF, 8 threads, no GPU, one request at a time):
| Q8_0 (1.8 GB) | Q4_K_M (1.1 GB) | |
|---|---|---|
| RAM, peak | 5.6 GB | 5.6 GB |
| One handwritten line | about 3.5 s | about 2.7 s |
| 1-5 printed lines | about 31 s | about 24 s |
| 13-line typeset page | about 53 s | about 65 s |
| CER on our real photos + test lines (19 items) | 2.8% | 3.5% |
Q8_0 gave the same error rate on CPU and GPU on our real-photo check (3.8%). We have not tested laptops or phones. Older laptop CPUs will be slower; treat anything beyond this desktop as an estimate.
Results
Character error rate (CER) and word error rate (WER), in percent, lower is better. These are the 362 test items that every system was run on, so the comparison is like for like:
| Test set (items) | Tesseract | Base Qwen3-VL-2B | Qaari 0.1 | Qaari + our data | Ours v1 | Ours v3 |
|---|---|---|---|---|---|---|
| Handwriting, unseen writers (200) | 61.4 / 96.7 | 41.5 / 77.1 | 241.3 / 282.1 | 10.4 / 31.8 | 8.7 / 27.3 | 9.2 / 27.7 |
| News pages (87) | 11.1 / 17.1 | 86.2 / 96.5 | 6.9 / 8.9 * | 21.0 / 35.8 | 5.7 / 6.4 | 5.7 / 6.5 |
| Printed lines, synthetic (24) | 59.7 / 90.4 | 45.8 / 79.0 | 71.2 / 107.7 | 5.2 / 22.1 | 2.8 / 20.6 | 3.1 / 18.8 |
| 1908 book, never trained on (51) | 67.1 / 100.9 | 85.7 / 114.1 | 194.7 / 217.1 | 43.8 / 80.7 | 80.1 / 111.0 | 34.1 / 73.2 |
| All 362 | 18.7 / 29.4 | 82.8 / 96.3 | 36.0 / 43.7 | 21.7 / 38.6 | 11.0 / 15.6 | 7.9 / 13.0 |
* Qaari was trained on this news dataset, so that score is not a held-out result.
Caveats on this table: the printed-line row has only 24 items. Our v1 and v3 runs used the letter-size enlargement described above; the baseline runs did not (the table is not a claim that baselines cannot be improved the same way). All systems have the repetition cleanup applied. v3's extra training did not improve handwriting (9.2 vs 8.7) but helped books and printed pages.
Other v3 results on its own larger test sets (CER / WER): Noto-font pages 1.9 / 9.9, stacked printed pages 6.9 / 23.1, notebook-photo handwriting 11.5 / 32.1. These test sets come from the same generator as the training data, so they are optimistic.
Real photos: the honest test
Three real images, none ever trained on (a printed Nastaliq couplet, a typeset page, a notebook handwriting photo), read through the same app with the same preprocessing. CER / WER:
| Image | Ours v3 | Ours v1 | Qaari 0.1 | Qaari + our data |
|---|---|---|---|---|
| Notebook handwriting | 11.1 / 35.7 | 27.0 / 64.3 | 74.6 / 100.0 | 20.6 / 35.7 |
| Typeset page | 3.7 / 16.3 | 5.5 / 22.0 | 238.6 / 246.9 | 29.6 / 47.4 |
| Printed couplet | 3.2 / 18.8 | 4.8 / 18.8 | 31.7 / 75.0 | 9.5 / 31.2 |
| All three | 4.1 / 17.6 | 6.7 / 24.3 | 217.9 / 226.8 | 28.0 / 45.6 |
Three images show a direction, not a guarantee.
Examples (v3, Q8_0, CPU)
| Image | True text | v3 output | Base Qwen3-VL-2B |
|---|---|---|---|
| held-out printed line | نجیب رزاق نے انگلستان کے اعلیٰ کالجوں سے تعلیم حاصل کی۔ | exactly right | تیمیر مسلکِ کے اصل کا بچنے تیزاق نے الگہاتان کے |
| held-out printed line | مرحلہ 7: باقی تمام فلٹر بیگ کے ساتھ 3-6 قدم دہرائیں۔ | مرحلہ7: باقی تمام فلسطر بیگ کے ساتھ 3-6 قدم دہرائیں۔ | مَرْحُلَة 7: باقی تَمَام فَلْسِرِیِ کَے 3-6 تَمَر دِو رَائِتِنَدِي |
| real photo, couplet | کیا تنگ ہم ستم زدگاں کا جہان ہے | کیا تنگ ہم ستم زد گاں کا جان ہے | |
| real photo, notebook | اور ہو سکتا ہو تمہارا یقین تمہیں معجزوں … جب یقین اللہ | اور ہوسکتا ہو تمہارا یقین تمہیں مجھروں … جیہ یقین اللّہ |
Where it still fails
- About 1 word in 5 is still wrong on real photos (WER 18-36% on our three), mostly single-letter slips: جہان read as جان, معجزوں as مجھروں. When letters are unclear the model falls back on a common word, which can change the meaning.
- Dense old print. On the 1908 dictionary pages CER is still 34% and WER 73%; the model loops on numbered entries.
- Handwriting beyond neat samples is not solved. We have only three real images and no labelled phone-photo test set of useful size.
- Dense pages are slow on CPU (30-60 s), and we have not tested older laptops or phones.
- Test sets from our own generator flatter us. Treat the real-photo table as the guide.
Code
Training, evaluation and demo code: https://github.com/OmgItsAmmer/finetune-anywhere/tree/showcase/urdu-nastaliq-ocr/showcase/qwen-local-hackathon-2026/urdu-nastaliq-ocr
Built for the Qwen Local Hackathon 2026. Author: OmgItsAmmer.
Best accuracy: v4-NC (non-commercial)
A fourth training round adds real scanned book lines (UTRSet-Real, CC BY-NC-SA 4.0): 92.18% accuracy on 2,096 real book lines, handwriting CER 8.2%. Research and non-commercial use only: OmgItsAmmer/urdu-nastaliq-ocr-qwen3vl-2b-v4nc-GGUF. This v3 model is the openly licensed release.
Hackathon entry (PR): https://github.com/junaiddshaukat/finetune-anywhere/pull/14