amornpan commited on
Commit
c3ad444
·
verified ·
1 Parent(s): ce067e9

Update README.md

Browse files
Files changed (1) hide show
  1. README.md +66 -94
README.md CHANGED
@@ -30,22 +30,22 @@ tags:
30
  new_version: Aekanun/openthaigpt-MedChatModelv5.1
31
  ---
32
 
33
- # 🇹🇭 Model Card for `openthaigpt1.5-7b-medical-tuned`
34
  <!-- Provide a quick summary of what the model is/does. -->
35
- This model is fine-tuned from `openthaigpt1.5-7b-instruct` using Supervised Fine-Tuning (SFT) on the `Thaweewat/thai-med-pack` dataset. The model is designed for medical question-answering tasks in Thai, specializing in providing accurate and contextual answers based on medical information.
36
 
37
  ## 👤 **Developed and Fine-tuned by:**
38
  - **Amornpan Phornchaicharoen**
39
  - **Aekanun Thongtae**
40
 
41
  ## Model Description
42
- This model was fine-tuned using Supervised Fine-Tuning (SFT) to optimize it for medical question answering in Thai. The base model is `openthaigpt1.5-7b-instruct`, and it has been enhanced with domain-specific knowledge using the `Thaweewat/thai-med-pack` dataset.
43
 
44
  - **Model type:** Causal Language Model (AutoModelForCausalLM)
45
  - **Language(s):** Thai
46
  - **License:** Apache License 2.0
47
- - **Fine-tuned from model:** `openthaigpt1.5-7b-instruct`
48
- - **Dataset used for fine-tuning:** `Thaweewat/thai-med-pack`
49
 
50
  ### Model Sources
51
 
@@ -97,120 +97,92 @@ This model can be used as a foundational model for medical assistance systems, c
97
 
98
  ## How to Get Started with the Model
99
 
100
- Here’s how you can start using the model in your project:
101
 
102
- ```python
 
 
 
 
 
 
 
 
 
 
 
103
  import torch
104
  from transformers import AutoModelForCausalLM, AutoTokenizer, BitsAndBytesConfig
105
- ```
106
 
107
- # Configure the model name
108
- ```python
109
- model_name = "amornpan/openthaigpt-MedChatModelv11.1"
110
- ```
 
 
 
 
 
 
 
 
 
 
 
 
 
 
111
 
112
- # Set up quantization (optional for saving RAM)
113
- ```python
 
 
 
114
  bnb_config = BitsAndBytesConfig(
115
  load_in_4bit=True,
116
  bnb_4bit_quant_type="nf4",
117
- bnb_4bit_compute_dtype=torch.float16,
118
  )
119
- ```
120
 
121
- # Load the model and tokenizer
122
- ```python
123
- print("Loading model and tokenizer...")
 
 
124
  model = AutoModelForCausalLM.from_pretrained(
125
- model_name,
126
  quantization_config=bnb_config,
127
- trust_remote_code=True,
128
- device_map="auto"
129
- )
130
-
131
- tokenizer = AutoTokenizer.from_pretrained(
132
- model_name,
133
  trust_remote_code=True
134
  )
135
- tokenizer.pad_token = tokenizer.eos_token
136
- ```
137
-
138
- # Function to generate responses
139
- ```python
140
- def generate_response(prompt, max_new_tokens=256):
141
- PROMPT = f'[INST] <You are a question answering assistant. Answer the question as truthful and helpful as possible คุณคือผู้ช่วยตอบคำถาม จงตอบคำถามอย่างถูกต้องและมีประโยชน์ที่สุด<>{prompt}[/INST]'
142
-
143
- inputs = tokenizer(PROMPT, return_tensors="pt").to(model.device)
144
-
145
- generation_config = {
146
- "temperature": 0.6,
147
- "top_p": 0.95,
148
- "repetition_penalty": 1.15,
149
- "max_new_tokens": max_new_tokens,
150
- "pad_token_id": tokenizer.eos_token_id
151
- }
152
-
153
- with torch.no_grad():
154
- generation_output = model.generate(
155
- **inputs,
156
- **generation_config
157
- )
158
-
159
- response = tokenizer.decode(generation_output[0], skip_special_tokens=True)
160
- response = response.split("[/INST]")[-1].strip()
161
- return response
162
- ```
163
-
164
- # Example usage
165
- ```python
166
- if __name__ == "__main__":
167
- questions = [
168
- "โปรดอธิบายลักษณะช่องปากที่เป็นมะเร็งในระยะเริ่มต้น",
169
- "อาการของโรคไข้เลือดออกมีอะไรบ้าง"
170
- ]
171
-
172
- print("Testing question answering:")
173
- for question in questions:
174
- print("\nQuestion: ", question)
175
- answer = generate_response(question)
176
- print("Answer: ", answer)
177
- print("-" * 50)
178
- ```
179
-
180
- ## 9. Output
181
 
