File size: 16,208 Bytes
c2f8b18
70c5496
 
 
 
 
 
88c124a
c2f8b18
70c5496
 
 
88c124a
70c5496
 
 
 
 
 
 
 
 
 
 
c2f8b18
70c5496
66c4470
70c5496
66c4470
70c5496
4636d03
70c5496
 
9d3c32d
70c5496
0927f25
70c5496
40c97e9
 
 
70c5496
0927f25
70c5496
f573097
 
 
 
 
 
88c124a
70c5496
 
88c124a
be4f274
70c5496
 
 
3ee14cd
 
 
 
d73d93d
45ba289
d73d93d
3ee14cd
 
0bcb657
3951eb7
8720fe8
a5ce0b1
 
8720fe8
3ee14cd
8720fe8
3ee14cd
 
8720fe8
3ee14cd
8720fe8
3ee14cd
 
8720fe8
3ee14cd
8720fe8
3ee14cd
 
8720fe8
3ee14cd
8720fe8
3ee14cd
 
8720fe8
3ee14cd
8720fe8
3ee14cd
 
8720fe8
3ee14cd
8720fe8
3ee14cd
 
8720fe8
3ee14cd
8720fe8
3ee14cd
 
8720fe8
3ee14cd
8720fe8
3ee14cd
 
8720fe8
3ee14cd
8720fe8
3ee14cd
 
8720fe8
3ee14cd
8720fe8
3ee14cd
 
8720fe8
3ee14cd
8720fe8
3ee14cd
 
8720fe8
3ee14cd
8720fe8
3ee14cd
 
8720fe8
3ee14cd
8720fe8
3ee14cd
 
8720fe8
3ee14cd
8720fe8
3ee14cd
 
8720fe8
3ee14cd
8720fe8
3ee14cd
 
a7e9d70
 
 
70c5496
 
 
 
 
41d55e0
 
 
70c5496
499f6f2
 
 
 
 
 
 
 
 
70c5496
499f6f2
 
 
70c5496
 
 
499f6f2
 
 
 
 
 
 
 
 
 
 
70c5496
 
d49aefd
3ca5e31
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
41d55e0
d49aefd
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
41d55e0
d49aefd
 
 
a2e2f1a
d49aefd
 
 
15660b1
d49aefd
15660b1
d49aefd
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
3ca5e31
 
 
 
a2e2f1a
3ca5e31
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
70c5496
 
 
 
 
 
 
 
c2f8b18
775fda0
70c5496
 
 
 
c2f8b18
70c5496
 
 
c2f8b18
70c5496
 
 
 
775fda0
70c5496
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
c2f8b18
70c5496
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
a817d1e
70c5496
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
dd1ef69
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
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
---
license: apache-2.0
language:
- vi
- en
- zh
base_model:
- Qwen/Qwen2-VL-2B-Instruct
library_name: transformers
tags:
- erax
- multimodal
- erax-vl-2B
- 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="left">
  <img src="https://cdn-uploads.huggingface.co/production/uploads/63d8d8879dfcfa941d4d7cd9/GsQKdaTyn2FFx_cZvVHk3.png" alt="Logo">
</p>


# EraX-VL-2B-V1.5
## Introduction 🎉

