Downloads · 30 days
292
27% of all-time downloads
AbdoTarek/Baseer-OCR-V1.0
Baseer-OCR-V1.0 is a image-to-text model from AbdoTarek. Use it when you need a caption or text from an image. The card lists the license as apache-2.0.
<p align="center" <img src="https://img.shields.io/badge/Python-3.10+-blue.svg" alt="Python" <img src="https://img.shields.io/badge/Transformers-5.3.0+-blue.svg" alt="Transformers" <img src="https://img.shields.io/bad…
Downloads · 30 days
292
27% of all-time downloads
All-time downloads
1.1K
Public
Parameters
2.2B
4.4 GB on disk
Likes
0
Public
Click a slice to open those files.
.safetensors4.4 GB · 100%
From the Hugging Face model README
Baseer OCR V1.0 is a fine-tuned version of Qwen/Qwen2-VL-2B-Instruct specifically designed for Optical Character Recognition (OCR) on complex Arabic legal documents.
| Attribute | Value |
|---|---|
| Base Model | Qwen2-VL-2B-Instruct |
| Fine-tuning Method | LoRA (Rank: 48) |
| Training Framework | LlamaFactory |
| Model Type | Vision-Language Model (VLM) |
| License | Apache 2.0 |
| Release Date | March 2025 |
Baseer OCR (بصير - meaning "reader" in Arabic) is specialized for extracting text from Arabic legal documents with complex layouts. This model builds upon Qwen2-VL's strong vision-language capabilities and is fine-tuned to handle:
from transformers import Qwen2VLForConditionalGeneration, AutoProcessor
from qwen_vl_utils import process_vision_info
from PIL import Image
# Load the model
model = Qwen2VLForConditionalGeneration.from_pretrained(
"AbdoTarek/Baseer-OCR-V1.0",
torch_dtype="auto",
device_map="auto"
).eval()
processor = AutoProcessor.from_pretrained("AbdoTarek/Baseer-OCR-V1.0")
# Prepare the image
image_path = "path_to_your_arabic_document.jpg"
image = Image.open(image_path)
# Create the prompt
prompt = """Extract ALL visible text from the document image.
Return the result strictly as JSON with this structure:
{
"subject": "",
"keywords": [],
"full_text": ""
}
Rules:
- Do not repeat lines.
- Preserve original order of text.
- Do not add explanations."""
# Prepare messages
messages = [
{
"role": "system",
"content": [{"type": "text", "text": "You are a helpful assistant."}]
},
{
"role": "user",
"content": [
{"type": "image", "image": image},
{"type": "text", "text": prompt}
]
}
]
# Process and generate
text = processor.apply_chat_template(messages, add_generation_prompt=True, tokenize=False)
image_inputs, _ = process_vision_info(messages)
inputs = processor(
text=[text],
images=image_inputs,
padding=True,
return_tensors="pt"
).to(model.device)
with torch.inference_mode():
output_ids = model.generate(**inputs, max_new_tokens=1024)
output_text = processor.batch_decode(
output_ids[:, inputs.input_ids.shape[1]:],
skip_special_tokens=True
)[0]
print(output_text)
| Parameter | Value |
|---|---|
| Stage | SFT (Supervised Fine-tuning) |
| Fine-tuning Type | LoRA |
| LoRA Rank | 48 |
| LoRA Dropout | 0.05 |
| LoRA Target | all |
| Learning Rate | 1e-4 |
| Epochs | 8 |
| Batch Size | 1 |
| Gradient Accumulation | 32 |
| Warmup Ratio | 0.1 |
| Scheduler | Cosine |
| Precision | BF16 |
# Input: Image of Arabic legal contract
# Output: Structured JSON with subject, keywords, and full text
# Process multiple document images in a directory
import os
from glob import glob
image_files = glob("documents/*.jpg")
for img_path in image_files:
# Process each image...
The model is optimized for Arabic legal document OCR and provides:
The model responds well to detailed prompts. Recommended prompt structure:
Extract ALL visible text from the document image.
Return the result strictly as JSON with this structure:
{
"subject": "",
"keywords": [],
"full_text": ""
}
Rules:
- Do not repeat lines.
- Preserve original order of text.
- Do not add explanations.
This model is released under the Apache 2.0 license.