🚀 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
许可证。
模型信息