Update README.md
Browse files
README.md
CHANGED
@@ -1,202 +1,209 @@
|
|
1 |
---
|
2 |
-
base_model:
|
3 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
4 |
---
|
5 |
|
6 |
-
# Model Card for
|
7 |
-
|
8 |
<!-- Provide a quick summary of what the model is/does. -->
|
9 |
|
|
|
10 |
|
|
|
11 |
|
12 |
-
|
13 |
-
|
14 |
-
### Model Description
|
15 |
-
|
16 |
-
<!-- Provide a longer summary of what this model is. -->
|
17 |
|
|
|
|
|
18 |
|
|
|
|
|
|
|
|
|
|
|
19 |
|
20 |
-
|
21 |
-
- **Funded by [optional]:** [More Information Needed]
|
22 |
-
- **Shared by [optional]:** [More Information Needed]
|
23 |
-
- **Model type:** [More Information Needed]
|
24 |
-
- **Language(s) (NLP):** [More Information Needed]
|
25 |
-
- **License:** [More Information Needed]
|
26 |
-
- **Finetuned from model [optional]:** [More Information Needed]
|
27 |
|
28 |
-
|
29 |
-
|
30 |
-
|
31 |
-
|
32 |
-
- **Repository:** [More Information Needed]
|
33 |
-
- **Paper [optional]:** [More Information Needed]
|
34 |
-
- **Demo [optional]:** [More Information Needed]
|
35 |
|
36 |
## Uses
|
37 |
|
38 |
-
<!-- Address questions around how the model is intended to be used, including the foreseeable users of the model and those affected by the model. -->
|
39 |
-
|
40 |
### Direct Use
|
|
|
|
|
|
|
|
|
41 |
|
42 |
-
|
43 |
-
|
44 |
-
[More Information Needed]
|
45 |
-
|
46 |
-
### Downstream Use [optional]
|
47 |
-
|
48 |
-
<!-- This section is for the model use when fine-tuned for a task, or when plugged into a larger ecosystem/app -->
|
49 |
-
|
50 |
-
[More Information Needed]
|
51 |
|
52 |
### Out-of-Scope Use
|
53 |
-
|
54 |
-
|
55 |
-
|
56 |
-
[More Information Needed]
|
57 |
|
58 |
## Bias, Risks, and Limitations
|
59 |
|
60 |
-
|
|
|
61 |
|
62 |
-
|
|
|
|
|
63 |
|
64 |
-
###
|
|
|
|
|
65 |
|
66 |
-
|
67 |
|
68 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
69 |
|
70 |
## How to Get Started with the Model
|
71 |
|
72 |
-
|
73 |
-
|
74 |
-
[More Information Needed]
|
75 |
-
|
76 |
-
## Training Details
|
77 |
-
|
78 |
-
### Training Data
|
79 |
-
|
80 |
-
<!-- This should link to a Dataset Card, perhaps with a short stub of information on what the training data is all about as well as documentation related to data pre-processing or additional filtering. -->
|
81 |
-
|
82 |
-
[More Information Needed]
|
83 |
-
|
84 |
-
### Training Procedure
|
85 |
-
|
86 |
-
<!-- This relates heavily to the Technical Specifications. Content here should link to that section when it is relevant to the training procedure. -->
|
87 |
-
|
88 |
-
#### Preprocessing [optional]
|
89 |
-
|
90 |
-
[More Information Needed]
|
91 |
-
|
92 |
-
|
93 |
-
#### Training Hyperparameters
|
94 |
-
|
95 |
-
- **Training regime:** [More Information Needed] <!--fp32, fp16 mixed precision, bf16 mixed precision, bf16 non-mixed precision, fp16 non-mixed precision, fp8 mixed precision -->
|
96 |
-
|
97 |
-
#### Speeds, Sizes, Times [optional]
|
98 |
-
|
99 |
-
<!-- This section provides information about throughput, start/end time, checkpoint size if relevant, etc. -->
|
100 |
-
|
101 |
-
[More Information Needed]
|
102 |
-
|
103 |
-
## Evaluation
|
104 |
-
|
105 |
-
<!-- This section describes the evaluation protocols and provides the results. -->
|
106 |
-
|
107 |
-
### Testing Data, Factors & Metrics
|
108 |
-
|
109 |
-
#### Testing Data
|
110 |
-
|
111 |
-
<!-- This should link to a Dataset Card if possible. -->
|
112 |
-
|
113 |
-
[More Information Needed]
|
114 |
-
|
115 |
-
#### Factors
|
116 |
-
|
117 |
-
<!-- These are the things the evaluation is disaggregating by, e.g., subpopulations or domains. -->
|
118 |
-
|
119 |
-
[More Information Needed]
|
120 |
-
|
121 |
-
#### Metrics
|
122 |
-
|
123 |
-
<!-- These are the evaluation metrics being used, ideally with a description of why. -->
|
124 |
-
|
125 |
-
[More Information Needed]
|
126 |
-
|
127 |
-
### Results
|
128 |
-
|
129 |
-
[More Information Needed]
|
130 |
-
|
131 |
-
#### Summary
|
132 |
-
|
133 |
-
|
134 |
-
|
135 |
-
## Model Examination [optional]
|
136 |
|
137 |
-
|
138 |
|
139 |
-
|
140 |
|
141 |
-
|
|
|
|
|
142 |
|
143 |
-
|
144 |
|
145 |
-
|
|
|
|
|
146 |
|
147 |
-
|
148 |
-
- **Hours used:** [More Information Needed]
|
149 |
-
- **Cloud Provider:** [More Information Needed]
|
150 |
-
- **Compute Region:** [More Information Needed]
|
151 |
-
- **Carbon Emitted:** [More Information Needed]
|
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 |
-
### Framework versions
|
201 |
|
202 |
-
|
|
|
|
|
|
1 |
---
|
2 |
+
base_model:
|
3 |
+
- Qwen/Qwen2.5-32B-Instruct
|
4 |
+
datasets:
|
5 |
+
- Thaweewat/thai-med-pack
|
6 |
+
language:
|
7 |
+
- th
|
8 |
+
- en
|
9 |
+
library_name: transformers
|
10 |
+
license: apache-2.0
|
11 |
+
pipeline_tag: text-generation
|
12 |
+
tags:
|
13 |
+
- text-generation-inference
|
14 |
+
- sft
|
15 |
+
- trl
|
16 |
+
- 4-bit precision
|
17 |
+
- bitsandbytes
|
18 |
+
- LoRA
|
19 |
+
- Fine-Tuning with LoRA
|
20 |
+
- LLM
|
21 |
+
- GenAI
|
22 |
+
- medical
|
23 |
+
- medtech
|
24 |
+
- HealthGPT
|
25 |
+
- minddatatech.com
|
26 |
+
- NT Academy
|
27 |
+
new_version: amornpan/openthaigpt-MedChatModelv11
|
28 |
---
|
29 |
|
30 |
+
# 🇹🇭 **Model Card for Qwen2.5-32B-Instruct-medical-tuned**
|
|
|
31 |
<!-- Provide a quick summary of what the model is/does. -->
|
32 |
|
33 |
+
## <font color="blue">ℹ️ This version is significantly better than OpenThaiGPT!.</font>
|
34 |
|
35 |
+
## Qwen2.5-32B-Instruct for Thai Medical QA
|
36 |
|
37 |
+
This model is fine-tuned from `Qwen2.5-32B-Instruct` using Supervised Fine-Tuning (SFT) on the `Thaweewat/thai-med-pack` dataset. It is designed for medical question-answering tasks in Thai, providing accurate and contextual answers based on medical information.
|
|
|
|
|
|
|
|
|
38 |
|
39 |
+
## Model Description
|
40 |
+
This model was fine-tuned using Supervised Fine-Tuning (SFT) to enhance its capabilities for medical question answering in Thai. The base model is `Qwen2.5-32B-Instruct`, which has been optimized with domain-specific knowledge using the `Thaweewat/thai-med-pack` dataset.
|
41 |
|
42 |
+
- **Model type:** Causal Language Model (AutoModelForCausalLM)
|
43 |
+
- **Language(s):** Thai
|
44 |
+
- **License:** Apache License 2.0
|
45 |
+
- **Fine-tuned from model:** Qwen2.5-32B-Instruct
|
46 |
+
- **Dataset used for fine-tuning:** Thaweewat/thai-med-pack
|
47 |
|
48 |
+
### Model Sources
|
|
|
|
|
|
|
|
|
|
|
|
|
49 |
|
50 |
+
- **Repository:** https://huggingface.co/amornpan
|
51 |
+
- **Citing Repository:** https://huggingface.co/Aekanun
|
52 |
+
- **Base Model:** https://huggingface.co/Qwen/Qwen2.5-32B-Instruct
|
53 |
+
- **Dataset:** https://huggingface.co/datasets/Thaweewat/thai-med-pack
|
|
|
|
|
|
|
54 |
|
55 |
## Uses
|
56 |
|
|
|
|
|
57 |
### Direct Use
|
58 |
+
The model can be used directly for generating medical responses in Thai. It has been optimized for:
|
59 |
+
- Medical question-answering
|
60 |
+
- Providing clinical information
|
61 |
+
- Health-related dialogue generation
|
62 |
|
63 |
+
### Downstream Use
|
64 |
+
This model serves as a foundational model for medical assistance systems, chatbots, and applications related to healthcare in the Thai language.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
65 |
|
66 |
### Out-of-Scope Use
|
67 |
+
- This model should not be used for real-time diagnosis or emergency medical scenarios.
|
68 |
+
- It should not be relied upon for critical clinical decisions without human oversight, as it is not intended to replace professional medical advice.
|
|
|
|
|
69 |
|
70 |
## Bias, Risks, and Limitations
|
71 |
|
72 |
+
### Bias
|
73 |
+
- The model may reflect biases present in the dataset, especially regarding underrepresented medical conditions or topics.
|
74 |
|
75 |
+
### Risks
|
76 |
+
- Responses may contain inaccuracies due to the model's inherent limitations and the dataset used for fine-tuning.
|
77 |
+
- The model should not be used as the sole source of medical advice.
|
78 |
|
79 |
+
### Limitations
|
80 |
+
- Primarily limited to the medical domain.
|
81 |
+
- Sensitive to prompts and may generate off-topic responses for non-medical queries.
|
82 |
|
83 |
+
## Model Training Results:
|
84 |
|
85 |
+

