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

Update README.md

Browse files
Files changed (1) hide show
  1. README.md +82 -60
README.md CHANGED
@@ -24,6 +24,9 @@ tags:
24
  - lahnmah
25
  - NT Thai GPT
26
  - ntthaigpt
 
 
 
27
  new_version: Aekanun/openthaigpt-MedChatModelv5.1
28
  ---
29
 
@@ -94,100 +97,119 @@ This model can be used as a foundational model for medical assistance systems, c
94
 
95
  ## How to Get Started with the Model
96
 
97
- Here’s how to load and use the model for generating medical responses in Thai:
98
-
99
- ## 1. Install the Required Packages
100
-
101
- First, ensure you have installed the required libraries by running:
102
-
103
- ```python
104
- pip install torch transformers bitsandbytes
105
- ```
106
-
107
- ## 2. Load the Model and Tokenizer
108
-
109
- You can load the model and tokenizer directly from Hugging Face using the following code:
110
 
111
  ```python
112
  import torch
113
  from transformers import AutoModelForCausalLM, AutoTokenizer, BitsAndBytesConfig
114
-
115
- # Define the model path
116
- model_path = 'amornpan/openthaigpt-MedChatModelv11'
117
-
118
- # Load the tokenizer and model
119
- tokenizer = AutoTokenizer.from_pretrained(model_path)
120
- tokenizer.pad_token = tokenizer.eos_token
121
  ```
122
 
123
- ## 3. Prepare Your Input (Custom Prompt)
124
-
125
- Create a custom medical prompt that you want the model to respond to:
126
-
127
  ```python
128
- custom_prompt = "โปรดอธิบายลักษณะช่องปากที่เป็นมะเร็งในระยะเริ่มต้น"
129
- PROMPT = f'[INST] <You are a question answering assistant. Answer the question as truthfully and helpfully as possible. คุณคือผู้ช่วยตอบคำถาม จงตอบคำถามอย่างถูกต้องและมีประโยชน์ที่สุด<>{custom_prompt}[/INST]'
130
-
131
- # Tokenize the input prompt
132
- inputs = tokenizer(PROMPT, return_tensors="pt", padding=True, truncation=True)
133
-
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
 
148
- ## 5. Load the Model with Quantization Support
149
-
150
- Now, load the model with the 4-bit quantization settings:
151
-
152
  ```python
 
153
  model = AutoModelForCausalLM.from_pretrained(
154
- model_path,
155
  quantization_config=bnb_config,
 
 
 
 
 
 
156
  trust_remote_code=True
157
  )
 
158
  ```
159
 
160
- ## 6. Move the Model and Inputs to the GPU (prefer GPU)
161
-
162
- For faster inference, move the model and input tensors to a GPU, if available:
163
-
164
  ```python
165
- device = torch.device("cuda" if torch.cuda.is_available() else "cpu")
166
- model.to(device)
167
- inputs = {k: v.to(device) for k, v in inputs.items()}
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
168
  ```
169
 
170
- ## 7. Generate a Response from the Model
 
 
 
 
 
 
 
 
 
 
 
 
 
 
171
 
172
- Now, generate the medical response by running the model:
173
 
174
  ```python
175
- outputs = model.generate(**inputs, max_new_tokens=200, do_sample=True)
176
- ```
 
 
 
 
177
 
178
- ## 8. Decode the Generated Text
179
 
180
- Finally, decode and print the response from the model:
181
 
182
- ```python
183
- generated_text = tokenizer.decode(outputs[0], skip_special_tokens=True)
184
- print(generated_text)
185
- ```
186
 
187
- ## 9. Output
 
188
 
189
- ```python
190
- [INST] <You are a question answering assistant. Answer the question as truthfully and helpfully as possible. คุณคือผู้ช่วยตอบคำถาม จงตอบคำถามอย่างถูกต้องและมีประโยชน์ที่สุด<>โปรดอธิบายลักษณะช่องปากที่เป็นมะเร็งในระยะเริ่มต้น[/INST] มะเร็งช่องปากเป็นมะเร็งเพียงชนิดเดียวที่ได้รับผลกระทบจากนิโคติน มันคือผู้ชายกลุ่มอายุ 60 – 75 คน คุณจะแสดงอาการและเกิดขึ้นอย่างรวดเร็วหากเกิดมะเร็งช่องปาก คุณจะสังเกตเห็นปื้นแพร่กระจายของเนื้องอก ส่วนใหญ่ในช่องปาก เนื้องอกแสดงว่าเป็นเจ้าแห่ที่กำลังทำลายเยียวยา ค้นหาทั้งภายในและภายนอกลิ้นที่อยู่ติดกางเกงป่อง มะเร็งกระเพาะปัสสาวะหรือมะเร็งกล้ามเนื้อกระเพาะ
 
 
 
 
 
 
 
 
 
 
 
 
191
  ```
192
 
193
  ### Authors
 
24
  - lahnmah
25
  - NT Thai GPT
26
  - ntthaigpt
27
+ - medical
28
+ - medtech
29
+ - HealthGPT
30
  new_version: Aekanun/openthaigpt-MedChatModelv5.1
31
  ---
32
 
 
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