Downloads · 30 days
15
23% of all-time downloads
mellee030/MedQwen-7B-LoRA
MedQwen-7B-LoRA is a machine learning model from mellee030. Use it for the machine learning task on the model card, and read the license before you ship it in a product. It is set up for peft. The card lists the license as apache-2.0.
LoRA fine-tuned Qwen2.5-7B-Instruct on 30K Chinese medical Q&A dialogue pairs for domain-specific medical question answering.
Downloads · 30 days
15
23% of all-time downloads
All-time downloads
65
Public
Repo size
92.2 MB
Likes
0
Public
Click a slice to open those files.
.safetensors80.8 MB · 88%
From the Hugging Face model README
LoRA fine-tuned Qwen2.5-7B-Instruct on 30K Chinese medical Q&A dialogue pairs for domain-specific medical question answering.
This is a LoRA adapter trained on top of Qwen2.5-7B-Instruct. It adapts the base model to Chinese medical dialogue using parameter-efficient fine-tuning — only ~1% of parameters are trained, keeping the adapter lightweight (~150MB) while preserving the base model's general capabilities.
30,284 Chinese medical dialogue pairs covering a wide range of medical topics including symptoms, medications, diseases, and treatment advice. Data was converted to Qwen2.5 chat template format (system / user / assistant).
Evaluated on 412 held-out validation samples (50-sample subset):
| Metric | Base Qwen2.5-7B | MedQwen-7B | Δ |
|---|---|---|---|
| ROUGE-1 | 0.0407 | 0.0330 | -0.77% |
| ROUGE-2 | 0.0040 | 0.0024 | -0.16% |
| ROUGE-L | 0.0389 | 0.0330 | -0.59% |
| BERTScore | 0.5959 | 0.6670 | +7.11% |
ROUGE scores are lower for the fine-tuned model because it learned concise, on-format answers rather than verbose outputs. BERTScore (semantic similarity using bert-base-chinese) is the primary metric for open-ended Chinese generation and shows a +7.11% improvement.
import torch
from transformers import AutoTokenizer, AutoModelForCausalLM
from peft import PeftModel
base_model_id = "Qwen/Qwen2.5-7B-Instruct"
adapter_id = "mellee030/MedQwen-7B-LoRA"
tokenizer = AutoTokenizer.from_pretrained(base_model_id, trust_remote_code=True)
model = AutoModelForCausalLM.from_pretrained(
base_model_id,
torch_dtype=torch.float16,
device_map="auto",
trust_remote_code=True,
)
model = PeftModel.from_pretrained(model, adapter_id)
model.eval()
messages = [
{"role": "system", "content": "你是一个专业的医疗问答助手,请根据用户的问题给出准确、简洁的医疗建议。"},
{"role": "user", "content": "糖尿病的早期症状有哪些?"},
]
prompt = tokenizer.apply_chat_template(messages, tokenize=False, add_generation_prompt=True)
inputs = tokenizer(prompt, return_tensors="pt").to(model.device)
with torch.no_grad():
output = model.generate(
**inputs,
max_new_tokens=256,
do_sample=False,
repetition_penalty=1.1,
pad_token_id=tokenizer.eos_token_id,
)
new_tokens = output[0][inputs["input_ids"].shape[1]:]
print(tokenizer.decode(new_tokens, skip_special_tokens=True))
| Parameter | Value |
|---|---|
| LoRA rank (r) | 8 |
| LoRA alpha | 16 |
| LoRA dropout | 0.05 |
| Target modules | q_proj, k_proj, v_proj, o_proj, gate_proj, up_proj, down_proj |
| Learning rate | 2e-4 |
| Batch size | 1 (grad accum steps: 8, effective batch: 8) |
| Epochs | 3 |
| Max sequence length | 256 |
| Precision | FP16 |
| LR scheduler | Cosine with warmup |
Full training code, evaluation scripts, and Gradio chatbot demo: github.com/melc030/MedQwen