Arabic typewritten (machine-printed) text recognition. A LoRA adapter for
baidu/Unlimited-OCR that turns a typewritten Arabic
line image into Arabic Unicode text, and keeps the base model's document-parsing mode for full pages.
On 1,000 real typewritten lines from KITAB-Bench (500 PATS + 500 ISI-PPT) it reaches
9.66% CER / 26.18% WER: 48% fewer character errors than the best other model measured here
(Fanar-2-Oryx-IVU, 18.73% CER, zero-shot). Fine-tuning took the same base model from
33.63% → 9.66% CER (71% error reduction).
Read this before comparing: the benchmark lines (PATS, ISI-PPT) were never used for training. The typewritten training data was synthetic (Arabic text rendered in open-licence fonts), so this is an out-of-domain result for the adapter as well as for the zero-shot models. Every number was measured under one identical protocol (same images, greedy decoding, normalization); see Evaluation.
Source: Al-Omrani & Al-Suhaibani, التصكيك في الأسواق المالية الإسلامية: حالة صكوك الإجارة, SSRN 2276122.
| # | Model | Params | CER ↓ | WER ↓ | Exact ↑ | Lines ≤5% CER | Notes |
|---|---|---|---|---|---|---|---|
| 1 | Ours: Unlimited-OCR + LoRA (typewritten) | 3B MoE | 9.66% | 26.18% | 23.5% | 55.1% | this adapter |
| 2 | Fanar-2-Oryx-IVU (zero-shot) | 8.29B | 18.73% | 29.83% | 23.3% | 50.0% | general-purpose Arabic VLM |
| 3 | Unlimited-OCR (base, zero-shot) | 3B MoE | 33.63% | 48.65% | 12.7% | 36.9% | our base model, before fine-tuning |
CER = character error rate (verbatim: diacritics and punctuation count). Lower is better.
| Subset | Lines | CER (ours) | CER (Fanar-2-Oryx-IVU) | CER (Unlimited-OCR base) |
|---|---|---|---|---|
| PATS | 500 | 9.46% | 14.73% | 33.62% |
| ISI-PPT | 500 | 10.04% | 26.74% | 33.63% |
Corpus-level CER hides the shape of the errors, so here is the quality profile: what share of lines land under a given error threshold:
Quality profile of this model: median line CER 3.93%, with 55.1% of lines at ≤5% CER, 69.7% at ≤10%, and 23.5% transcribed exactly.
| Ground truth | Prediction | CER | |
|---|---|---|---|
| وقال أبو برزة كان النبي صلى الله عليه وسلم يستحب تأخيرها | وقال أبو برزة كان النبي صلى الله عليه وسلم يستحب تأخيرها | 0.0% | good |
| من أمر بحمل السلاح في يوم لا يحل فيه حمله يعني الحجاج | من أمر بحمل السلاح في يوم لا يحل فيه حمله يعني الحجاج | 0.0% | good |
| أفضل أدوات توفير الوقت في معالج النصوص "وورد". لسوء | فضل أدوات توفير الوقت في معالج النصوص "وررد". لسوء | 3.9% | typical (median) |
| يعرفها أهل الدنيا يطوف عليهم بها ولدان | ب ع ك ، ث خ ض ، ب س ش ، ص غ هـ أننا في الحج. | 92.1% | failure case |
import torch
from transformers import AutoModel, AutoTokenizer
from peft import PeftModel
BASE = "baidu/Unlimited-OCR"
ADAPTER = "IJyad/unlimited-ocr-arabic-typewritten"
tokenizer = AutoTokenizer.from_pretrained(BASE, trust_remote_code=True)
model = AutoModel.from_pretrained(BASE, trust_remote_code=True, use_safetensors=True,
torch_dtype=torch.bfloat16).cuda()
model = PeftModel.from_pretrained(model, ADAPTER).merge_and_unload().eval()
model.generation_config.max_new_tokens = 160
PROMPT = ("<image>Transcribe the printed Arabic text in this image exactly as written, "
"including any diacritics. Output only the transcription, nothing else.")
text = model.infer(tokenizer, prompt=PROMPT, image_file="line.png", output_path="out",
base_size=1024, image_size=640, crop_mode=True,
eval_mode=True, no_repeat_ngram_size=35, ngram_window=128)
print(text)
Input expectations: one single line of typewritten Arabic per image for transcription. For full
pages, use the base model's document-parsing prompt <image>document parsing.; the output is a list of
blocks <|det|>type [x1, y1, x2, y2]<|/det|>text with coordinates on a 0–999 grid.
Output: Arabic text in logical Unicode order (NFC).
Load the base model on the GPU before applying the adapter: merging this MoE adapter on CPU is very slow.
| Base model | baidu/Unlimited-OCR |
| Method | LoRA (bf16 base), r=16, α=32, dropout=0.05 |
| Adapted modules | attention + MLP projections of the language model (vision encoder and projector frozen) |
| Trainable params | 77.5M (LoRA only) |
| Data | 2,000 synthetic typewritten lines (Arabic Wikipedia sentences, 17 open-licence Arabic fonts) + KHATT v1.0 train+validation (3,878 handwritten lines after leakage filtering) |
| Schedule | 100 steps, effective batch 16, lr 0.0001, cosine, warmup 0.03 (checkpoint selected from a 1,104-step run) |
| Compute | single NVIDIA L40S (48 GB) |
Checkpoint selection: every checkpoint retained from the run was scored on the full benchmark (steps 100 / 700 / 1100 / 1104: 9.66% / 11.48% / 11.44% / 11.30% CER). Typewritten accuracy peaks early.
All models in the table were scored by the same script under one protocol:
ahmedheakl/arocrbench_patsocr and 500
from ahmedheakl/arocrbench_isippt (KITAB-Bench).max_new_tokens=160.The adapter is released under MIT, matching the base model
baidu/Unlimited-OCR (MIT). Using it requires downloading
that base model under its own license. Part of the training data is KHATT v1.0, distributed for
research; check the dataset's terms before commercial use and cite the KHATT authors in publications.
@misc{unlimited_ocr_arabic_typewritten,
title = {unlimited-ocr-arabic-typewritten: a LoRA adapter for typewritten Arabic text recognition},
author = {IJyad},
year = {2026},
url = {https://huggingface.co/IJyad/unlimited-ocr-arabic-typewritten}
}
Please also cite KITAB-Bench (Heakl et al., 2025), KHATT (Mahmoud et al., Pattern Recognition, 2014) and the base model Unlimited-OCR (Baidu, 2026).
baidu/Unlimited-OCR