Views
No views yet

| Model | WER ↓ | CER ↓ | BLEU ↑ |
|---|---|---|---|
| Qari-OCR-0.2.2.1-VL-2B-Instruct | 0.221 | 0.059 | 0.597 |
| AIN 8B | 0.757 | 0.309 | 0.103 |
| Qari-OCR-0.1-VL-2B-Instruct | 1.294 | 0.770 | 0.022 |
| easyOCR | 1.004 | 0.648 | 0.005 |
| pytesseract | 0.990 | 0.911 | <0.001 |



transformers and qwen_vl_utils library:!pip install transformers qwen_vl_utils accelerate>=0.26.0 PEFT -U
!pip install -U bitsandbytes1from PIL import Image
2from transformers import Qwen2VLForConditionalGeneration, AutoProcessor
3import torch
4import os
5from qwen_vl_utils import process_vision_info
6
7model_name = "NAMAA-Space/Qari-OCR-0.2.2.1-Arabic-2B-Instruct"
8model = Qwen2VLForConditionalGeneration.from_pretrained(
9 model_name,
10 torch_dtype="auto",
11 device_map="auto"
12 )
13processor = AutoProcessor.from_pretrained(model_name)
14max_tokens = 2000
15
16prompt = "Below is the image of one page of a document, as well as some raw textual content that was previously extracted for it. Just return the plain text representation of this document as if you were reading it naturally. Do not hallucinate."
17image.save("image.png")
18
19messages = [
20 {
21 "role": "user",
22 "content": [
23 {"type": "image", "image": f"file://{src}"},
24 {"type": "text", "text": prompt},
25 ],
26 }
27]
28text = processor.apply_chat_template(
29 messages, tokenize=False, add_generation_prompt=True
30)
31image_inputs, video_inputs = process_vision_info(messages)
32inputs = processor(
33 text=[text],
34 images=image_inputs,
35 videos=video_inputs,
36 padding=True,
37 return_tensors="pt",
38)
39inputs = inputs.to("cuda")
40generated_ids = model.generate(**inputs, max_new_tokens=max_tokens)
41generated_ids_trimmed = [
42 out_ids[len(in_ids) :] for in_ids, out_ids in zip(inputs.input_ids, generated_ids)
43]
44output_text = processor.batch_decode(
45 generated_ids_trimmed, skip_special_tokens=True, clean_up_tokenization_spaces=False
46)[0]
47os.remove(src)
48print(output_text)@article{wasfy2025qari,
title={QARI-OCR: High-Fidelity Arabic Text Recognition through Multimodal Large Language Model Adaptation},
author={Wasfy, Ahmed and Nacar, Omer and Elkhateb, Abdelakreem and Reda, Mahmoud and Elshehy, Omar and Ammar, Adel and Boulila, Wadii},
journal={arXiv preprint arXiv:2506.02295},
year={2025}
}