File size: 3,715 Bytes
93cd1d7 cfa92ac 93cd1d7 cfa92ac 93cd1d7 cfa92ac 93cd1d7 c7db220 93cd1d7 cfa92ac c7db220 cfa92ac 93cd1d7 cfa92ac 93cd1d7 cfa92ac 93cd1d7 cfa92ac 93cd1d7 cfa92ac 93cd1d7 cfa92ac 93cd1d7 cfa92ac |
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 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 |
---
library_name: transformers
tags: [OCR]
---
# Model Card for Model qwen-for-jawi-v1
## Model Description
This model is a fine-tuned version of [Qwen/Qwen2-VL-7B-Instruct](https://huggingface.co/Qwen/Qwen2-VL-2B-Instruct) specialized for Optical Character Recognition (OCR) of historical Malay texts written in Jawi script (Arabic script adapted for Malay language).
### Model Architecture
- **Base Model**: [Qwen2-VL-2B-Instruct](https://huggingface.co/Qwen/Qwen2-VL-2B-Instruct)
- **Model Type**: Vision-Language Model
- **Parameters**: 2 billion
- **Language(s)**: Malay (Jawi script)
## Intended Use
### Primary Intended Uses
- OCR for historical Malay manuscripts written in Jawi script
- Digital preservation of Malay cultural heritage
- Enabling computational analysis of historical Malay texts
### Out-of-Scope Uses
- General Arabic text recognition
- Modern Malay text processing
- Real-time OCR applications
## Training Data
### Dataset Description
This was trained and evaluated using
### Training Procedure
- Hardware used: 1 x H100
- Training time: 6 hours
## Performance and Limitations
### Performance Metrics
- Character Error Rate (CER): 8.66
- Word Error Rate (WER): 25.50
### Comparison with Other Models
We compared this model with https://github.com/VikParuchuri/surya, which reports high accuracy reates for Arabic, but performs poorly oun our Jawi data:
- Character Error Rate (CER): 70.89%
- Word Error Rate (WER): 91.73%
## How to Use
```python
# Example code for loading and using the model
from transformers import Qwen2VLForConditionalGeneration, AutoProcessor
import torch
from qwen_vl_utils import process_vision_info
from PIL import Image
model_name = 'mevsg/qwen-for-jawi-v1'
model = Qwen2VLForConditionalGeneration.from_pretrained(
model_name,
torch_dtype=torch.bfloat16, # Use the appropriate torch dtype if needed
device_map='auto' # Optional: automatically allocate model layers across devices
)
# Load the processor from Hugging Face Hub
processor = AutoProcessor.from_pretrained("Qwen/Qwen2-VL-2B-Instruct")
# Add example usage code
image_path = 'path/to/image'
image = Image.open(image_path).convert('RGB')
messages = [
{
"role": "user",
"content": [
{
"type": "image",
"image": image,
},
{"type": "text", "text": "Convert this image to text"},
],
}
]
# Preparation for inference
text = processor.apply_chat_template(
messages, tokenize=False, add_generation_prompt=True
)
image_inputs, video_inputs = process_vision_info(messages)
inputs = processor(
text=[text],
images=image_inputs,
videos=video_inputs,
padding=True,
return_tensors="pt",
)
inputs = inputs.to("cuda")
# Inference: Generation of the output
generated_ids = model.generate(**inputs, max_new_tokens=128)
generated_ids_trimmed = [
out_ids[len(in_ids) :] for in_ids, out_ids in zip(inputs.input_ids, generated_ids)
]
output_text = processor.batch_decode(
generated_ids_trimmed, skip_special_tokens=True, clean_up_tokenization_spaces=False
)
print(output_text)
```
## Citation
```bibtex
@misc{qwen-for-jawi-v1,
title = {Qwen for Jawi v1: a model for Jawi OCR},
author = {[Miguel Escobar Varela]},
year = {2024},
publisher = {HuggingFace},
url = {[https://huggingface.co/mevsg/qwen-for-Jawi-v1]},
note = {Model created at National University of Singapore }
}
```
## Acknowledgements
Special thanks to [William Mattingly](https://huggingface.co/wjbmattingly), whose finetuning script served as the base for our finetuning approach: https://github.com/wjbmattingly/qwen2-vl-finetune-huggingface
|