Hot on the heels of the popular **<a href="https://huggingface.co/erax-ai/EraX-VL-7B-V1.0" target="_blank">EraX-VL-7B-V1.0 model</a>**, we proudly present **EraX-VL-2B-V1.5**. This enhanced multimodal model offers robust **OCR and VQA** capabilities across diverse languages 🌍, with a significant advantage in processing **Vietnamese 🇻🇳**. The `EraX-VL-2B` 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-2B-Instruct](https://huggingface.co/Qwen/Qwen2-VL-2B-Instruct)[1], which we found to be of high quality and fluent in Vietnamese, `EraX-VL-2B` 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.

One standing-out feature of **EraX-VL-2B-V1.5** is the capability to do multi-turn Q&A with reasonable reasoning capability at its small size of only +2 billions parameters.

***NOTA BENE***: 
- EraX-VL-2B-V1.5 is NOT a typical OCR-only tool likes Tesseract but is a Multimodal LLM-based model. To use it effectively, you may have to **twist your prompt carefully** depending on your tasks.
- This model was NOT finetuned with medical (X-ray) dataset or car accidences (yet). Stay tune for updated version coming up sometime 2025.

**EraX-VL-2B-V1.5** is a young and tiny member of our **EraX's LànhGPT** collection of LLM models.

- **Developed by:**
  - Nguyễn Anh Nguyên ([email protected])
  - Nguyễn Hồ Nam (BCG)
  - Phạm Huỳnh Nhật ([email protected])
  - Phạm Đình Thục ([email protected])
- **Funded by:** [Bamboo Capital Group](https://bamboocap.com.vn) and EraX
- **Model type:** Multimodal Transformer with over 2B parameters
- **Languages (NLP):** Primarily Vietnamese with multilingual capabilities
- **License:** Apache 2.0
- **Fine-tuned from:** [Qwen/Qwen2-VL-2B-Instruct](https://huggingface.co/Qwen/Qwen2-VL-2B-Instruct)
- **Prompt examples:** <b><a href="https://github.com/EraX-JS-Company/erax-vl-7b-v1/blob/main/prompts/Vietnam_popular_prompts.txt" target="_blank">Some popular prompt examples.</a>

## Benchmarks 📊

## 🏆 LeaderBoard

<table style="width:75%;">
    <tr>
        <th align="middle" width="300">Models</th>
        <td align="middle" width="150"><b>Open-Source</b></td>
        <td align="middle" width="300"><b>VI-MTVQA</b></td>
    </tr>
    <tr>
        <th align="middle"><font color=darkred>EraX-VL-7B-V1.5 🥇 </font></th>
        <td align="middle"> ✅ </td>
        <td align="middle">47.2 </td>
    </tr>
    <tr>
        <th align="middle">Qwen2-VL 72B 🥈 </th>
        <td align="middle">✘</td>
        <td align="middle">41.6 </td>
    </tr>
    <tr>
        <th align="middle">ViGPT-VL 🥉 </th>
        <td align="middle">✘</td>
        <td align="middle">39.1 </td>
    </tr>
    <tr>
        <th align="middle"><font color=darkred>EraX-VL-2B-V1.5</font></th>
        <td align="middle"> ✅ </td>
        <td align="middle">38.2 </td>
    </tr>
    <tr>
        <th align="middle"><font color=darkred>EraX-VL-7B-V1 </font></th>
        <td align="middle"> ✅ </td>
        <td align="middle">37.6 </td>
    </tr>
    <tr>
        <th align="middle"><font color=darkred>Vintern-1B-V2</font></th>
        <td align="middle"> ✅ </td>
        <td align="middle">37.4 </td>
    </tr>
    <tr>
        <th align="middle"><font color=darkred>Qwen2-VL 7B </font></th>
        <td align="middle"> ✅ </td>
        <td align="middle">30.0 </td>
    </tr>
    <tr>
        <th align="middle">Claude3 Opus</th>
        <td align="middle">✘</td>
        <td align="middle">29.1 </td>
    </tr>
    <tr>
        <th align="middle">GPT-4o mini </th>
        <td align="middle"> ✘ </td>
        <td align="middle">29.1 </td>
    </tr>
    <tr>
        <th align="middle">GPT-4V</th>
        <td align="middle">✘</td>
        <td align="middle">28.9 </td>
    </tr>
    <tr>
        <th align="middle">Gemini Ultra</th>
        <td align="middle">✘</td>
        <td align="middle">28.6 </td>
    </tr>
     <tr>
        <th align="middle"><font color=darkred>InternVL2 76B</font></th>
        <td align="middle"> ✅ </td>
        <td align="middle">26.9 </td>
    </tr>
    <tr>
        <th align="middle">QwenVL Max</th>
        <td align="middle">✘</td>
        <td align="middle">23.5 </td>
    </tr>
    <tr>
        <th align="middle">Claude3 Sonnet</th>
        <td align="middle">✘</td>
        <td align="middle">20.8 </td>
    </tr>
    <tr>
        <th align="middle">QwenVL Plus</th>
        <td align="middle">✘</td>
        <td align="middle">18.1 </td>
    </tr>
    <tr>
        <th align="middle"><font color=darkred>MiniCPM-V2.5</font></th>
        <td align="middle">✅</td>
        <td align="middle">15.3 </td>
    </tr>
</table>

**The test code for evaluating models in the paper can be found in**: <b><a href="https://github.com/EraX-JS-Company/EraX-MTVQA-Benchmark" target="_blank">EraX-JS-Company/EraX-MTVQA-Benchmark</a></b>

## API trial 🎉
Please contact **[email protected]** for API access inquiry.

## Examples 🧩

### 1. OCR - Optical Character Recognition for Multi-Images

**Example 01: Citizen identification card**

<div style="display: flex; flex-direction: row; align-items: center; justify-content: center;">
  <div style="text-align: center; margin: 0 10px;">
    <img src="images/trinhquangduy_front.jpg" width="500" alt="Front View" />
    <p>Front View</p>
  </div>
  <div style="text-align: center; margin: 0 10px;">
    <img src="images/trinhquangduy_back.jpg" width="500" alt="Back View" />
    <p>Back View</p>
  </div>
</div>
<p style="text-align: center; font-size: 12px; color: gray; margin-top: 10px;">
  Source: <a href="https://support.google.com/google-ads/thread/270967947/t%C3%B4i-%C4%91%C3%A3-g%E1%BB%ADi-h%C3%ACnh-%E1%BA%A3nh-c%C4%83n-c%C6%B0%E1%BB%9Bc-c%C3%B4ng-d%C3%A2n-c%E1%BB%A7a-ch%C3%ADnh-t%C3%B4i-%C4%91%E1%BB%83-x%C3%A1c-minh-danh-t%C3%ADnh?hl=vi" target="_blank">Google Support</a>
</p>

```
{
  "Số thẻ":"037094012351"
  "Họ và tên":"TRỊNH QUANG DUY"
  "Ngày sinh":"04/09/1994"
  "Giới tính":"Nam"
  "Quốc tịch":"Việt Nam"
  "Quê quán / Place of origin":"Tân Thành, Kim Sơn, Ninh Bình"
  "Nơi thường trú / Place of residence":"Xóm 6 Tân Thành, Kim Sơn, Ninh Bình"
  "Có giá trị đến":"04/09/2034"
  "Đặc điểm nhân dạng / Personal identification":"seo chấm c:1cm trên đuôi mắt trái"
  "Cục trưởng cục cảnh sát quản lý hành chính về trật tự xã hội":"Nguyễn Quốc Hùng"
  "Ngày cấp":"10/12/2022"
}
```

**Example 01: Identity Card**


<div style="display: flex; flex-direction: row; align-items: center; justify-content: center;">
  <div style="text-align: center; margin: 0 10px;">
    <img src="https://cdn-uploads.huggingface.co/production/uploads/63d8d8879dfcfa941d4d7cd9/4RD71oI0p04n1hAvLnqCR.jpeg" width="500" alt="Front View" />
    <p>Front View</p>
  </div>
  <div style="text-align: center; margin: 0 10px;">
    <img src="https://cdn-uploads.huggingface.co/production/uploads/63d8d8879dfcfa941d4d7cd9/zNOWjwAoS9zEH1wUt6Fh6.jpeg" width="500" alt="Back View" />
    <p>Back View</p>
  </div>
</div>
<p style="text-align: center; font-size: 12px; color: gray; margin-top: 10px;">
  Source: <a href="https://lamgiaynhanh.com/lam-giay-chung-minh-nhan-dan-gia-nhanh/" target="_blank">Internet</a>
</p>

```
{
  "Số":"272737384"
  "Họ tên":"PHẠM NHẬT TRƯỜNG"
  "Sinh ngày":"08-08-2000"
  "Nguyên quán":"Tiền Giang"
  "Nơi ĐKHK thường trú":"393, Tân Xuân, Bảo Bình, Cẩm Mỹ, Đồng Nai"
  "Dân tộc":"Kinh"
  "Tôn giáo":"Không"
  "Đặc điểm nhận dạng":"Nốt ruồi c.3,5cm trên sau cánh mũi phải."
  "Ngày cấp":"30 tháng 01 năm 2018"
  "Giám đốc CA":"T.BÌNH ĐỊNH"
}
```

**Example 02: Driver's License**

<div style="display: flex; flex-direction: row; align-items: center; justify-content: center;">
  <div style="text-align: center; margin: 0 10px;">
    <img src="images/nguyenvandung_front.png" width="500" alt="Front View" />
    <p>Front View</p>
  </div>
  <div style="text-align: center; margin: 0 10px;">
    <img src="images/nguyenvandung_back.png" width="500" alt="Back View" />
    <p>Back View</p>
  </div>
</div>
<p style="text-align: center; font-size: 12px; color: gray; margin-top: 10px;">
  Source: <a href="https://baophapluat.vn/khoi-to-tai-xe-len-mang-mua-giay-phep-lai-xe-gia-de-chay-xe-post481047.html" target="_blank">Báo Pháp luật</a>
</p>

```
{
  "No.":"400116012313"
  "Fullname":"NGUYỄN VĂN DŨNG"
  "Date_of_birth":"08/06/1979"
  "Nationality":"VIỆT NAM"
  "Address":"X. Quỳnh Hầu, H. Quỳnh Lưu, T. Nghệ An
  Nghệ An, ngày/date 23 tháng/month 04 năm/year 2022"
  "Hang_Class":"FC"
  "Expires":"23/04/2027"
  "Place_of_issue":"Nghệ An"
  "Date_of_issue":"ngày/date 23 tháng/month 04 năm/year 2022"
  "Signer":"Trần Anh Tuấn"
  "Các loại xe được phép":"Ô tô hạng C kéo rơmoóc, đầu kéo kéo sơmi rơmoóc và xe hạng B1, B2, C, FB2 (Motor vehicle of class C with a trailer, semi-trailer truck and vehicles of classes B1, B2, C, FB2)"
  "Mã số":""
}
```

**Example 03: Vehicle Registration Certificate**

<div style="display: flex; flex-direction: row; align-items: center; justify-content: center;">
  <div style="text-align: center; margin: 0 10px;">
    <img src="images/nguyentonnhuan.jpg" width="500"/>
  </div>
</div>
<p style="text-align: center; font-size: 12px; color: gray; margin-top: 10px;">
  Source: <a href="https://vietnamnet.vn/phan-biet-cac-loai-giay-dang-ky-xe-khi-mua-moto-da-qua-su-dung-541341.html" target="_blank">Báo Vietnamnet</a>
</p>

```
{
  "Tên chủ xe":"NGUYỄN TÔN NHUẬN"
  "Địa chỉ":"KE27 Kp3 P.TTTây Q7"
  "Nhãn hiệu":"HONDA"
  "Số loại":"DYLAN"
  "Màu sơn":"Trắng"
  "Số người được phép chở":"02"
  "Nguồn gốc":"Xe nhập mới"
  "Biển số đăng ký":"59V1-498.89"
  "Đăng ký lần đầu ngày":"08/06/2004"
  "Số máy":"F03E-0057735"
  "Số khung":"5A04F-070410"
  "Dung tích":"152"
  "Quản lý":"TRƯỞNG CA QUẬN"
  "Thượng tá":"Trần Văn Hiểu"
}
```

**Example 04: Birth Certificate**

<div style="display: flex; flex-direction: row; align-items: center; justify-content: center;">
  <div style="text-align: center; margin: 0 10px;">
    <img src="https://cdn-uploads.huggingface.co/production/uploads/63d8d8879dfcfa941d4d7cd9/nVy1v3bwBl5lP9fZIIeux.jpeg" width="500"/>
  </div>
</div>
<p style="text-align: center; font-size: 12px; color: gray; margin-top: 10px;">
  Source: <a href="https://congchung247.com.vn/giay-khai-sinh-ban-chinh-co-the-lam-lai-duoc-khong/" target="_blank">https://congchung247.com.vn</a>
</p>

```
{
    "name": "NGUYỄN NAM PHƯƠNG",
    "gender": "Nữ",
    "date_of_birth": "08/6/2011",
    "place_of_birth": "Bệnh viện Việt - Pháp Hà Nội",
    "nationality": "Việt Nam",
    "father_name": "Nguyễn Ninh Hồng Quang",
    "father_dob": "1980",
    "father_address": "309 nhà E2 Bạch Khoa - Hai Bà Trưng - Hà Nội",
    "mother_name": "Phạm Thùy Trang",
    "mother_dob": "1984",
    "mother_address": "309 nhà E2 Bạch Khoa - Hai Bà Trưng - Hà Nội",
    "registration_place": "UBND phường Bạch Khoa - Quận Hai Bà Trưng - Hà Nội",
    "registration_date": "05/8/2011",
    "registration_ralation": "cha",
    "notes": None,
    "certified_by": "Nguyễn Thị Kim Hoa"
}
```

## Quickstart 🎮

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-2B-V1.5` 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-2B-V1.5"

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 = AutoProcessor.from_pretrained(
     model_path,
     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": "Trích xuất thông tin nội dung từ hình ảnh được cung cấp."
            },
        ],
    }
]

# 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 = 1.0
generation_config.top_k       = 1
generation_config.top_p       = 0.9
generation_config.min_p       = 0.1
generation_config.best_of     = 5
generation_config.max_new_tokens     = 2048
generation_config.repetition_penalty = 1.06

# 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])
```

## 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).


## Contact 🤝
- For correspondence regarding this work or inquiry for API trial, please contact Nguyễn Anh Nguyên at [[email protected]]([email protected]).
- Follow us on <b><a href="https://github.com/EraX-JS-Company" target="_blank">EraX Github</a></b>