Instructions to use context212/alhazen-ocr with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- PEFT
How to use context212/alhazen-ocr with PEFT:
from peft import PeftModel from transformers import AutoModelForCausalLM base_model = AutoModelForCausalLM.from_pretrained("unsloth/qwen3-vl-2b-instruct-unsloth-bnb-4bit") model = PeftModel.from_pretrained(base_model, "context212/alhazen-ocr") - Notebooks
- Google Colab
- Kaggle
- Local Apps Settings
- Unsloth Studio
How to use context212/alhazen-ocr with Unsloth Studio:
Install Unsloth Studio (macOS, Linux, WSL)
curl -fsSL https://unsloth.ai/install.sh | sh # Run unsloth studio unsloth studio -H 0.0.0.0 -p 8888 # Then open http://localhost:8888 in your browser # Search for context212/alhazen-ocr to start chatting
Install Unsloth Studio (Windows)
irm https://unsloth.ai/install.ps1 | iex # Run unsloth studio unsloth studio -H 0.0.0.0 -p 8888 # Then open http://localhost:8888 in your browser # Search for context212/alhazen-ocr to start chatting
Using HuggingFace Spaces for Unsloth
# No setup required # Open https://huggingface.co/spaces/unsloth/studio in your browser # Search for context212/alhazen-ocr to start chatting
Load model with FastModel
pip install unsloth from unsloth import FastModel model, tokenizer = FastModel.from_pretrained( model_name="context212/alhazen-ocr", max_seq_length=2048, )
File size: 2,861 Bytes
e9e6d3f 7b1ee7f d7fa0f3 7b1ee7f a7c8e71 7b1ee7f f7c27d5 7b1ee7f e9e6d3f 7b1ee7f d7fa0f3 7b1ee7f d7fa0f3 7b1ee7f d7fa0f3 7b1ee7f 110b461 7b1ee7f 110b461 d7fa0f3 7b1ee7f d7fa0f3 7b1ee7f d7fa0f3 7b1ee7f 110b461 d7fa0f3 110b461 d7fa0f3 7b1ee7f d7fa0f3 110b461 7b1ee7f 110b461 d7fa0f3 7b1ee7f d7fa0f3 7b1ee7f d7fa0f3 7b1ee7f d7fa0f3 7b1ee7f d7fa0f3 7b1ee7f d7fa0f3 7b1ee7f d7fa0f3 7b1ee7f d7fa0f3 7b1ee7f d7fa0f3 7b1ee7f d7fa0f3 7b1ee7f | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 | ---
base_model: unsloth/Qwen3-VL-2B-Instruct
library_name: peft
license: apache-2.0
pipeline_tag: image-text-to-text
tags:
- arabic
- ocr
- qwen3-vl
- lora
- unsloth
- document-ai
---
# Alhazen-OCR
QLoRA adapter on [`unsloth/Qwen3-VL-2B-Instruct`](https://huggingface.co/unsloth/Qwen3-VL-2B-Instruct) for Arabic institutional OCR: printed forms, invoices, and handwriting-heavy pages.
Named after Ibn al-Haytham (Alhazen), the 11th-century scholar who founded the science of optics.
- **Base:** Qwen3-VL-2B-Instruct (Apache-2.0)
- **Training data:** [`context212/context212-alhazen-ocr`](https://huggingface.co/datasets/context212/context212-alhazen-ocr) (khattmix rebuild)
- **Code:** [`github.com/context212/atlas-ocr`](https://github.com/context212/atlas-ocr)
- **Experiment sibling:** [`context212/alhazen-ocr-khattmix`](https://huggingface.co/context212/alhazen-ocr-khattmix)
## Results
CER / WER (lower is better), greedy decoding, **50 samples** each on the held-out eval split and on external [`ahmedheakl/arocrbench_khatt`](https://huggingface.co/datasets/ahmedheakl/arocrbench_khatt):
| Model | Eval CER ↓ | Eval WER ↓ | KHATT CER ↓ | KHATT WER ↓ |
|---|---:|---:|---:|---:|
| Qwen3-VL-2B-Instruct (base) | 0.792 | 0.947 | 1.893 | 1.801 |
| **Alhazen-OCR** | **0.328** | **0.504** | **0.841** | **1.193** |
Held-out character error: **0.79 → 0.33**. External KHATT handwriting: **1.89 → 0.84** CER.
This release (khattmix) adds line-level KHATT handwriting (~30% of the mix) on top of synthetic printed, invoices, and paragraph handwriting; KHATT-bench transcript overlap is removed from train.
## Training
- **Objective:** QLoRA SFT, one epoch
- **LR:** 2e-5 cosine, warmup 5%
- **Effective batch:** 16 (8 × grad accum 2) on A100 80GB
- **LoRA:** r=16, RSLoRA, vision + language layers
- **Mix:** ~30% loay synthetic / 15% invoices / 30% KHATT lines / 23% KHATT paragraphs / 2% historical (~18k train rows)
## Usage
Serve the base with the adapter attached (vLLM example):
```bash
vllm serve Qwen/Qwen3-VL-2B-Instruct \
--enable-lora \
--lora-modules alhazen=context212/alhazen-ocr \
--limit-mm-per-prompt '{"image": 1}' \
--mm-processor-cache-gb 0 \
--no-enable-prefix-caching
```
Prompt:
> Extract all the text from this image, preserving the original reading order.
Keep `temperature=0` for transcription.
## Limitations
- Tuned for Arabic institutional paperwork; not a general multilingual OCR.
- KHATT remains harder than printed forms — scores above 1.0 CER mean many lines are still wrong.
- Eval above is capped at 50 samples per split; treat as directional until a full-split rerun.
## Citation
```bibtex
@misc{alhazen-ocr-2026,
title = {Alhazen-OCR},
author = {Context212},
year = {2026},
howpublished = {\url{https://huggingface.co/context212/alhazen-ocr}}
}
```
|