|
86 |
+

|
87 |
+

|
88 |
+

|
89 |
+

|
90 |
+

|
91 |
+

|
92 |
+

|
93 |
+

|
94 |
|
95 |
## How to Get Started with the Model
|
96 |
|
97 |
+
This section provides a step-by-step guide to loading and using the model for generating medical responses in Thai.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
98 |
|
99 |
+
### 1. Install the Required Packages
|
100 |
|
101 |
+
Ensure that you have installed the required libraries:
|
102 |
|
103 |
+
```python
|
104 |
+
pip install torch transformers accelerate bitsandbytes
|
105 |
+
pip install --upgrade transformers huggingface_hub
|
106 |
|
107 |
+
[!pip install bitsandbytes --upgrade]
|
108 |
|
109 |
+
[!pip install --upgrade transformers huggingface_hub]
|
110 |
+
```
|
111 |
+
## 2. Load the Model and Tokenizer
|
112 |
|
113 |
+
You can load the model and tokenizer directly from Hugging Face using the following code:
|
|
|
|
|
|
|
|
|
114 |
|
115 |
+
```python
|
116 |
+
import torch
|
117 |
+
from transformers import AutoModelForCausalLM, AutoTokenizer, BitsAndBytesConfig
|
118 |
+
```
|
119 |
+
# Define the model path
|
120 |
+
model_path = 'amornpan/Qwen2.5-32B-MedChatModel'
|
121 |
|
122 |
+
# Load the tokenizer and model
|
123 |
+
tokenizer = AutoTokenizer.from_pretrained(model_path)
|
124 |
+
tokenizer.pad_token = tokenizer.eos_token
|
125 |
|
126 |
+
## 3. Prepare Your Input (Custom Prompt)
|
127 |
|
128 |
+
Create a custom medical prompt that you want the model to respond to:
|
129 |
|
130 |
+
```python
|
131 |
+
custom_prompt = "อาการของโรคเบาหวานมีอะไรบ้าง"
|
132 |
+
PROMPT = f'[INST] <คุณเป็นผู้ช่วยตอบคำถามทางการแพทย์ จงตอบคำถามอย่างถูกต้องและให้ข้อมูลที่เป็นประโยชน์ที่สุด<> {custom_prompt} [/INST]'
|
133 |
|
134 |
+
# Tokenize the input prompt
|
135 |
+
inputs = tokenizer(PROMPT, return_tensors="pt", padding=True, truncation=True)
|
136 |
+
```
|
137 |
|
138 |
+
## 4. Configure the Model for Efficient Loading (4-bit Quantization)
|
139 |
|
140 |
+
The model uses 4-bit precision for efficient inference. Here’s how to set up the configuration:
|
141 |
|
142 |
+
```python
|
143 |
+
bnb_config = BitsAndBytesConfig(
|
144 |
+
load_in_4bit=True,
|
145 |
+
bnb_4bit_quant_type="nf4",
|
146 |
+
bnb_4bit_compute_dtype=torch.float16
|
147 |
+
)
|
148 |
+
```
|
149 |
|
150 |
+
## 5. Load the Model with Quantization Support
|
151 |
|
152 |
+
Now, load the model with the 4-bit quantization settings:
|
153 |
|
154 |
+
```python
|
155 |
+
model = AutoModelForCausalLM.from_pretrained(
|
156 |
+
model_path,
|
157 |
+
quantization_config=bnb_config,
|
158 |
+
trust_remote_code=True
|
159 |
+
)
|
160 |
+
```
|
161 |
|
162 |
+
## 6. Move the Model and Inputs to the GPU (prefer GPU)
|
163 |
|
164 |
+
For faster inference, move the model and input tensors to a GPU, if available:
|
165 |
|
166 |
+
```python
|
167 |
+
device = torch.device("cuda" if torch.cuda.is_available() else "cpu")
|
168 |
+
model.to(device)
|
169 |
+
inputs = {k: v.to(device) for k, v in inputs.items()}
|
170 |
+
```
|
171 |
|
172 |
+
## 7. Generate a Response from the Model
|
173 |
|
174 |
+
Now, generate the medical response by running the model:
|
175 |
|
176 |
+
```python
|
177 |
+
outputs = model.generate(**inputs, max_new_tokens=256, do_sample=True)
|
178 |
+
```
|
179 |
|
180 |
+
## 8. Decode the Generated Text
|
181 |
|
182 |
+
Finally, decode and print the response from the model:
|
183 |
|
184 |
+
```python
|
185 |
+
generated_text = tokenizer.decode(outputs[0], skip_special_tokens=True)
|
186 |
+
print(generated_text)
|
187 |
+
```
|
188 |
|
189 |
+
## 9. Output
|
190 |
+
```python
|
191 |
+
คำถาม: การรักษาโรคความดันโลหิตสูงทำอย่างไร
|
192 |
+
คำตอบ: สวัสดี ความดันโลหิตสูงสามารถรักษาได้โดยการใช้ยาหลายชนิด เช่น เบนโซเพอรีซิน, อะโมโลนิด, ลิโซโปรตาซอล, อีลาฟอร์เท็ต,
|
193 |
+
อัลฟูราลิท, อะเซติซิลดิโพราเมต, อาราคานา, อาเนอโรนิก, อาเซติซิลสัมพันธ์, อาเนอโรนิก, อะเซติซิลสัมพันธ์ เป็นต้น
|
194 |
+
คุณสามารถปรึกษาแพทย์ผู้เชี่ยวชาญในเรื่องนี้เพื่อทราบข้อมูลเพิ่มเติมเกี่ยวกับยาดังกล่าว หวังว่าคำตอบของฉันจะเป็นประโยชน์สำหรับคุณ
|
195 |
+
ขอให้คุณมีสุขภาพที่ดี ขอบคุณที่เลือกใช้บริการของเรา หากคุณมีคำถามใด ๆ
|
196 |
|
197 |
+
คำถาม: ยา Paracetamol มีผลข้างเคียงอะไรบ้าง
|
198 |
+
คำตอบ: Paracetamol เป็นยาแก้ปวดและลดไข้ที่ใช้กันอย่างแพร่หลาย ซึ่งมีผลข้างเคียงน้อยกว่ายาแก้ปวดชนิดอื่นๆ โดยทั่วไปจะไม่มีผลข้างเคียงใดๆ
|
199 |
+
หากใช้ในขนาดที่แนะนำ แต่อาจพบได้ เช่น ปวดท้อง อาเจียน และรู้สึกคลื่นไส้ นอกจากนี้ หากใช้ในปริมาณที่มากเกินไป อาจทำให้มีอาการปัสสาวะขุ่น
|
200 |
+
มีสีเหลืองเข้ม เบื่ออาหาร คลื่นไส้ อาเจียน ปวดท้อง ปวดหัว ตาเหลือง หรือปัสสาวะสีเข้มเป็นสีชาโคล่า
|
201 |
+
หากมีอาการดังกล่าวควรหยุดการใช้ยาและรีบไปพบแพทย์เพื่อตรวจหาความเสียหายของตับจากยา
|
202 |
+
โดยการตรวจการทำงานของตับ ซึ่งหากพบว่ามีอาการของโรคตับวายเฉียบพลัน
|
203 |
+
```
|
204 |
|
205 |
+
### 👤 **Authors**
|
|
|
206 |
|
207 |
+
* Amornpan Phornchaicharoen (amornpan@gmail.com)
|
208 |
+
* Aekanun Thongtae ([email protected])
|
209 |
+
* Montita Somsoo ([email protected])
|