Update README.md
Browse files
README.md
CHANGED
@@ -65,64 +65,88 @@ The Bllossom language model is a Korean-English bilingual language model based o
|
|
65 |
pip install torch transformers==4.40.0 accelerate
|
66 |
```
|
67 |
|
68 |
-
### Python code with
|
69 |
```python
|
70 |
-
import
|
|
|
71 |
import torch
|
72 |
|
73 |
-
|
|
|
74 |
|
75 |
-
|
76 |
-
"text-generation",
|
77 |
-
model=model_id,
|
78 |
-
model_kwargs={"torch_dtype": torch.bfloat16},
|
79 |
-
device_map="auto",
|
80 |
-
)
|
81 |
|
82 |
-
|
|
|
83 |
|
84 |
-
|
85 |
-
instruction = "서울의 유명한 관광 코스를 만들어줄래?"
|
86 |
|
|
|
|
|
87 |
messages = [
|
88 |
-
{
|
89 |
-
{
|
90 |
-
|
91 |
|
92 |
-
|
93 |
-
messages,
|
94 |
-
tokenize=False,
|
95 |
-
add_generation_prompt=True
|
96 |
-
)
|
97 |
|
98 |
-
|
99 |
-
|
100 |
-
|
101 |
-
|
|
|
102 |
|
103 |
-
|
104 |
-
|
105 |
-
max_new_tokens=
|
106 |
-
|
107 |
-
do_sample=True,
|
108 |
-
temperature=0.6,
|
109 |
-
top_p=0.9
|
110 |
-
)
|
111 |
|
112 |
-
print(
|
113 |
-
```
|
114 |
```
|
115 |
-
# 물론이죠! 서울은 다양한 문화와 역사, 자연을 겸비한 도시로, 많은 관광 명소를 자랑합니다. 여기 서울의 유명한 관광 코스를 소개해 드릴게요.
|
116 |
|
117 |
-
###
|
|
|
|
|
|
|
|
|
|
|
|
|
118 |
|
119 |
-
|
120 |
-
- 서울의 대표적인 궁궐로, 조선 왕조의 역사와 문화를 체험할 수 있는 곳입니다.
|
121 |
|
122 |
-
|
123 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
124 |
|
125 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
126 |
```
|
127 |
|
128 |
## Supported by
|
|
|
65 |
pip install torch transformers==4.40.0 accelerate
|
66 |
```
|
67 |
|
68 |
+
### Python code with Image
|
69 |
```python
|
70 |
+
from PIL import Image
|
71 |
+
from transformers import LlavaNextForConditionalGeneration,LlavaNextProcessor
|
72 |
import torch
|
73 |
|
74 |
+
model = LlavaNextForConditionalGeneration.from_pretrained('Bllossom/llama-3.1-Korean-Bllossom-Vision-8B', torch_dtype=torch.bfloat16)
|
75 |
+
processor = LlavaNextProcessor.from_pretrained('Bllossom/llama-3.1-Korean-Bllossom-Vision-8B', torch_dtype=torch.bfloat16)
|
76 |
|
77 |
+
image = Image.open('[IMAGE_PATH]').convert('RGB')
|
|
|
|
|
|
|
|
|
|
|
78 |
|
79 |
+
PROMPT=\
|
80 |
+
"""You are a versatile AI assistant named Bllava, capable of both understanding and generating text as well as interpreting and analyzing images. Your role is to kindly and effectively answer the user’s questions, whether they are about text or images, and provide appropriate and helpful responses to all types of queries.
|
81 |
|
82 |
+
당신은 텍스트를 이해하고 생성하는 것뿐만 아니라 이미지를 해석하고 분석할 수 있는 다재다능한 AI 어시스턴트 블라바입니다. 사용자의 질문이 텍스트에 관한 것이든 이미지에 관한 것이든 친절하고 효과적으로 답변하며, 모든 유형의 질의에 대해 적절하고 유용한 응답을 제공하는 것이 당신의 역할입니다."""
|
|
|
83 |
|
84 |
+
|
85 |
+
instruction = '이미지에 대해서 설명해주세요.'
|
86 |
messages = [
|
87 |
+
{'role': 'system', 'content': f"{PROMPT}"},
|
88 |
+
{'role': 'user', 'content': f"<image>\n{instruction}"}
|
89 |
+
]
|
90 |
|
91 |
+
chat_messages = processor.tokenizer.apply_chat_template(messages,tokenize=False,add_generation_prompt=True)
|
|
|
|
|
|
|
|
|
92 |
|
93 |
+
inputs = processor(
|
94 |
+
chat_messages,
|
95 |
+
image,
|
96 |
+
return_tensors='pt',
|
97 |
+
).to('cuda:0')
|
98 |
|
99 |
+
output = model.generate(
|
100 |
+
**inputs,
|
101 |
+
max_new_tokens=1024,
|
102 |
+
)
|
|
|
|
|
|
|
|
|
103 |
|
104 |
+
print(processor.tokenizer.decode(output[0]))
|
|
|
105 |
```
|
|
|
106 |
|
107 |
+
### Python code No Image
|
108 |
+
```python
|
109 |
+
from transformers import LlavaNextForConditionalGeneration,LlavaNextProcessor
|
110 |
+
import torch
|
111 |
+
|
112 |
+
model = LlavaNextForConditionalGeneration.from_pretrained('Bllossom/llama-3.1-Korean-Bllossom-Vision-8B', torch_dtype=torch.bfloat16)
|
113 |
+
processor = LlavaNextProcessor.from_pretrained('Bllossom/llama-3.1-Korean-Bllossom-Vision-8B', torch_dtype=torch.bfloat16)
|
114 |
|
115 |
+
with torch.no_grad():
|
|
|
116 |
|
117 |
+
PROMPT=\
|
118 |
+
"""You are a versatile AI assistant named Bllava, capable of both understanding and generating text as well as interpreting and analyzing images. Your role is to kindly and effectively answer the user’s questions, whether they are about text or images, and provide appropriate and helpful responses to all types of queries.
|
119 |
+
|
120 |
+
당신은 텍스트를 이해하고 생성하는 것뿐만 아니라 이미지를 해석하고 분석할 수 있는 다재다능한 AI 어시스턴트 블라바입니다. 사용자의 질문이 텍스트에 관한 것이든 이미지에 관한 것이든 친절하고 효과적으로 답변하며, 모든 유형의 질의에 대해 적절하고 유용한 응답을 제공하는 것이 당신의 역할입니다."""
|
121 |
+
|
122 |
+
instruction = '자연어처리 15주 분량 커리큘럼을 짜줘'
|
123 |
+
|
124 |
+
messages = [
|
125 |
+
{'role': 'system', 'content': f"{PROMPT}"},
|
126 |
+
{'role': 'user', 'content': f"{instruction}"}
|
127 |
+
]
|
128 |
|
129 |
+
chat_messages = processor.tokenizer.apply_chat_template(
|
130 |
+
messages,
|
131 |
+
tokenize=True,
|
132 |
+
add_generation_prompt=True,
|
133 |
+
return_tensors='pt',
|
134 |
+
)
|
135 |
+
|
136 |
+
bos_token = processor.tokenizer.bos_token_id
|
137 |
+
chat_messages = torch.cat([torch.tensor([[bos_token]]),chat_messages],dim=-1).to('cuda:0')
|
138 |
+
|
139 |
+
|
140 |
+
output = model.generate(
|
141 |
+
input_ids = chat_messages,
|
142 |
+
use_cache=False,
|
143 |
+
max_new_tokens=2048,
|
144 |
+
top_p=0.9,
|
145 |
+
temperature=0.6,
|
146 |
+
do_sample=True,
|
147 |
+
)
|
148 |
+
|
149 |
+
print(processor.tokenizer.decode(output[0]))
|
150 |
```
|
151 |
|
152 |
## Supported by
|