Views
No views yet
| Domain | Benchmark | Original | + Med-REFL |
|---|---|---|---|
| In-Domain | MedQA-USMLE | 59.92 | 65.74 (+5.82) |
| Out-of-Domain | MedMCQA | 57.61 | 59.11 (+1.50) |
| Out-of-Domain | GPQA (Med+) | 45.16 | 50.22 (+5.06) |
| Out-of-Domain | MMLU-Pro (Med+) | 57.56 | 60.89 (+3.30) |
| LoRA for Base Model | Backbone | Hugging Face Link |
|---|---|---|
| Med-REFL for Llama-3.1-8B | Llama-3.1-8B | HF Link |
| Med-REFL for Qwen2.5-7B | Qwen2.5-7B | HF Link |
| Med-REFL for Huatuo-o1-8B | Huatuo-o1-8b | HF Link |
| Med-REFL for MedReason-8B | MedReason-8B | HF Link |
1import torch
2from peft import PeftModel
3from transformers import AutoModelForCausalLM, AutoTokenizer
4
5# Define the paths for the base model and your LoRA adapter on the Hugging Face Hub
6base_model_path = "meta-llama/Meta-Llama-3.1-8B-Instruct"
7lora_path = "HANI-LAB/Med-REFL-Llama-3.1-8B-lora/Llama3.1-Med-REFL-LoraAdapter"
8
9# Load the tokenizer
10tokenizer = AutoTokenizer.from_pretrained(base_model_path)
11
12# Load the base model
13base_model = AutoModelForCausalLM.from_pretrained(
14 base_model_path,
15 torch_dtype=torch.bfloat16,
16 device_map="auto"
17)
18
19# Load and merge your LoRA weights into the base model
20model = PeftModel.from_pretrained(base_model, lora_path)
21
22# Prepare the prompt
23system_prompt = '''You are a helpful medical expert specializing in USMLE exam questions, and your task is to answer a multi-choice medical question. Please first think step-by-step and then choose the answer from the provided options. Your responses will be used for research purposes only, so please have a definite answer.\nProvide your response in the following JSON format:\n{"reason": "Step-by-step explanation of your thought process","answer": "Chosen answer from the given options"}\n'''
24user_prompt = "A 67-year-old man with transitional cell carcinoma of the bladder comes to the physician because of a 2-day history of ringing sensation in his ear. He received this first course of neoadjuvant chemotherapy 1 week ago. Pure tone audiometry shows a sensorineural hearing loss of 45 dB. The expected beneficial effect of the drug that caused this patient's symptoms is most likely due to which of the following actions?\nOptions:\nA: Inhibition of thymidine synthesis\nB: Inhibition of proteasome\nC: Hyperstabilization of microtubules\nD: Generation of free radicals\nE: Cross-linking of DNA"
25
26messages = [
27 {"role": "system", "content": system_prompt},
28 {"role": "user", "content": user_prompt},
29]
30
31# Convert the formatted prompt into input tensors
32input_ids = tokenizer.apply_chat_template(
33 messages,
34 add_generation_prompt=True,
35 return_tensors="pt"
36).to(model.device)
37
38# Generate the response
39outputs = model.generate(
40 input_ids,
41 max_new_tokens=4096,
42 do_sample=True,
43 temperature=0.2,
44 top_p=0.7,
45 repetition_penalty=1
46)
47
48# Decode and print the generated text
49response = outputs[0][input_ids.shape[-1]:]
50print(tokenizer.decode(response, skip_special_tokens=True))@misc{yang2025medreflmedicalreasoningenhancement,
title={Med-REFL: Medical Reasoning Enhancement via Self-Corrected Fine-grained Reflection},
author={Zongxian Yang and Jiayu Qian and Zegao Peng and Haoyu Zhang and Zhi-An Huang},
year={2025},
eprint={2506.13793},
archivePrefix={arXiv},
primaryClass={cs.AI},
url={https://arxiv.org/abs/2506.13793},
}