Update README.md
Browse files
README.md
CHANGED
@@ -115,31 +115,41 @@ This model serves as a foundational model for medical assistance systems, chatbo
|
|
115 |
This section provides a step-by-step guide to loading and using the model for generating medical responses in Thai.
|
116 |
|
117 |
|
118 |
-
|
|
|
|
|
119 |
|
120 |
```python
|
121 |
-
#
|
122 |
-
|
123 |
-
from transformers import AutoModelForCausalLM, AutoTokenizer
|
124 |
```
|
125 |
|
126 |
-
|
|
|
|
|
|
|
|
|
127 |
```
|
128 |
-
#Set the model to amornpan/V3_qwen2.5-32b-med-thai-optimized
|
129 |
-
base_model_name = "amornpan/V3_qwen2.5-32b-med-thai-optimized"
|
130 |
|
131 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
132 |
model = AutoModelForCausalLM.from_pretrained(
|
133 |
base_model_name,
|
134 |
device_map="auto",
|
135 |
-
trust_remote_code=True
|
|
|
136 |
)
|
137 |
tokenizer = AutoTokenizer.from_pretrained(base_model_name, trust_remote_code=True)
|
138 |
```
|
139 |
|
140 |
-
|
141 |
-
|
142 |
-
|
143 |
def test_model(prompt, max_new_tokens=256):
|
144 |
system_prompt = "You are a question answering assistant. Answer the question as truthful and helpful as possible. คุณคือผู้ช่วยตอบคำถาม จงตอบคำถามอย่างถูกต้องและมีประโยชน์ที่สุด"
|
145 |
full_prompt = f"<s><|im_start|>system\n{system_prompt}<|im_end|>\n<|im_start|>user\n{prompt}<|im_end|>\n<|im_start|>assistant\n"
|
@@ -156,24 +166,32 @@ def test_model(prompt, max_new_tokens=256):
|
|
156 |
)
|
157 |
|
158 |
response = tokenizer.decode(generated_ids[0], skip_special_tokens=False)
|
159 |
-
|
160 |
assistant_response = response.split("<|im_start|>assistant\n")[-1].split("<|im_end|>")[0]
|
161 |
|
162 |
return assistant_response
|
163 |
```
|
164 |
|
165 |
-
|
166 |
-
|
167 |
-
```
|
168 |
-
#
|
169 |
example_question = "อาการของโรคเบาหวานมีอะไรบ้าง"
|
170 |
print(f"\nคำถาม: {example_question}")
|
171 |
response = test_model(example_question)
|
172 |
print(f"คำตอบ: {response}")
|
173 |
```
|
174 |
|
175 |
-
|
176 |
```python
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
177 |
คำถาม: การรักษาโรคความดันโลหิตสูงทำอย่างไร
|
178 |
คำตอบ: สวัสดี ความดันโลหิตสูงสามารถรักษาได้โดยการใช้ยาหลายชนิด เช่น เบนโซเพอรีซิน, อะโมโลนิด, ลิโซโปรตาซอล, อีลาฟอร์เท็ต,
|
179 |
อัลฟูราลิท, อะเซติซิลดิโพราเมต, อาราคานา, อาเนอโรนิก, อาเซติซิลสัมพันธ์, อาเนอโรนิก, อะเซติซิลสัมพันธ์ เป็นต้น
|
|
|
115 |
This section provides a step-by-step guide to loading and using the model for generating medical responses in Thai.
|
116 |
|
117 |
|
118 |
+
# Qwen 2.5 32B Thai Medical Model
|
119 |
+
|
120 |
+
## Installation Requirements
|
121 |
|
122 |
```python
|
123 |
+
# Install required libraries if not already installed
|
124 |
+
pip install transformers torch peft
|
|
|
125 |
```
|
126 |
|
127 |
+
## Import Libraries
|
128 |
+
|
129 |
+
```python
|
130 |
+
import os
|
131 |
+
from transformers import AutoModelForCausalLM, AutoTokenizer
|
132 |
```
|
|
|
|
|
133 |
|
134 |
+
## Load Model with Disk Offloading
|
135 |
+
|
136 |
+
```python
|
137 |
+
# Create a directory for offloading model weights
|
138 |
+
os.makedirs("offload_dir", exist_ok=True)
|
139 |
+
|
140 |
+
base_model_name = "amornpan/V3_qwen2.5-32b-med-thai-optimized"
|
141 |
model = AutoModelForCausalLM.from_pretrained(
|
142 |
base_model_name,
|
143 |
device_map="auto",
|
144 |
+
trust_remote_code=True,
|
145 |
+
offload_folder="offload_dir" # Specify the offload directory
|
146 |
)
|
147 |
tokenizer = AutoTokenizer.from_pretrained(base_model_name, trust_remote_code=True)
|
148 |
```
|
149 |
|
150 |
+
## Define Test Function
|
151 |
+
|
152 |
+
```python
|
153 |
def test_model(prompt, max_new_tokens=256):
|
154 |
system_prompt = "You are a question answering assistant. Answer the question as truthful and helpful as possible. คุณคือผู้ช่วยตอบคำถาม จงตอบคำถามอย่างถูกต้องและมีประโยชน์ที่สุด"
|
155 |
full_prompt = f"<s><|im_start|>system\n{system_prompt}<|im_end|>\n<|im_start|>user\n{prompt}<|im_end|>\n<|im_start|>assistant\n"
|
|
|
166 |
)
|
167 |
|
168 |
response = tokenizer.decode(generated_ids[0], skip_special_tokens=False)
|
169 |
+
|
170 |
assistant_response = response.split("<|im_start|>assistant\n")[-1].split("<|im_end|>")[0]
|
171 |
|
172 |
return assistant_response
|
173 |
```
|
174 |
|
175 |
+
## Test the Model
|
176 |
+
|
177 |
+
```python
|
178 |
+
# ทดสอบโมเดล
|
179 |
example_question = "อาการของโรคเบาหวานมีอะไรบ้าง"
|
180 |
print(f"\nคำถาม: {example_question}")
|
181 |
response = test_model(example_question)
|
182 |
print(f"คำตอบ: {response}")
|
183 |
```
|
184 |
|
185 |
+
## Output
|
186 |
```python
|
187 |
+
คำถาม: อาการของโรคเบาหวานมีอะไรบ้าง
|
188 |
+
คำตอบ: สวัสดี โรคเบาหวานเป็นโรคทางระบบเมตาบอลิซึม โดยเกิดจากภาวะการผลิตฮอร์โมนอินซูลินไม่เพียงพอ
|
189 |
+
หรือร่างกายไม่สามารถใช้อินซูลินได้อย่างมีประสิทธิภาพ ทำให้ระดับน้ำตาลในเลือดสูงขึ้น ซึ่งอาจนำไปสู่ความเสียหายของอวัยวะต่างๆ
|
190 |
+
ในร่างกายได้ โดยเฉพาะหัวใจ เลือด เยื่อบุตา และไต เมื่อระดับน้ำตาลในเลือดสูงขึ้นมากขึ้นเรื่อยๆ จะมีอาการทางคลินิก เช่น
|
191 |
+
1. มีปัสสาวะบ่อย ปัสสาวะมาก เนื่องจากต้องขับน้ำตาลออกทางปัสสาวะ
|
192 |
+
2. กระหายน้ำมาก เนื่องจากมีปัสสาวะมาก
|
193 |
+
3. อ่อนแรง หมดแรง
|
194 |
+
|
195 |
คำถาม: การรักษาโรคความดันโลหิตสูงทำอย่างไร
|
196 |
คำตอบ: สวัสดี ความดันโลหิตสูงสามารถรักษาได้โดยการใช้ยาหลายชนิด เช่น เบนโซเพอรีซิน, อะโมโลนิด, ลิโซโปรตาซอล, อีลาฟอร์เท็ต,
|
197 |
อัลฟูราลิท, อะเซติซิลดิโพราเมต, อาราคานา, อาเนอโรนิก, อาเซติซิลสัมพันธ์, อาเนอโรนิก, อะเซติซิลสัมพันธ์ เป็นต้น
|