182
- ```python
183
- คำถาม: โปรดอธิบายลักษณะช่องปากที่เป็นมะเร็งในระยะเริ่มต้น
184
- /usr/local/lib/python3.10/dist-packages/transformers/generation/configuration_utils.py:590: UserWarning: `do_sample` is set to `False`. However, `temperature` is set to `0.6` -- this flag is only used in sample-based generation modes. You should set `do_sample=True` or unset `temperature`.
185
- warnings.warn(
186
- /usr/local/lib/python3.10/dist-packages/transformers/generation/configuration_utils.py:595: UserWarning: `do_sample` is set to `False`. However, `top_p` is set to `0.95` -- this flag is only used in sample-based generation modes. You should set `do_sample=True` or unset `top_p`.
187
- warnings.warn(
188
- คำตอบ: [ANS] ในระยะเริ่มต้นของมะเร็งช่องปาก อาจไม่มีอาการแสดงที่ชัดเจนหรือมีเพียงเล็กน้อย เช่น การเปลี่ยนแปลงทางกายภาพเล็กๆ บนเนื้อเยื่อภายในช่องปาก ซึ่งอาจรวมถึง:
189
 
190
- 1. สีหรือรูปร่างที่เปลี่ยนแปลง: มีการเปลี่ยนแปลงทางกายภาพเช่น เปลี่ยนสี, ขนาด, รูปทรง หรือความหนาแน่นของเนื้อเยื่อ
191
 
192
- 2. แผลที่หายยาก: แผลในช่องปากที่เกิดขึ้นแล้วหายยาก หรือไม่หายเลย
 
 
 
193
 
194
- 3. การเปลี่ยนแปลงในการเคี้ยวหรือกลืนอาหาร: หากพบว่ามีการเปลี่ยนแปลงในการเคี้ยวหรือกลืนอาหาร ควรไปตรวจโดยแพทย์
195
 
196
- 4. การเปลี่ยนแปลงทางเสียง: หากเสียงเปลี่ยนแปลง โดยเฉพาะ
197
- --------------------------------------------------
198
 
199
- คำถาม: อาการของโรคไข้เลือดออกมีอะไรบ้าง
200
- คำตอบ: [ANS] อาการของโรคไข้เลือดออกอาจแตกต่างกันไปในแต่ละคน แต่โดยทั่วไปแล้ว มักจะมีอาการดังนี้:
201
 
202
- 1. ไข้: เป็นอาการที่พบได้มากที่สุด และอาจมีความร้อนสูงเป็นเวลานานหลายวัน
203
 
204
- 2. การอ่อนเพลียและเหนื่อยล้า
205
 
206
- 3. ปวดศีรษะหรือปวดตามข้อ
 
 
207
 
208
- 4. สิ่งที่คล้ายกับการแพ้ (เช่น ผื่นหรือลมพิษ)
209
-
210
- 5. เยื่อบุใต้ผิวหนังอักเสบ (Hemorrhagic rash) : ซึ่งเริ่มจากจุดแดงๆ บนใบหน้��� ลำคอ และแขน แล้วขยายไปทั่วร่างกาย โดยเฉพาะบริเวณขาและแขน
211
 
212
- 6. แผลเลือดฝาด (Petechiae): ซึ่งเป็นจุดเล็กๆ ที่เห็นได้ชัดเจนบน
213
- ```
214
 
215
  ### Authors
216
  * Amornpan Phornchaicharoen (amornpan@gmail.com)
 
30
  new_version: Aekanun/openthaigpt-MedChatModelv5.1
31
  ---
32
 
33
+ # 🇹🇭 Model Card for openthaigpt1.5-7b-medical-tuned
34
  <!-- Provide a quick summary of what the model is/does. -->
35
+ This model is fine-tuned from openthaigpt1.5-7b-instruct using Supervised Fine-Tuning (SFT) on the Thaweewat/thai-med-pack dataset. The model is designed for medical question-answering tasks in Thai, specializing in providing accurate and contextual answers based on medical information.
36
 
37
  ## 👤 **Developed and Fine-tuned by:**
38
  - **Amornpan Phornchaicharoen**
39
  - **Aekanun Thongtae**
40
 
41
  ## Model Description
42
+ This model was fine-tuned using Supervised Fine-Tuning (SFT) to optimize it for medical question answering in Thai. The base model is `openthaigpt1.5-7b-instruct`, and it has been enhanced with domain-specific knowledge using the Thaweewat/thai-med-pack dataset.
43
 
44
  - **Model type:** Causal Language Model (AutoModelForCausalLM)
45
  - **Language(s):** Thai
46
  - **License:** Apache License 2.0
47
+ - **Fine-tuned from model:** openthaigpt1.5-7b-instruct
48
+ - **Dataset used for fine-tuning:** Thaweewat/thai-med-pack
49
 
