Views
No views yet
| 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 |
1from transformers import Qwen2VLForConditionalGeneration, AutoProcessor
2from qwen_vl_utils import process_vision_info
3from PIL import Image
4
5# Load the model
6model = Qwen2VLForConditionalGeneration.from_pretrained(
7 "AbdoTarek/Baseer-OCR-V1.0",
8 torch_dtype="auto",
9 device_map="auto"
10).eval()
11
12processor = AutoProcessor.from_pretrained("AbdoTarek/Baseer-OCR-V1.0")
13
14# Prepare the image
15image_path = "path_to_your_arabic_document.jpg"
16image = Image.open(image_path)
17
18# Create the prompt
19prompt = """Extract ALL visible text from the document image.
20
21Return the result strictly as JSON with this structure:
22
23{
24 "subject": "",
25 "keywords": [],
26 "full_text": ""
27}
28
29Rules:
30- Do not repeat lines.
31- Preserve original order of text.
32- Do not add explanations."""
33
34# Prepare messages
35messages = [
36 {
37 "role": "system",
38 "content": [{"type": "text", "text": "You are a helpful assistant."}]
39 },
40 {
41 "role": "user",
42 "content": [
43 {"type": "image", "image": image},
44 {"type": "text", "text": prompt}
45 ]
46 }
47]
48
49# Process and generate
50text = processor.apply_chat_template(messages, add_generation_prompt=True, tokenize=False)
51image_inputs, _ = process_vision_info(messages)
52
53inputs = processor(
54 text=[text],
55 images=image_inputs,
56 padding=True,
57 return_tensors="pt"
58).to(model.device)
59
60with torch.inference_mode():
61 output_ids = model.generate(**inputs, max_new_tokens=1024)
62 output_text = processor.batch_decode(
63 output_ids[:, inputs.input_ids.shape[1]:],
64 skip_special_tokens=True
65 )[0]
66
67print(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 |
1# Input: Image of Arabic legal contract
2# Output: Structured JSON with subject, keywords, and full text1# Process multiple document images in a directory
2import os
3from glob import glob
4
5image_files = glob("documents/*.jpg")
6for img_path in image_files:
7 # Process each image...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.