base_model:
- Qwen/Qwen2.5-32B-Instruct
datasets:
- Thaweewat/thai-med-pack
language:
- th
- en
library_name: transformers
license: apache-2.0
pipeline_tag: text-generation
tags:
- text-generation-inference
- sft
- trl
- 4-bit precision
- bitsandbytes
- LoRA
- Fine-Tuning with LoRA
- LLM
- GenAI
- medical
- medtech
- HealthGPT
- minddatatech.com
- NT Academy
🇹🇭 Model Card for Qwen2.5-32B-Instruct-medical-tuned
ℹ️ This version is significantly better than OpenThaiGPT!.
Qwen2.5-32B-Instruct for Thai Medical QA
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.
Model Description
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.
- Model type: Causal Language Model (AutoModelForCausalLM)
- Language(s): Thai
- License: Apache License 2.0
- Fine-tuned from model: Qwen2.5-32B-Instruct
- Dataset used for fine-tuning: Thaweewat/thai-med-pack
Model Sources
- Repository: https://huggingface.co/amornpan
- Citing Repository: https://huggingface.co/Aekanun
- Base Model: https://huggingface.co/Qwen/Qwen2.5-32B-Instruct
- Dataset: https://huggingface.co/datasets/Thaweewat/thai-med-pack
Uses
Direct Use
The model can be used directly for generating medical responses in Thai. It has been optimized for:
- Medical question-answering
- Providing clinical information
- Health-related dialogue generation
Downstream Use
This model serves as a foundational model for medical assistance systems, chatbots, and applications related to healthcare in the Thai language.
Out-of-Scope Use
- This model should not be used for real-time diagnosis or emergency medical scenarios.
- It should not be relied upon for critical clinical decisions without human oversight, as it is not intended to replace professional medical advice.
Bias, Risks, and Limitations
Bias
- The model may reflect biases present in the dataset, especially regarding underrepresented medical conditions or topics.
Risks
- Responses may contain inaccuracies due to the model's inherent limitations and the dataset used for fine-tuning.
- The model should not be used as the sole source of medical advice.
Limitations
- Primarily limited to the medical domain.
- Sensitive to prompts and may generate off-topic responses for non-medical queries.
Model Training Statistics
Training Summary
- Total Steps: 1050
- Total Epochs: 98.25
- Validation Checks: 42
- Epoch with Lowest Validation Loss: 93.57
Performance Improvement
- Training Loss Reduction: 45.32%
- Validation Loss Reduction: 35.97%
- Final Training Loss: 1.0060
- Lowest Validation Loss: 1.1385
Loss Values
Metric | Initial | Final | Minimum |
---|---|---|---|
Training Loss | 1.8398 | 1.0060 | 1.0060 |
Validation Loss | 1.7782 | 1.1386 | 1.1385 |
Training Duration
- Started: 2025-03-07 08:24:41
- Ended: 2025-03-08 13:23:30
- Total Training Time: ~29 hours
Model Training Results:
How to Get Started with the Model
This section provides a step-by-step guide to loading and using the model for generating medical responses in Thai.
1. Install the Required Packages
Ensure that you have installed the required libraries:
pip install torch transformers accelerate bitsandbytes
pip install --upgrade transformers huggingface_hub
[!pip install bitsandbytes --upgrade]
[!pip install --upgrade transformers huggingface_hub]
2. Load the Model and Tokenizer
You can load the model and tokenizer directly from Hugging Face using the following code:
import torch
from transformers import AutoModelForCausalLM, AutoTokenizer, BitsAndBytesConfig
Define the model path
model_path = 'amornpan/Qwen2.5-32B-MedChatModel'
Load the tokenizer and model
tokenizer = AutoTokenizer.from_pretrained(model_path) tokenizer.pad_token = tokenizer.eos_token
3. Prepare Your Input (Custom Prompt)
Create a custom medical prompt that you want the model to respond to:
custom_prompt = "อาการของโรคเบาหวานมีอะไรบ้าง"
PROMPT = f'[INST] <คุณเป็นผู้ช่วยตอบคำถามทางการแพทย์ จงตอบคำถามอย่างถูกต้องและให้ข้อมูลที่เป็นประโยชน์ที่สุด<> {custom_prompt} [/INST]'
# Tokenize the input prompt
inputs = tokenizer(PROMPT, return_tensors="pt", padding=True, truncation=True)
4. Configure the Model for Efficient Loading (4-bit Quantization)
The model uses 4-bit precision for efficient inference. Here’s how to set up the configuration:
bnb_config = BitsAndBytesConfig(
load_in_4bit=True,
bnb_4bit_quant_type="nf4",
bnb_4bit_compute_dtype=torch.float16
)
5. Load the Model with Quantization Support
Now, load the model with the 4-bit quantization settings:
model = AutoModelForCausalLM.from_pretrained(
model_path,
quantization_config=bnb_config,
trust_remote_code=True
)
6. Move the Model and Inputs to the GPU (prefer GPU)
For faster inference, move the model and input tensors to a GPU, if available:
device = torch.device("cuda" if torch.cuda.is_available() else "cpu")
model.to(device)
inputs = {k: v.to(device) for k, v in inputs.items()}
7. Generate a Response from the Model
Now, generate the medical response by running the model:
outputs = model.generate(**inputs, max_new_tokens=256, do_sample=True)
8. Decode the Generated Text
Finally, decode and print the response from the model:
generated_text = tokenizer.decode(outputs[0], skip_special_tokens=True)
print(generated_text)
9. Output
คำถาม: การรักษาโรคความดันโลหิตสูงทำอย่างไร
คำตอบ: สวัสดี ความดันโลหิตสูงสามารถรักษาได้โดยการใช้ยาหลายชนิด เช่น เบนโซเพอรีซิน, อะโมโลนิด, ลิโซโปรตาซอล, อีลาฟอร์เท็ต,
อัลฟูราลิท, อะเซติซิลดิโพราเมต, อาราคานา, อาเนอโรนิก, อาเซติซิลสัมพันธ์, อาเนอโรนิก, อะเซติซิลสัมพันธ์ เป็นต้น
คุณสามารถปรึกษาแพทย์ผู้เชี่ยวชาญในเรื่องนี้เพื่อทราบข้อมูลเพิ่มเติมเกี่ยวกับยาดังกล่าว หวังว่าคำตอบของฉันจะเป็นประโยชน์สำหรับคุณ
ขอให้คุณมีสุขภาพที่ดี ขอบคุณที่เลือกใช้บริการของเรา หากคุณมีคำถามใด ๆ
คำถาม: ยา Paracetamol มีผลข้างเคียงอะไรบ้าง
คำตอบ: Paracetamol เป็นยาแก้ปวดและลดไข้ที่ใช้กันอย่างแพร่หลาย ซึ่งมีผลข้างเคียงน้อยกว่ายาแก้ปวดชนิดอื่นๆ โดยทั่วไปจะไม่มีผลข้างเคียงใดๆ
หากใช้ในขนาดที่แนะนำ แต่อาจพบได้ เช่น ปวดท้อง อาเจียน และรู้สึกคลื่นไส้ นอกจากนี้ หากใช้ในปริมาณที่มากเกินไป อาจทำให้มีอาการปัสสาวะขุ่น
มีสีเหลืองเข้ม เบื่ออาหาร คลื่นไส้ อาเจียน ปวดท้อง ปวดหัว ตาเหลือง หรือปัสสาวะสีเข้มเป็นสีชาโคล่า
หากมีอาการดังกล่าวควรหยุดการใช้ยาและรีบไปพบแพทย์เพื่อตรวจหาความเสียหายของตับจากยา
โดยการตรวจการทำงานของตับ ซึ่งหากพบว่ามีอาการของโรคตับวายเฉียบพลัน
👤 Authors
- Amornpan Phornchaicharoen ([email protected])
- Aekanun Thongtae ([email protected])
- Montita Somsoo ([email protected])