ERNIE AI Developer Challenge Submission
Modellquelle
Quellenbeschreibung
ERNIE AI Developer Challenge Submission
A fine-tuned PaddleOCR-VL model specialized for medical document OCR, achieving high accuracy on medical prescriptions, lab reports, and forms while maintaining general OCR capabilities.
MedOCR-Vision is a vision-language model fine-tuned specifically for optical character recognition (OCR) of medical documents. The model is based on PaddleOCR-VL (1B parameters) and has been fine-tuned using LoRA (Low-Rank Adaptation) on a carefully curated dataset of 2,462 medical and general documents.
Quellen
1 QuelleVerifiziert 17. Sept.
Modellartefakte
1 ArtefaktQuellenauszüge
2 AuszügeOur fine-tuned model demonstrates significant improvements across multiple metrics:
The model was trained on naazimsnh02/medocr-vision-dataset, a curated dataset of 2,462 samples with the following composition:
| Dataset | Samples | Domain | Type |
|---|---|---|---|
| Medical Prescriptions | 1,000 | Medical | Handwritten |
| OMR Scanned Documents | 36 | Medical | Scanned Forms |
| Medical Lab Reports | 426 | Medical | Printed Reports |
| Invoices & Receipts | 1,000 | General | Business Docs |
| Total | 2,462 | - | - |
# Training Duration
num_train_epochs: 3
total_steps: 741
# Batch Configuration
per_device_train_batch_size: 4
gradient_accumulation_steps: 2
effective_batch_size: 8
# Learning Rate
learning_rate: 5e-5
warmup_steps: 50
lr_scheduler_type: linear
# Optimization
optimizer: adamw_8bit
weight_decay: 0.001
# LoRA Configuration
lora_r: 64
lora_alpha: 64
lora_dropout: 0
# Checkpointing
save_steps: 100
eval_steps: 100
save_total_limit: 5
load_best_model_at_end: true
| Step | Training Loss | Validation Loss |
|---|---|---|
| 100 | 1.7026 | 0.7900 |
| 200 | 1.3005 | 0.6821 |
| 300 | 1.0004 | 0.6402 |
| 400 | 0.8176 | 0.6036 |
| 500 | 0.7387 | 0.5806 |
| 600 | 0.7406 | 0.5819 |
| 700 | 0.8801 | 0.5787 |
Final Metrics:
pip install transformers unsloth einops torch pillow
from unsloth import FastVisionModel
from transformers import AutoProcessor
from PIL import Image
# Load model and processor
model, tokenizer = FastVisionModel.from_pretrained(
"naazimsnh02/medocr-vision"
)
processor = AutoProcessor.from_pretrained(
"naazimsnh02/medocr-vision",
trust_remote_code=True
)
# Enable inference mode
FastVisionModel.for_inference(model)
# Load image
image = Image.open("medical_document.jpg")
# Prepare input
instruction = "Extract all text from this medical document:"
messages = [{
"role": "user",
"content": [
{"type": "image"},
{"type": "text", "text": instruction}
]
}]
# Generate
text_prompt = processor.tokenizer.apply_chat_template(
messages,
tokenize=False,
add_generation_prompt=True
)
inputs = processor(
image,
text_prompt,
add_special_tokens=False,
return_tensors="pt",
).to("cuda")
output = model.generate(
**inputs,
max_new_tokens=256,
use_cache=False,
temperature=1.5,
min_p=0.1
)
# Decode output
text = tokenizer.decode(output[0], skip_special_tokens=True)
print(text)
from transformers import TextStreamer
# Create text streamer
text_streamer = TextStreamer(tokenizer, skip_prompt=True)
# Generate with streaming
_ = model.generate(
**inputs,
streamer=text_streamer,
max_new_tokens=256,
use_cache=False,
temperature=1.5,
min_p=0.1
)
@misc{medocr-vision-2025,
title={MedOCR-Vision: Medical Document OCR with PaddleOCR-VL},
author={Syed Naazim Hussain},
year={2025},
publisher={HuggingFace},
howpublished={\url{https://huggingface.co/naazimsnh02/medocr-vision}}
}
This model is released under the MIT License. Please refer to individual dataset licenses for usage terms of the training data.
Model Version: 1.0
Release Date: December 2025
Challenge: ERNIE AI Developer Challenge
--- language: - en license: mit tags: - vision - image-to-text - ocr - medical - paddleocr - unsloth - lora - ernie-challenge datasets: - naazimsnh02/medocr-vision-dataset base_model: unsloth/PaddleOCR-VL library_name: transformers pipeline_tag: image-to-text --- # MedOCR-Vision: Medical Document OCR with PaddleOCR-VL **ERNIE AI Developer Challenge Submission** A fine-tuned PaddleOCR-VL model specialized for medical document OCR, achieving high accuracy on medical prescriptions, lab reports, and forms while maintaining general OCR capabilities. ## Model Description MedOCR-Vision is a vision-language model fine-tuned specifically for optical character recognition (OCR) of medical documents. The model is based on PaddleOCR-VL (1B parameters) and has been fine-tuned using LoRA (Low-Rank Adaptation) on a carefully curated dataset of 2,462 medical and general documents. ### Key Features - **Specialized for Medical Documents**: Optimized for prescriptions, lab reports, and medical forms - **Domain-Balanced Training**: Maintains general OCR capabilities (invoices, receipts, business documents) - **Production-Ready**: Full merged model in float16 precision - **Efficient Fine-tuning**: LoRA-based training for optimal performance with minimal parameters - **High Accuracy**: Validation loss of 0.578 after 3 epochs of training ### Model Architecture - **Base Model**: unsloth/PaddleOCR-VL (1B parameters) - **Fine-tuning Method**: LoRA (Low-Rank Adaptation) - **LoRA Rank**: 64 - **LoRA Alpha**: 64 - **Target Modules**: q_proj, k_proj, v_proj, o_proj, gate_proj, up_proj, down_proj, out_proj, fc1, fc2, linear_1, linear_2 - **Precision**: Mixed (BF16/FP16) ## Performance Highlights ### Model Improvements Over Base Model Our fine-tuned model demonstrates significant improvements across multiple metrics: - ✅ **Enhanced Information Extraction**: Captures more complete medical information including headers, test values, and reference ranges - ✅ **Better Document Understanding**: Improved coverage of document structure and context - ✅ **Medical Domain Specialization**: Superior performance on medical terminology and clinical data - ✅ **Comprehensive Coverage**: Extracts significantly more relevant content from medical documents ## Intended Uses ### Primary Use Cases - **Medical Prescription Digitization**: Extract text from handwritten and printed prescriptions...
Source context: 188 downloads · 4 likes · Pipeline image-to-text · Library transformers · Repo naazimsnh02/medocr-vision