Upload folder using huggingface_hub
Browse files- .gitattributes +1 -0
- README.md +105 -0
- SGK_CanhDieu_TuNhienVaXaHoi_3_page_063.png +3 -0
- adapter_config.json +43 -0
- adapter_model.safetensors +3 -0
- run_config.json +17 -0
.gitattributes
CHANGED
|
@@ -33,3 +33,4 @@ saved_model/**/* filter=lfs diff=lfs merge=lfs -text
|
|
| 33 |
*.zip filter=lfs diff=lfs merge=lfs -text
|
| 34 |
*.zst filter=lfs diff=lfs merge=lfs -text
|
| 35 |
*tfevents* filter=lfs diff=lfs merge=lfs -text
|
|
|
|
|
|
| 33 |
*.zip filter=lfs diff=lfs merge=lfs -text
|
| 34 |
*.zst filter=lfs diff=lfs merge=lfs -text
|
| 35 |
*tfevents* filter=lfs diff=lfs merge=lfs -text
|
| 36 |
+
SGK_CanhDieu_TuNhienVaXaHoi_3_page_063.png filter=lfs diff=lfs merge=lfs -text
|
README.md
ADDED
|
@@ -0,0 +1,105 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
---
|
| 2 |
+
language:
|
| 3 |
+
- en
|
| 4 |
+
library_name: transformers
|
| 5 |
+
pipeline_tag: image-text-to-text
|
| 6 |
+
base_model: Qwen/Qwen2-VL-2B-Instruct
|
| 7 |
+
datasets:
|
| 8 |
+
- bbdontcry/vietnamese-image-captioning
|
| 9 |
+
license: apache-2.0
|
| 10 |
+
tags:
|
| 11 |
+
- qwen2-vl
|
| 12 |
+
- lora
|
| 13 |
+
- peft
|
| 14 |
+
- image-captioning
|
| 15 |
+
- vietnamese
|
| 16 |
+
- accessibility
|
| 17 |
+
- textbook
|
| 18 |
+
---
|
| 19 |
+
|
| 20 |
+
[](https://github.com/itshoang2024/vi-textbook-caption-qwen2vl)
|
| 21 |
+
|
| 22 |
+
# LoRA Adapter - Vietnamese Textbook (SGK) Narration Captioning
|
| 23 |
+
|
| 24 |
+
This repository provides LoRA adapter weights only finetuned from **`Qwen/Qwen2-VL-2B-Instruct`** for Vietnamese textbook image captioning in a **narration-style** format that is screen-reader friendly aiming to **support visually impaired learners**.
|
| 25 |
+
|
| 26 |
+
> This repo contains **only the adapter** (not the base model).
|
| 27 |
+
> Full documentation + end-to-end pipeline (01→05) are on GitHub:
|
| 28 |
+
> https://github.com/itshoang2024/vi-textbook-caption-qwen2vl
|
| 29 |
+
|
| 30 |
+
---
|
| 31 |
+
|
| 32 |
+
## Contents
|
| 33 |
+
|
| 34 |
+
- `adapter_model.safetensors`, `adapter_config.json`: LoRA adapter weights (PEFT)
|
| 35 |
+
- `run_config.json`: prompt + generation config used in our pipeline (reproducibility)
|
| 36 |
+
|
| 37 |
+
---
|
| 38 |
+
|
| 39 |
+
## Benchmark (test split)
|
| 40 |
+
|
| 41 |
+
Dataset: `bbdontcry/vietnamese-image-captioning` (test)
|
| 42 |
+
|
| 43 |
+
| Model | Quote-CER ↓ | Concept-Rec ↑ | LLM-Score ↑ | BERTScore ↑ | BLEU-4 ↑ | METEOR ↑ |
|
| 44 |
+
|---|---:|---:|---:|---:|---:|---:|
|
| 45 |
+
| Qwen2-VL-2B (Zero-shot) | 0.995 | 0.222 | 3.36/10 | 0.671 | 6.30 | 0.142 |
|
| 46 |
+
| **Qwen2-VL-2B + LoRA (RUN_ID=A)** | **0.385** | **0.632** | **5.09/10** | **0.837** | **43.73** | **0.521** |
|
| 47 |
+
|
| 48 |
+
---
|
| 49 |
+
|
| 50 |
+
## Quickstart (load adapter)
|
| 51 |
+
|
| 52 |
+
```bash
|
| 53 |
+
pip install -U transformers accelerate peft safetensors pillow qwen-vl-utils
|
| 54 |
+
````
|
| 55 |
+
|
| 56 |
+
```python
|
| 57 |
+
import torch
|
| 58 |
+
from peft import PeftModel
|
| 59 |
+
from transformers import Qwen2VLForConditionalGeneration, AutoProcessor
|
| 60 |
+
|
| 61 |
+
BASE_ID = "Qwen/Qwen2-VL-2B-Instruct"
|
| 62 |
+
ADAPTER_ID = "hoangphann/LoRA-Qwen2-VL-2B-Instruct-captioning"
|
| 63 |
+
|
| 64 |
+
model = Qwen2VLForConditionalGeneration.from_pretrained(
|
| 65 |
+
BASE_ID,
|
| 66 |
+
torch_dtype=torch.bfloat16 if torch.cuda.is_available() else torch.float32,
|
| 67 |
+
device_map="auto" if torch.cuda.is_available() else None,
|
| 68 |
+
)
|
| 69 |
+
model = PeftModel.from_pretrained(model, ADAPTER_ID)
|
| 70 |
+
model.eval()
|
| 71 |
+
|
| 72 |
+
processor = AutoProcessor.from_pretrained(BASE_ID)
|
| 73 |
+
print("Loaded LoRA adapter (RUN_ID=A).")
|
| 74 |
+
```
|
| 75 |
+
|
| 76 |
+
> For the exact prompt/generation setup used in evaluation, see `run_config.json` and the Kaggle/GitHub pipeline.
|
| 77 |
+
|
| 78 |
+
---
|
| 79 |
+
|
| 80 |
+
## Example (SGK page → narration-style caption)
|
| 81 |
+
|
| 82 |
+
* `SGK_CanhDieu_TuNhienVaXaHoi_3_page_063.png`
|
| 83 |
+
|
| 84 |
+
<img src="./SGK_CanhDieu_TuNhienVaXaHoi_3_page_063.png" alt="SGK example page" width="420">
|
| 85 |
+
|
| 86 |
+
|
| 87 |
+
<details>
|
| 88 |
+
<summary><b>Model output</b></summary>
|
| 89 |
+
|
| 90 |
+
Phía trên cùng là câu hỏi bài tập số 2: "2. Cây nào có rễ cọc, cây nào có rễ chìm trong các hình dưới đây?". Bên dưới là 4 hình minh họa được đánh số thứ tự: - Hình 1 ở góc trên bên trái: Vẽ một cây xoài. Cây có thân và lá, thân cây có rễ. Bên dưới hình là nhãn: "1 Cây xoài". - Hình 2 ở góc trên bên phải: Vẽ một cây lúa. Cây có thân và lá, thân cây có rễ. Bên dưới hình là nhãn: "2 Cây lúa". - Hình 3 ở góc dưới bên trái: Vẽ một cây ngô. Cây có thân và lá, thân cây có rễ. Bên dưới hình là nhãn: "3 Cây ngô". - Hình 4 ở góc dưới bên phải: Vẽ một cây cam. Cây có thân và lá, thân cây có rễ. Bên dưới hình là nhãn: "4 Cây cam". Phía dưới các hình minh họa là biểu tượng dấu hỏi chấm màu đỏ cam kèm câu hỏi: "Kể tên một số cây khác có rễ cọc, rễ chìm mà em biết.". Góc dưới cùng bên trái trang sách có số trang "62". Dưới cùng là dòng chữ mờ "Đọc sách tại hoc10.vn".
|
| 91 |
+
|
| 92 |
+
</details>
|
| 93 |
+
|
| 94 |
+
---
|
| 95 |
+
|
| 96 |
+
## Kaggle notebooks (pipeline)
|
| 97 |
+
|
| 98 |
+
- [](https://www.kaggle.com/code/dangpham321/01-finetune-qwen-vl-config-a) **01 - Finetune**
|
| 99 |
+
- [](https://www.kaggle.com/code/hoangphann/02-infer-qwen-vl) **02 - Inference**
|
| 100 |
+
- [](https://www.kaggle.com/code/hoangphann/03a-qwen-vl-metrics-light) **03A - Metrics (Light):** Quote-CER, Concept-Rec, BLEU-4, METEOR
|
| 101 |
+
- [](https://www.kaggle.com/code/hoangphann/03b-qwen-vl-metrics-heavy) **03B - Metrics (Heavy):** BERTScore, LLM-Score
|
| 102 |
+
- [](https://www.kaggle.com/code/hoangphann/04-qwen-vl-merge-results) **04 - Merge results**
|
| 103 |
+
- [](https://www.kaggle.com/code/hoangphann/05-qwen-vl-deploy) **05 - Demo (Gradio)**
|
| 104 |
+
|
| 105 |
+
---
|
SGK_CanhDieu_TuNhienVaXaHoi_3_page_063.png
ADDED
|
Git LFS Details
|
adapter_config.json
ADDED
|
@@ -0,0 +1,43 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"alora_invocation_tokens": null,
|
| 3 |
+
"alpha_pattern": {},
|
| 4 |
+
"arrow_config": null,
|
| 5 |
+
"auto_mapping": null,
|
| 6 |
+
"base_model_name_or_path": "Qwen/Qwen2-VL-2B-Instruct",
|
| 7 |
+
"bias": "none",
|
| 8 |
+
"corda_config": null,
|
| 9 |
+
"ensure_weight_tying": false,
|
| 10 |
+
"eva_config": null,
|
| 11 |
+
"exclude_modules": null,
|
| 12 |
+
"fan_in_fan_out": false,
|
| 13 |
+
"inference_mode": true,
|
| 14 |
+
"init_lora_weights": true,
|
| 15 |
+
"layer_replication": null,
|
| 16 |
+
"layers_pattern": null,
|
| 17 |
+
"layers_to_transform": null,
|
| 18 |
+
"loftq_config": {},
|
| 19 |
+
"lora_alpha": 32,
|
| 20 |
+
"lora_bias": false,
|
| 21 |
+
"lora_dropout": 0.05,
|
| 22 |
+
"megatron_config": null,
|
| 23 |
+
"megatron_core": "megatron.core",
|
| 24 |
+
"modules_to_save": null,
|
| 25 |
+
"peft_type": "LORA",
|
| 26 |
+
"peft_version": "0.18.0",
|
| 27 |
+
"qalora_group_size": 16,
|
| 28 |
+
"r": 16,
|
| 29 |
+
"rank_pattern": {},
|
| 30 |
+
"revision": null,
|
| 31 |
+
"target_modules": [
|
| 32 |
+
"v_proj",
|
| 33 |
+
"q_proj",
|
| 34 |
+
"k_proj",
|
| 35 |
+
"o_proj"
|
| 36 |
+
],
|
| 37 |
+
"target_parameters": null,
|
| 38 |
+
"task_type": "CAUSAL_LM",
|
| 39 |
+
"trainable_token_indices": null,
|
| 40 |
+
"use_dora": false,
|
| 41 |
+
"use_qalora": false,
|
| 42 |
+
"use_rslora": false
|
| 43 |
+
}
|
adapter_model.safetensors
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:e874379f3140feda12e4e7d5b880046aa5c2a3535c74ff1b6dfcee69fc34fb82
|
| 3 |
+
size 17465792
|
run_config.json
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"created_at": "2026-01-03 01:00:58",
|
| 3 |
+
"preset": "A",
|
| 4 |
+
"dataset_id": "bbdontcry/vietnamese-image-captioning",
|
| 5 |
+
"model_id": "Qwen/Qwen2-VL-2B-Instruct",
|
| 6 |
+
"quantization": null,
|
| 7 |
+
"min_pixels": 200704,
|
| 8 |
+
"max_pixels": 802816,
|
| 9 |
+
"system_message": "Bạn là một Vision-Language Model hỗ trợ người khiếm thị bằng cách tạo mô tả ảnh bằng tiếng Việt cho trang sách giáo khoa. Chỉ mô tả những gì thấy trong ảnh, không suy đoán.Khi OCR, trích toàn bộ chữ nhìn thấy, theo thứ tự trên xuống dưới, trái sang phải",
|
| 10 |
+
"prompt_detail": "Hãy thuyết minh chi tiết trang SGK trong ảnh theo luồng đọc từ trên xuống dưới. Khi gặp chữ trong ảnh, hãy đưa vào đúng ngữ cảnh và trích nguyên văn trong ngoặc kép. Không suy luận.",
|
| 11 |
+
"gen": {
|
| 12 |
+
"max_new_tokens_detail": 256,
|
| 13 |
+
"temperature": 0.2,
|
| 14 |
+
"top_p": 0.9,
|
| 15 |
+
"do_sample": false
|
| 16 |
+
}
|
| 17 |
+
}
|