50
  ### Model Sources
51
 
 
97
 
98
  ## How to Get Started with the Model
99
 
100
+ Here’s how to load and use the model for generating medical responses in Thai:
101
 
102
+ ## 1. Install the Required Packages
103
+
104
+ First, ensure you have installed the required libraries by running:
105
+
106
+ python
107
+ pip install torch transformers bitsandbytes
108
+
109
+ ## 2. Load the Model and Tokenizer
110
+
111
+ You can load the model and tokenizer directly from Hugging Face using the following code:
112
+
113
+ python
114
  import torch
115
  from transformers import AutoModelForCausalLM, AutoTokenizer, BitsAndBytesConfig
 
116
 
117
+ # Define the model path
118
+ model_path = 'amornpan/openthaigpt-MedChatModelv11'
119
+
120
+ # Load the tokenizer and model
121
+ tokenizer = AutoTokenizer.from_pretrained(model_path)
122
+ tokenizer.pad_token = tokenizer.eos_token
123
+
124
+ ## 3. Prepare Your Input (Custom Prompt)
125
+
126
+ Create a custom medical prompt that you want the model to respond to:
127
+
128
+ python
129
+ custom_prompt = "โปรดอธิบายลักษณะช่องปากที่เป็นมะเร็งในระยะเริ่มต้น"
130
+ PROMPT = f'[INST] <You are a question answering assistant. Answer the question as truthfully and helpfully as possible. คุณคือผู้ช่วยตอบคำถาม จงตอบคำถามอย่างถูกต้องและมีประโยชน์ที่สุด<>{custom_prompt}[/INST]'
131
+
132
+ # Tokenize the input prompt
133
+ inputs = tokenizer(PROMPT, return_tensors="pt", padding=True, truncation=True)
134
+
135
 
136
+ ## 4. Configure the Model for Efficient Loading (4-bit Quantization)
137
+
138
+ The model uses 4-bit precision for efficient inference. Here’s how to set up the configuration:
139
+
140
+ python
141
  bnb_config = BitsAndBytesConfig(
142
  load_in_4bit=True,
143
  bnb_4bit_quant_type="nf4",
144
+ bnb_4bit_compute_dtype=torch.float16
145
  )
 
146
 
147
+ ## 5. Load the Model with Quantization Support
148
+
149
+ Now, load the model with the 4-bit quantization settings:
150
+
151
+ python
152
  model = AutoModelForCausalLM.from_pretrained(
153
+ model_path,
154
  quantization_config=bnb_config,
 
 
 
 
 
 
155
  trust_remote_code=True
156
  )
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
157
 
158
+ ## 6. Move the Model and Inputs to the GPU (prefer GPU)
 
 
 
 
 
 
159
 
160
+ For faster inference, move the model and input tensors to a GPU, if available:
161
 
162
+ python
163
+ device = torch.device("cuda" if torch.cuda.is_available() else "cpu")
164
+ model.to(device)
165
+ inputs = {k: v.to(device) for k, v in inputs.items()}
166
 
167
+ ## 7. Generate a Response from the Model
168
 
169
+ Now, generate the medical response by running the model:
 
170
 
171
+ python
172
+ outputs = model.generate(**inputs, max_new_tokens=200, do_sample=True)
173
 
174
+ ## 8. Decode the Generated Text
175
 
176
+ Finally, decode and print the response from the model:
177
 
178
+ python
179
+ generated_text = tokenizer.decode(outputs[0], skip_special_tokens=True)
180
+ print(generated_text)
181
 
182
+ ## 9. Output
 
 
183
 
184
+ python
185
+ [INST] <You are a question answering assistant. Answer the question as truthfully and helpfully as possible. คุณคือผู้ช่วยตอบคำถาม จงตอบคำถามอย่างถูกต้องและมีประโยชน์ที่สุด<>โปรดอธิบายลักษณะช่องปากที่เป็นมะเร็งในระยะเริ่มต้น[/INST] มะเร็งช่องปากเป็นมะเร็งเพียงชนิดเดียวที่ได้รับผลกระทบจากนิโคติน มันคือผู้ชายกลุ่มอายุ 60 – 75 คน คุณจะแสดงอาการและเกิดขึ้นอย่างรวดเร็วหากเกิดมะเร็งช่องปาก คุณจะสังเกตเห็นปื้นแพร่กระจายของเนื้องอก ส่วนใหญ่ในช่องปาก เนื้องอกแสดงว่าเป็นเจ้าแห่ที่กำลังทำลายเยียวยา ค้นหาทั้งภายในและภายนอกลิ้นที่อยู่ติดกางเกงป่อง มะเร็งกระเพาะปัสสาวะหรือมะเร็งกล้ามเนื้อกระเพาะ
186
 
187
  ### Authors
188
  * Amornpan Phornchaicharoen (amornpan@gmail.com)