File size: 13,751 Bytes
1188cc9 d948b64 46d4e53 02277ae c41c00f 1188cc9 fca3735 d4d0f79 fca3735 1188cc9 a605c65 1188cc9 ce6d29f 1188cc9 c269769 1188cc9 2766807 9faf4db 2766807 9faf4db 38d492c 1188cc9 a605c65 ecb789e a605c65 1188cc9 a1eb664 a9f189f 36e4d64 1188cc9 c2f1a37 1188cc9 c2f1a37 a1eb664 0d79f76 a9f189f a1eb664 1188cc9 ea5cacd 1188cc9 ea5cacd a9f189f 0d79f76 a9f189f 1188cc9 a9f189f 0d79f76 a9f189f 96b4d24 1188cc9 6ce6a2d 0d79f76 1188cc9 bc875ce a605c65 ac6a587 ce6d29f 8220107 1188cc9 a605c65 605e2f3 1188cc9 605e2f3 83d6be0 605e2f3 b0c5e0b 605e2f3 1188cc9 a605c65 ecb789e b0c5e0b 9e8eeca b0c5e0b 1188cc9 b0c5e0b 1188cc9 b0c5e0b 1188cc9 b0c5e0b |
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 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 |
---
license: apache-2.0
language:
- vi
- en
- zh
base_model:
- Qwen/Qwen2-VL-7B-Instruct
library_name: transformers
tags:
- erax
- multimodal
- erax-vl-7b
- insurance
- ocr
- vietnamese
- bcg
pipeline_tag: visual-question-answering
widget:
- src: images/photo-1-16505057982762025719470.webp
example_title: Test 1
- src: images/vt-don-thuoc-f0-7417.jpeg
example_title: Test 2
---
<p align="center">
<img src="https://cdn-uploads.huggingface.co/production/uploads/66e93d483745423cbb14c5ff/fNxjr3en_onzbOv0sghpE.jpeg" alt="Logo">
</p>
<!-- ![image/jpeg](https://cdn-uploads.huggingface.co/production/uploads/66e93d483745423cbb14c5ff/fNxjr3en_onzbOv0sghpE.jpeg) -->
# EraX-VL-7B-V1
## Introduction🎉
We are excited to introduce **EraX-VL-7B-v1**, a robust multimodal model for **OCR (optical character recognition)** and **VQA (visual question-answering)** that excels in various languages🌍, with a particular focus on Vietnamese🇻🇳. The `EraX-VL-7B` model stands out for its precise recognition capabilities across a range of documents📝, including medical forms 🩺, invoices 🧾, bills of sale 💳, quotes 📄, and medical records 💊. This functionality is expected to be highly beneficial for hospitals 🏥, clinics 💉, insurance companies 🛡️, and other similar applications 📋. Built on the solid foundation of the [Qwen/Qwen2-VL-7B-Instruct](https://huggingface.co/Qwen/Qwen2-VL-7B-Instruct)[1], which we found to be of high quality and fluent in Vietnamese, `EraX-VL-7B` has been fine-tuned to enhance its performance. We plan to continue improving and releasing new versions for free, along with sharing performance benchmarks in the near future.
**EraX-VL-7B-V1** is a young member of our **EraX's LànhGPT** collection of LLM models.
- **Developed by:**
- Nguyễn Anh Nguyên (nguyen@erax.ai)
- Nguyễn Hồ Nam (BCG)
- Hoàng Tiến Dũng (dung.ht@erax.ai)
- Phạm Huỳnh Nhật (nhat.ph@erax.ai)
- Phạm Đình Thục (thuc.pd@erax.ai)
- **Funded by:** [Bamboo Capital Group](https://bamboocap.com.vn) and EraX
- **Model type:** Multimodal Transformer with over 7B parameters
- **Languages (NLP):** Primarily Vietnamese with multilingual capabilities
- **License:** Apache 2.0
- **Fine-tuned from:** [Qwen/Qwen2-VL-7B-Instruct](https://huggingface.co/Qwen/Qwen2-VL-7B-Instruct)
## Benchmarks📊
Coming Soon!!!
## Examples🧩
<details>
<summary>Example 01:</summary>
![image/jpeg](https://cdn-uploads.huggingface.co/production/uploads/66e93d483745423cbb14c5ff/Q5GkK8vuZ9zDVPkhwu4yH.jpeg)
* Kết quả:
```
{
"document": {
"header": {
"title": "GIẤY HẸN KHÁM LẠI",
"organization": "SỞ Y TẾ NGHỆ AN\nBỆNH VIỆN UNG BƯỚU NGHỆ AN",
"address": "Võ Thị Sáu, Thủy Tùng - TP Vinh - Nghệ An"
},
"patient_info": {
"name": "NGUYỄN THỊ LUÂN",
"date_of_birth": "03/07/1976",
"gender": "40",
"address": "Xã Nghĩa Khánh-Huyện Nghĩa Đàn-Nghệ An",
"medical_card_number": "CN 3 40 40 168 60413",
"registration_date": "16/12/2016",
"admission_date": "Từ 01/03/2016",
"diagnosis": "C20-Bướu ac trực tràng",
"revisit_date": "17/01/2017"
},
"administrative_details": {
"department": "Trung tâm điều trị ung bướu",
"revisit_instruction": "vào ngày 17/01/2017, hoặc đến hết kỳ thời gian nếu nước ngoài hẹn khám lại nếu có dấu hiệu (triệu chứng)",
"note": "nếu KCB ban đầu: Trạm y tế xã Nghĩa Khánh",
"signature": "Trưởng khoa",
"doctor_signature": "Lâm Nguyễn Khang",
"revisiting_date_confirmation": "Ngày 16 tháng 12 năm 2016",
"confirmation_signature": "Bác sĩ điều trị",
"physician_signature": "Nguyễn Văn Việt"
}
}
}
```
</details>
<details>
<summary>Example 02:</summary>
![image/png](https://cdn-uploads.huggingface.co/production/uploads/66e93d483745423cbb14c5ff/IrX-QP67TZTcTl3vlp1uZ.png)
* Kết quả:
```
{
"header": {
"title": "PHIẾU KHÁM BỆNH",
"date": "Hà Nội, ngày 23 tháng 3 năm 2020",
"patient_info": {
"id": "HN011000002",
"name": "Vương Hồng Thắng - Năm sinh: 1978",
"address": "Số 10 tầng 2, TTTM V+, Số 505 Phố Minh Khai, Quận Hai Bà Trưng, Hà Nội",
"phone": "+0942116117",
"email": "bamu.vn@gmail.com"
},
"contact_info": {
"address": "Nhà Khoa Bamufit\nĐịa chỉ: 505, Phố Minh Khai, Hai Bà Trưng, Hà Nội, Việt Nam",
"phone": "0942484784",
"email": "info@bamufit.vn",
"website": "https://bamufit.vn"
}
},
"treatment_details": [
{
"visit_date": "13-09-2019",
"treatment_type": "Chẩn đoán: Abscess chẽ",
"procedure": "Cắt lợi bằng Laser r23",
"doctor": "THỊ HIEN",
"price": "500,000",
"quantity": "1",
"discounted_price": "0",
"total_cost": "500,000"
},
{
"visit_date": "13-09-2019",
"treatment_type": "Chẩn đoán: Abscess quanh chóp",
"procedure": "Bám gai xuống ở răng r23",
"doctor": "THỊ HIEN",
"price": "100,000",
"quantity": "1",
"discounted_price": "0",
"total_cost": "100,000"
}
],
"financial_details": {
"total_cost": "600,000",
"discounted_total": "0",
"paid_amount": "1,114,000",
"remaining_balance": "1,714,000"
},
"notes": "- Kiêng ăn uống đồ để gây nhiễm mủ như chè, cà phê, thuốc lá, rượu vang đỏ .. và hạn chế dùng đồ quá nóng, quá lạnh sau khi tẩy trắng răng ít nhất 2 tuần.",
"footer": {
"customer_signature": "(Ký và ghi rõ họ tên)",
"accountant_signature": "(Ký và ghi rõ họ tên)",
"dentist_signature": "(Ký và ghi rõ họ tên)"
}
}
```
</details>
<details>
<summary>Example 03:</summary>
![image/jpeg](https://cdn-uploads.huggingface.co/production/uploads/66e93d483745423cbb14c5ff/pSSqEOXQCsvz9H76CGQXa.jpeg)
* Kết quả:
Hình ảnh là một biểu đồ thể hiện mối quan hệ giữa chỉ số BMI (Body Mass Index) và tuổi, được chia thành các mức độ khác nhau dựa trên phần trăm percentile. Trục hoành của biểu đồ đại diện cho tuổi từ 2 đến 20 năm, trong khi trục tung đại diện cho chỉ số BMI từ 10 đến 32. Biểu đồ này có ba khu vực chính: vùng màu đỏ ở phía dưới cùng đại diện cho mức béo phì với chỉ số BMI cao hơn 30; vùng màu vàng nằm giữa đại diện cho nguy cơ béo phì với chỉ số BMI từ khoảng 25 đến 30; và vùng màu xanh lá cây ở phía trên đại diện cho mức cân nặng khỏe mạnh hoặc thiếu cân với chỉ số BMI thấp hơn 25. Trên biểu đồ còn có đường cong màu xám chạy qua các mức độ BMI theo tuổi, đánh dấu các mức 5th, 50th, và 95th percentile. Văn bản trong hình gồm các cụm từ 'Béo phì', 'Nguy cơ béo phì', 'Sức khỏe dinh dưỡng tốt', và 'Thiếu cân' để mô tả từng khu vực tương ứng với chỉ số BMI.
</details>
<details>
<summary>Example 04:</summary>
![image/jpeg](https://cdn-uploads.huggingface.co/production/uploads/66e93d483745423cbb14c5ff/kXrR6s990p0EgphZEtEnJ.jpeg)
* Kết quả:
Hình ảnh chụp một khung cảnh đồng quê Việt Nam với những nét đặc trưng riêng biệt. Bối cảnh là một cánh đồng lúa xanh mướt, trải dài bất tận, được bao phủ bởi một lớp sương mù nhẹ nhàng. Phía xa là những dãy núi xanh ngắt, tạo nên một bức tranh thiên nhiên thơ mộng và trữ tình. Ở trung tâm bức ảnh, hai cậu bé đang ngồi trên lưng con trâu nước đen tuyền. Cậu bé phía trước mặc quần đỏ, đang cười tươi rói, trong khi cậu bé phía sau mặc quần đen, vẻ mặt trầm tư hơn. Con trâu nước đang đứng yên, đầu hướng về phía bên phải, nhìn về phía xa xăm. Phía bên phải hình ảnh, một người đàn ông đang cầm một cái chậu màu đen, đang đổ nước lên đầu mình. Nước từ chậu chảy xuống tạo thành những giọt nước li ti, tung tóe khắp không gian. Trên bầu trời, có những đám mây trắng bồng bềnh, tạo nên một khung cảnh thanh bình và lãng mạn. Ánh nắng vàng óng chiếu rọi xuống cánh đồng, tạo nên một bức tranh tuyệt đẹp.
</details>
## Quickstart🎮
[![Open In Colab](https://colab.research.google.com/assets/colab-badge.svg)](https://colab.research.google.com/drive/1CnSxtWDLG48-NQh7wk9_z8WI7J4OY_Ci?usp=sharing)
Install the necessary packages:
```curl
python -m pip install git+https://github.com/huggingface/transformers accelerate
python -m pip install qwen-vl-utils
pip install flash-attn --no-build-isolation
```
Then you can use `EraX-VL-7B-V1` like this:
```python
import os
import base64
import json
import cv2
import numpy as np
import matplotlib.pyplot as plt
import torch
from transformers import Qwen2VLForConditionalGeneration, AutoTokenizer, AutoProcessor
from qwen_vl_utils import process_vision_info
model_path = "erax/EraX-VL-7B-V1"
model = Qwen2VLForConditionalGeneration.from_pretrained(
model_path,
torch_dtype=torch.bfloat16,
attn_implementation="eager", # replace with "flash_attention_2" if your GPU is Ampere architecture
device_map="auto"
)
tokenizer = AutoTokenizer.from_pretrained(model_path)
# processor = AutoProcessor.from_pretrained(model_path)
min_pixels = 256 * 28 * 28
max_pixels = 1280 * 28 * 28
processor_model = "Qwen/Qwen2-VL-7B-Instruct-GPTQ-Int4"
processor = AutoProcessor.from_pretrained(
processor_model,
min_pixels=min_pixels,
max_pixels=max_pixels,
)
image_path ="image.jpg"
with open(image_path, "rb") as f:
encoded_image = base64.b64encode(f.read())
decoded_image_text = encoded_image.decode('utf-8')
base64_data = f"data:image;base64,{decoded_image_text}"
messages = [
{
"role": "user",
"content": [
{
"type": "image",
"image": base64_data,
},
{
"type": "text",
"text": "Diễn tả nội dung bức ảnh như 1 bác sỹ giỏi."
# "Diễn tả nội dung bức ảnh này bằng định dạng json."
},
],
}
]
# Prepare prompt
tokenized_text = processor.apply_chat_template(
messages, tokenize=False, add_generation_prompt=True
)
image_inputs, video_inputs = process_vision_info(messages)
inputs = processor(
text=[ tokenized_text],
images=image_inputs,
videos=video_inputs,
padding=True,
return_tensors="pt",
)
inputs = inputs.to("cuda")
# Generation configs
generation_config = model.generation_config
generation_config.do_sample = True
generation_config.temperature = 0.2
generation_config.top_k = 1
generation_config.top_p = 0.001
generation_config.max_new_tokens = 2048
generation_config.repetition_penalty = 1.1
# Inference
generated_ids = model.generate(**inputs, generation_config=generation_config)
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[0])
```
## Acknowledgments👏
We thank Khang Đoàn ([5CD-AI](https://huggingface.co/5CD-AI)) for his invaluable support in order to train `EraX-VL-7B-V1`. Our appreciation also goes to AAA JS Company for their support and resources, which significantly contributed to this project.
## Contact🤝
For correspondence regarding this work, please contact Nguyễn Anh Nguyên at [nguyen@erax.ai](nguyen@erax.ai).
## Citation📝
<!-- - title={EraX-VL-7B-V1: A Highly Efficient Multimodal LLM for Vietnamese, especially for medical forms and bills.},
- author={Nguyễn Anh Nguyên and Nguyễn Hồ Nam (BCG) and Dũng Hoàng and Thục Phạm and Nhật Phạm},
- helpers={Khang Đoàn and AAA JS Company},
- contact={nguyen@erax.ai},
- organization={EraX} -->
If you find our project useful, we would appreciate it if you could star our repository and cite our work as follows:
```
@article{EraX-VL-7B-V1,
title={EraX-VL-7B-V1: A Highly Efficient Multimodal LLM for Vietnamese, especially for medical forms and bills},
author={Nguyễn Anh Nguyên and Nguyễn Hồ Nam (BCG) and Dũng Hoàng and Thục Phạm and Nhật Phạm},
organization={EraX},
year={2024},
url={https://huggingface.co/erax-ai/EraX-VL-7B-V1}
}
```
## References📑
[1] Qwen team. Qwen2-VL. 2024.
[2] Bai, Jinze, et al. "Qwen-VL: A Versatile Vision-Language Model for Understanding, Localization, Text Reading, and Beyond." arXiv preprint arXiv:2308.12966 (2023).
[4] Yang, An, et al. "Qwen2 technical report." arXiv preprint arXiv:2407.10671 (2024).
[5] Chen, Zhe, et al. "Internvl: Scaling up vision foundation models and aligning for generic visual-linguistic tasks." Proceedings of the IEEE/CVF Conference on Computer Vision and Pattern Recognition. 2024.
[6] Chen, Zhe, et al. "How far are we to gpt-4v? closing the gap to commercial multimodal models with open-source suites." arXiv preprint arXiv:2404.16821 (2024).
[7] Tran, Chi, and Huong Le Thanh. "LaVy: Vietnamese Multimodal Large Language Model." arXiv preprint arXiv:2404.07922 (2024). |