Update README.md
Browse files
README.md
CHANGED
@@ -1,3 +1,151 @@
|
|
1 |
-
---
|
2 |
-
license: cc-by-nc-4.0
|
3 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
---
|
2 |
+
license: cc-by-nc-4.0
|
3 |
+
language:
|
4 |
+
- ja
|
5 |
+
pipeline_tag: image-to-text
|
6 |
+
tags:
|
7 |
+
- vision
|
8 |
+
- image-captioning
|
9 |
+
- VQA
|
10 |
+
---
|
11 |
+
|
12 |
+
# Chat-Vector-LLaVA-v1.5-7b-JA Model Card
|
13 |
+
## Model detail
|
14 |
+
**Model type:**
|
15 |
+
Chat-Vector-LLaVA-v1.5-7b-JA is a vision-language model that can converse about input images in Japanese.<br>
|
16 |
+
This model was created by adding and subtracting the weights of the [llava-v1.5-7b](https://huggingface.co/liuhaotian/llava-v1.5-7b), [Llama-2-7b-hf](https://huggingface.co/meta-llama/Llama-2-7b-hf), and [ELYZA-japanese-Llama-2-7b](https://huggingface.co/elyza/ELYZA-japanese-Llama-2-7b) models using the Chat Vector method as follows.
|
17 |
+
```
|
18 |
+
ELYZA-japanese-Llama-2-7b + (llava-v1.5-7b - Llama-2-7b-hf)
|
19 |
+
```
|
20 |
+
|
21 |
+
Chat-Vector-LLaVA-v1.5-7b-JAは、入力画像について日本語で会話できるvision-language modelです。<br>
|
22 |
+
このモデルはChat Vectorの手法で[llava-v1.5-7b](https://huggingface.co/liuhaotian/llava-v1.5-7b)と[Llama-2-7b-hf](https://huggingface.co/meta-llama/Llama-2-7b-hf)と[ELYZA-japanese-Llama-2-7b](https://huggingface.co/elyza/ELYZA-japanese-Llama-2-7b)のモデルの重みを以下の通り加減算することで作成しました。
|
23 |
+
```
|
24 |
+
ELYZA-japanese-Llama-2-7b + (llava-v1.5-7b - Llama-2-7b-hf)
|
25 |
+
```
|
26 |
+
|
27 |
+
**Comparing VLMs**
|
28 |
+
|Model|JA-VG-VQA-500<br>(ROUGE-L)|JA-VLM-Bench-In-the-Wild<br>(ROUGE-L)|Heron-Bench(Detail)|Heron-Bench(Conv)|Heron-Bench(Complex)|Heron-Bench(Average)
|
29 |
+
|-|-|-|-|-|-|-|
|
30 |
+
|[Japanese Stable VLM](https://huggingface.co/stabilityai/japanese-stable-vlm)|-|40.50|25.15|51.23|37.84|38.07|
|
31 |
+
|[EvoVLM-JP-v1-7B](https://huggingface.co/SakanaAI/EvoVLM-JP-v1-7B)|**19.70**|**51.25**|50.31|44.42|40.47|45.07|
|
32 |
+
|[Heron BLIP Japanese StableLM Base 7B llava-620k](https://huggingface.co/turing-motors/heron-chat-blip-ja-stablelm-base-7b-v1-llava-620k)|14.51|33.26|49.09|41.51|45.72|45.44|
|
33 |
+
|[Heron GIT Japanese StableLM Base 7B](https://huggingface.co/turing-motors/heron-chat-git-ja-stablelm-base-7b-v1)|15.18|37.82|42.77|**54.20**|43.53|46.83|
|
34 |
+
|[llava-jp-1.3b-v1.0-620k](https://huggingface.co/toshi456/llava-jp-1.3b-v1.0-620k)|12.69|44.58|51.21|41.05|45.95|44.84|
|
35 |
+
|[llava-jp-1.3b-v1.1](https://huggingface.co/toshi456/llava-jp-1.3b-v1.1)|13.33|44.40|50.00|51.83|**48.98**|**50.39**|
|
36 |
+
|[chat-vector-llava-v1.5-7b-ja](https://huggingface.co/toshi456/chat-vector-llava-v1.5-7b-ja)|18.64|42.23|**53.61**|44.36|44.48|46.10|
|
37 |
+
|
38 |
+
|
39 |
+
![image/png](https://cdn-uploads.huggingface.co/production/uploads/630af71ffaaea618ebc973db/jSW9RYPccrxaqrxntwtUb.png)
|
40 |
+
|
41 |
+
## How to use the model
|
42 |
+
**1. Download dependencies**
|
43 |
+
```
|
44 |
+
git clone https://github.com/tosiyuki/vlm-chat-vector-ja.git
|
45 |
+
```
|
46 |
+
|
47 |
+
**2. Inference**
|
48 |
+
```python
|
49 |
+
import requests
|
50 |
+
import torch
|
51 |
+
import transformers
|
52 |
+
from PIL import Image
|
53 |
+
|
54 |
+
from transformers.generation.streamers import TextStreamer
|
55 |
+
from llava.constants import DEFAULT_IMAGE_TOKEN, IMAGE_TOKEN_INDEX
|
56 |
+
from llava.conversation import conv_templates, SeparatorStyle
|
57 |
+
from llava.model.language_model.llava_llama import LlavaLlamaForCausalLM
|
58 |
+
from llava.mm_utils import tokenizer_image_token, process_images
|
59 |
+
|
60 |
+
|
61 |
+
if __name__ == "__main__":
|
62 |
+
model_path = 'toshi456/chat-vector-llava-v1.5-7b-ja'
|
63 |
+
device = "cuda" if torch.cuda.is_available() else "cpu"
|
64 |
+
torch_dtype = torch.bfloat16 if device=="cuda" else torch.float32
|
65 |
+
|
66 |
+
model = LlavaLlamaForCausalLM.from_pretrained(
|
67 |
+
model_path,
|
68 |
+
device_map=device,
|
69 |
+
low_cpu_mem_usage=True,
|
70 |
+
use_safetensors=True,
|
71 |
+
torch_dtype=torch.float16,
|
72 |
+
).eval()
|
73 |
+
tokenizer = transformers.AutoTokenizer.from_pretrained(
|
74 |
+
model_path,
|
75 |
+
model_max_length=1024,
|
76 |
+
padding_side="right",
|
77 |
+
use_fast=False,
|
78 |
+
)
|
79 |
+
model.get_model().vision_tower.load_model()
|
80 |
+
model = model.to(device)
|
81 |
+
|
82 |
+
eos_token_id_list = [
|
83 |
+
tokenizer.eos_token_id,
|
84 |
+
tokenizer.bos_token_id,
|
85 |
+
]
|
86 |
+
|
87 |
+
# image pre-process
|
88 |
+
image_url = "https://huggingface.co/rinna/bilingual-gpt-neox-4b-minigpt4/resolve/main/sample.jpg"
|
89 |
+
image = Image.open(requests.get(image_url, stream=True).raw).convert('RGB')
|
90 |
+
|
91 |
+
if not isinstance(image, list):
|
92 |
+
image = [image]
|
93 |
+
|
94 |
+
image_tensor = process_images(image, model.get_model().vision_tower.image_processor, model.config)
|
95 |
+
if type(image_tensor) is list:
|
96 |
+
image_tensor = [image.to(model.device, dtype=torch.float16) for image in image_tensor]
|
97 |
+
else:
|
98 |
+
image_tensor = image_tensor.to(model.device, dtype=torch.float16)
|
99 |
+
|
100 |
+
# create prompt
|
101 |
+
# ユーザー: <image>\n{prompt}
|
102 |
+
conv_mode = "llava_llama_2"
|
103 |
+
conv = conv_templates[conv_mode].copy()
|
104 |
+
prompt = "猫の隣には何がありますか?"
|
105 |
+
inp = DEFAULT_IMAGE_TOKEN + '\n' + prompt
|
106 |
+
conv.append_message(conv.roles[0], inp)
|
107 |
+
conv.append_message(conv.roles[1], None)
|
108 |
+
prompt = conv.get_prompt()
|
109 |
+
|
110 |
+
input_ids = tokenizer_image_token(
|
111 |
+
prompt,
|
112 |
+
tokenizer,
|
113 |
+
IMAGE_TOKEN_INDEX,
|
114 |
+
return_tensors='pt'
|
115 |
+
).unsqueeze(0)
|
116 |
+
if device == "cuda":
|
117 |
+
input_ids = input_ids.to(device)
|
118 |
+
|
119 |
+
stop_str = conv.sep if conv.sep_style != SeparatorStyle.TWO else conv.sep2
|
120 |
+
keywords = [stop_str]
|
121 |
+
streamer = TextStreamer(tokenizer, skip_prompt=True, timeout=20.0)
|
122 |
+
|
123 |
+
# parameter
|
124 |
+
temperature = 0.0
|
125 |
+
top_p = 1.0
|
126 |
+
max_new_tokens=256
|
127 |
+
|
128 |
+
# predict
|
129 |
+
with torch.inference_mode():
|
130 |
+
model.generate(
|
131 |
+
inputs=input_ids,
|
132 |
+
images=image_tensor,
|
133 |
+
do_sample=True if temperature > 0 else False,
|
134 |
+
temperature=temperature,
|
135 |
+
top_p=top_p,
|
136 |
+
max_new_tokens=max_new_tokens,
|
137 |
+
streamer=streamer,
|
138 |
+
use_cache=True,
|
139 |
+
eos_token_id=eos_token_id_list,
|
140 |
+
)
|
141 |
+
|
142 |
+
"""猫の隣には、コンピューター(パソコン)があります。<s>"""
|
143 |
+
|
144 |
+
```
|
145 |
+
|
146 |
+
## Acknowledgement
|
147 |
+
- [LLaVA](https://llava-vl.github.io/)
|
148 |
+
- [Chat Vector](https://arxiv.org/abs/2310.04799)
|
149 |
+
|
150 |
+
## License
|
151 |
+
cc-by-nc-4.0
|