🚀 Qwen2.5-3B-Medical-LoRA
Qwen2.5-3B-Medical-LoRA是基於醫療數據集微調的模型,能為用戶提供醫學相關的清晰準確回覆,助力醫療問答與健康諮詢等場景。
🚀 快速開始
Qwen2.5-3B-Medical-LoRA
是 Qwen2.5-3B-Instruct 在專注於醫療保健的數據集 ChatDoctor-HealthCareMagic-100k
上的微調版本。它旨在針對用戶的指令生成醫學相關的回覆,提供清晰簡潔的健康指導。
該模型使用 LoRA(低秩自適應) 進行高效訓練,通過 bitsandbytes 實現 4 位量化,從而能夠在消費級硬件上進行部署。
✨ 主要特性
- 醫療問答:為用戶提供醫學相關問題的解答。
- 健康諮詢系統:輔助構建健康諮詢服務。
- 醫療專業人員教育工具:助力醫療從業者的學習。
- AI 輔助醫療助手:為醫療工作提供智能輔助。
⚠️ 重要提示
此模型不能替代專業的醫療建議、診斷或治療。請始終諮詢有資質的醫療服務提供者。
📦 安裝指南
文檔未提及具體安裝步驟,暫無法提供。
💻 使用示例
基礎用法
instruction = "I'm a 60-year-old man with a history of hypertension and type 2 diabetes..."
response = generate_response(instruction)
The symptoms you're describing — including chest pain on exertion, fatigue, shortness of breath, and ankle swelling — may indicate congestive heart failure or coronary artery disease...
高級用法
from transformers import AutoTokenizer, AutoModelForCausalLM, BitsAndBytesConfig
from peft import PeftModel
import torch
tokenizer = AutoTokenizer.from_pretrained("Qwen/Qwen2.5-3B-Instruct", trust_remote_code=True)
bnb_config = BitsAndBytesConfig(
load_in_4bit=True,
bnb_4bit_compute_dtype=torch.float16,
bnb_4bit_use_double_quant=True,
bnb_4bit_quant_type="nf4"
)
base_model = AutoModelForCausalLM.from_pretrained(
"Qwen/Qwen2.5-3B-Instruct",
quantization_config=bnb_config,
device_map="auto",
trust_remote_code=True
)
model = PeftModel.from_pretrained(base_model, "AbdullahAlnemr1/qwen2.5-medical-lora")
model = model.merge_and_unload()
model.eval()
prompt = '''<|im_start|>system
You are a highly knowledgeable and accurate medical assistant...
<|im_end|>
<|im_start|>user
Instruction: What are the symptoms of anemia?<|im_end|>
<|im_start|>assistant
'''
inputs = tokenizer(prompt, return_tensors="pt").to(model.device)
outputs = model.generate(**inputs, max_new_tokens=512)
response = tokenizer.decode(outputs[0], skip_special_tokens=True)
print(response)
📚 詳細文檔
文件和工件
adapter_model
:在醫療數據集上訓練的 LoRA 權重。
README.md
:項目文檔。
training_args.bin
:訓練配置。
tokenizer_config.json
、tokenizer.model
、special_tokens_map.json
:分詞器文件。
提示格式
此模型遵循指令微調格式:
<|im_start|>system
You are a highly knowledgeable and accurate medical assistant trained to provide evidence-based medical advice. Answer clearly and concisely using medical best practices. If the question is unclear or potentially harmful to answer, respond with a disclaimer.<|im_end|>
<|im_start|>user
Instruction: [YOUR INSTRUCTION HERE]
[OPTIONAL INPUT]<|im_end|>
<|im_start|>assistant
📄 許可證
本項目採用 apache-2.0
許可證。
模型信息