LoRA fine-tuned
Qwen2.5-1.5B-Instruct on ~43K Chinese medical Q&A pairs derived from the MedGraphRAG knowledge base, with rank-16 adapters and an 80/10/10 train/val/test split.
54,095 Chinese medical Q&A pairs generated from the
MedGraphRAG knowledge base (
medical.json, 8,807 disease records). Each disease produces up to 14 Q&A pairs covering symptoms, causes, prevention, treatment, medication, diet, complications, and more. Pairs with answers shorter than 15 characters are filtered out to remove low-information entries. Split 80/10/10 with seed=42.
1from transformers import AutoTokenizer, AutoModelForCausalLM
2from peft import PeftModel
3import torch
4
5base_model_id = "Qwen/Qwen2.5-1.5B-Instruct"
6adapter_id = "mellee030/MedQwen-1.5B-LoRA-medrag"
7
8tokenizer = AutoTokenizer.from_pretrained(base_model_id, trust_remote_code=True)
9model = AutoModelForCausalLM.from_pretrained(
10 base_model_id, dtype=torch.float16, device_map="auto", trust_remote_code=True
11)
12model = PeftModel.from_pretrained(model, adapter_id)
13model.eval()
14
15messages = [
16 {"role": "system", "content": "你是一个专业的医疗问答助手,请根据用户的问题给出准确、简洁的医疗建议。"},
17 {"role": "user", "content": "糖尿病的早期症状有哪些?"},
18]
19text = tokenizer.apply_chat_template(messages, tokenize=False, add_generation_prompt=True)
20inputs = tokenizer(text, return_tensors="pt").to(model.device)
21
22with torch.no_grad():
23 outputs = model.generate(**inputs, max_new_tokens=256, temperature=0.7, do_sample=True)
24print(tokenizer.decode(outputs[0][inputs.input_ids.shape[1]:], skip_special_tokens=True))
BERTScore is the primary metric because it captures semantic equivalence rather than surface overlap — a concise correct answer scores well even if it uses different phrasing than the reference.
This model is for research purposes only and should not be used as a substitute for professional medical advice.