Improve language tag
#2
by lbourdois - opened
README.md
CHANGED
|
@@ -1,150 +1,162 @@
|
|
| 1 |
-
---
|
| 2 |
-
datasets:
|
| 3 |
-
- iimran/Medical-Intelligence-Questions
|
| 4 |
-
base_model:
|
| 5 |
-
- Qwen/Qwen2.5-3B
|
| 6 |
-
language:
|
| 7 |
-
-
|
| 8 |
-
|
| 9 |
-
-
|
| 10 |
-
-
|
| 11 |
-
-
|
| 12 |
-
-
|
| 13 |
-
-
|
| 14 |
-
|
| 15 |
-
|
| 16 |
-
|
| 17 |
-
|
| 18 |
-
|
| 19 |
-
|
| 20 |
-
|
| 21 |
-
-
|
| 22 |
-
-
|
| 23 |
-
-
|
| 24 |
-
|
| 25 |
-
|
| 26 |
-
|
| 27 |
-
|
| 28 |
-
|
| 29 |
-
|
| 30 |
-
|
| 31 |
-
|
| 32 |
-
- **
|
| 33 |
-
|
| 34 |
-
|
| 35 |
-
|
| 36 |
-
|
| 37 |
-
|
| 38 |
-
|
| 39 |
-
|
| 40 |
-
|
| 41 |
-
|
| 42 |
-
|
| 43 |
-
|
| 44 |
-
|
| 45 |
-
|
| 46 |
-
|
| 47 |
-
|
| 48 |
-
|
| 49 |
-
|
| 50 |
-
|
| 51 |
-
|
| 52 |
-
|
| 53 |
-
|
| 54 |
-
|
| 55 |
-
|
| 56 |
-
|
| 57 |
-
|
| 58 |
-
|
| 59 |
-
|
| 60 |
-
|
| 61 |
-
|
| 62 |
-
|
| 63 |
-
|
| 64 |
-
"
|
| 65 |
-
|
| 66 |
-
|
| 67 |
-
"
|
| 68 |
-
|
| 69 |
-
)
|
| 70 |
-
|
| 71 |
-
|
| 72 |
-
|
| 73 |
-
|
| 74 |
-
|
| 75 |
-
|
| 76 |
-
|
| 77 |
-
|
| 78 |
-
|
| 79 |
-
|
| 80 |
-
|
| 81 |
-
)
|
| 82 |
-
|
| 83 |
-
|
| 84 |
-
|
| 85 |
-
|
| 86 |
-
|
| 87 |
-
|
| 88 |
-
|
| 89 |
-
|
| 90 |
-
|
| 91 |
-
|
| 92 |
-
|
| 93 |
-
|
| 94 |
-
|
| 95 |
-
|
| 96 |
-
|
| 97 |
-
|
| 98 |
-
|
| 99 |
-
|
| 100 |
-
|
| 101 |
-
|
| 102 |
-
|
| 103 |
-
|
| 104 |
-
|
| 105 |
-
|
| 106 |
-
|
| 107 |
-
|
| 108 |
-
|
| 109 |
-
|
| 110 |
-
|
| 111 |
-
|
| 112 |
-
|
| 113 |
-
|
| 114 |
-
|
| 115 |
-
|
| 116 |
-
|
| 117 |
-
|
| 118 |
-
|
| 119 |
-
|
| 120 |
-
|
| 121 |
-
|
| 122 |
-
|
| 123 |
-
|
| 124 |
-
|
| 125 |
-
|
| 126 |
-
|
| 127 |
-
|
| 128 |
-
|
| 129 |
-
|
| 130 |
-
|
| 131 |
-
|
| 132 |
-
|
| 133 |
-
|
| 134 |
-
|
| 135 |
-
|
| 136 |
-
|
| 137 |
-
|
| 138 |
-
|
| 139 |
-
|
| 140 |
-
|
| 141 |
-
|
| 142 |
-
|
| 143 |
-
|
| 144 |
-
|
| 145 |
-
}
|
| 146 |
-
|
| 147 |
-
|
| 148 |
-
|
| 149 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 150 |
This model is intended for research and educational purposes only. It should not be used as the sole basis for clinical decision-making. All outputs should be validated by qualified healthcare professionals.
|
|
|
|
| 1 |
+
---
|
| 2 |
+
datasets:
|
| 3 |
+
- iimran/Medical-Intelligence-Questions
|
| 4 |
+
base_model:
|
| 5 |
+
- Qwen/Qwen2.5-3B
|
| 6 |
+
language:
|
| 7 |
+
- zho
|
| 8 |
+
- eng
|
| 9 |
+
- fra
|
| 10 |
+
- spa
|
| 11 |
+
- por
|
| 12 |
+
- deu
|
| 13 |
+
- ita
|
| 14 |
+
- rus
|
| 15 |
+
- jpn
|
| 16 |
+
- kor
|
| 17 |
+
- vie
|
| 18 |
+
- tha
|
| 19 |
+
- ara
|
| 20 |
+
tags:
|
| 21 |
+
- medical
|
| 22 |
+
- text-generation-inference
|
| 23 |
+
- transformers
|
| 24 |
+
- unsloth
|
| 25 |
+
---
|
| 26 |
+
# Qwen2.5-3B-R1-MedicalReasoner
|
| 27 |
+
|
| 28 |
+
**Qwen2.5-3B-R1-MedicalReasoner** is a clinical reasoning language model fine-tuned for advanced diagnostic and case-based problem solving. It has been developed for applications in medical education, clinical decision support, and research, with the capability to generate detailed chain-of-thought responses that include both the reasoning process and the final answer.
|
| 29 |
+
|
| 30 |
+
## Overview
|
| 31 |
+
|
| 32 |
+
- **Model Name:** Qwen2.5-3B-R1-MedicalReasoner
|
| 33 |
+
- **Base Architecture:** Qwen2.5 (3B)
|
| 34 |
+
- **Primary Application:** Clinical reasoning and medical problem solving
|
| 35 |
+
- **Key Features:**
|
| 36 |
+
- **Chain-of-Thought Outputs:** Responds with structured reasoning (`<reasoning> ... </reasoning>`) followed by a concise answer (`<answer> ... </answer>`).
|
| 37 |
+
- **Multi-Specialty Coverage:** Well-suited for scenarios in internal medicine, surgery, pediatrics, OB/GYN, emergency medicine, and more.
|
| 38 |
+
- **Explainable AI:** Generates detailed, educational explanations that support clinical decision-making.
|
| 39 |
+
|
| 40 |
+
## Model Capabilities
|
| 41 |
+
|
| 42 |
+
- **Expert-Level Clinical Reasoning:** Equipped to analyze complex clinical scenarios and provide in-depth diagnostic reasoning.
|
| 43 |
+
- **Structured Outputs:** Enforces a response format that separates the thought process from the final answer, aiding transparency and interpretability.
|
| 44 |
+
- **Optimized for Speed:** Uses Unsloth and vLLM for fast, efficient inference on GPU systems.
|
| 45 |
+
|
| 46 |
+
## Inference and Usage
|
| 47 |
+
|
| 48 |
+
Below is an example of how to use the model for inference or refer to inference.py in files section:
|
| 49 |
+
|
| 50 |
+
```python
|
| 51 |
+
from unsloth import FastLanguageModel, is_bfloat16_supported
|
| 52 |
+
from vllm import SamplingParams
|
| 53 |
+
from huggingface_hub import snapshot_download
|
| 54 |
+
model, tokenizer = FastLanguageModel.from_pretrained(
|
| 55 |
+
model_name="iimran/Qwen2.5-3B-R1-MedicalReasoner",
|
| 56 |
+
load_in_4bit=True,
|
| 57 |
+
fast_inference=True,
|
| 58 |
+
gpu_memory_utilization=0.5
|
| 59 |
+
)
|
| 60 |
+
lora_rank = 64
|
| 61 |
+
model = FastLanguageModel.get_peft_model(
|
| 62 |
+
model,
|
| 63 |
+
r=lora_rank,
|
| 64 |
+
target_modules=["q_proj", "k_proj", "v_proj", "o_proj",
|
| 65 |
+
"gate_proj", "up_proj", "down_proj"],
|
| 66 |
+
lora_alpha=lora_rank,
|
| 67 |
+
use_gradient_checkpointing="unsloth",
|
| 68 |
+
random_state=3407,
|
| 69 |
+
)
|
| 70 |
+
lora_path = snapshot_download("iimran/Qwen2.5-3B-R1-MedicalReasoner-lora-adapter")
|
| 71 |
+
print("LoRA adapter downloaded to:", lora_path)
|
| 72 |
+
model.load_lora(lora_path)
|
| 73 |
+
SYSTEM_PROMPT = (
|
| 74 |
+
"Respond in the following format:\n"
|
| 75 |
+
"<reasoning>\n"
|
| 76 |
+
"...\n"
|
| 77 |
+
"</reasoning>\n"
|
| 78 |
+
"<answer>\n"
|
| 79 |
+
"...\n"
|
| 80 |
+
"</answer>"
|
| 81 |
+
)
|
| 82 |
+
USER_PROMPT = (
|
| 83 |
+
"In the context of disseminated intravascular coagulation (DIC), "
|
| 84 |
+
"which blood component is expected to show an increase due to the excessive breakdown of fibrin?"
|
| 85 |
+
)
|
| 86 |
+
text = tokenizer.apply_chat_template(
|
| 87 |
+
[
|
| 88 |
+
{"role": "system", "content": SYSTEM_PROMPT},
|
| 89 |
+
{"role": "user", "content": USER_PROMPT},
|
| 90 |
+
],
|
| 91 |
+
tokenize=False,
|
| 92 |
+
add_generation_prompt=True
|
| 93 |
+
)
|
| 94 |
+
sampling_params = SamplingParams(
|
| 95 |
+
temperature=0.1,
|
| 96 |
+
top_p=0.95,
|
| 97 |
+
max_tokens=4096,
|
| 98 |
+
)
|
| 99 |
+
outputs = model.fast_generate(
|
| 100 |
+
text,
|
| 101 |
+
sampling_params=sampling_params,
|
| 102 |
+
lora_request=None
|
| 103 |
+
)
|
| 104 |
+
print(outputs[0].outputs[0].text)
|
| 105 |
+
```
|
| 106 |
+
|
| 107 |
+
### Adapter Integration
|
| 108 |
+
|
| 109 |
+
For further fine-tuning or experiments with LoRA adapters, the LoRA adapter for this model is available in a separate repository.
|
| 110 |
+
|
| 111 |
+
- **LoRA Adapter Repo:** [iimran/Qwen2.5-3B-R1-MedicalReasoner-lora-adapter](https://huggingface.co/iimran/Qwen2.5-3B-R1-MedicalReasoner-lora-adapter)
|
| 112 |
+
|
| 113 |
+
To download and integrate the LoRA adapter:
|
| 114 |
+
```python
|
| 115 |
+
from huggingface_hub import snapshot_download
|
| 116 |
+
|
| 117 |
+
# Download the LoRA adapter repository:
|
| 118 |
+
lora_path = snapshot_download("iimran/Qwen2.5-3B-R1-MedicalReasoner-lora-adapter")
|
| 119 |
+
print("LoRA adapter downloaded to:", lora_path)
|
| 120 |
+
|
| 121 |
+
# Load the adapter into the model:
|
| 122 |
+
model.load_lora(lora_path)
|
| 123 |
+
```
|
| 124 |
+
|
| 125 |
+
## Installation
|
| 126 |
+
|
| 127 |
+
To use this model, install the required packages:
|
| 128 |
+
```bash
|
| 129 |
+
pip install unsloth vllm trl datasets huggingface-hub
|
| 130 |
+
```
|
| 131 |
+
|
| 132 |
+
A compatible GPU is recommended for optimal performance.
|
| 133 |
+
|
| 134 |
+
## Citation
|
| 135 |
+
|
| 136 |
+
If you use **Qwen2.5-3B-R1-MedicalReasoner** in your research, please cite:
|
| 137 |
+
```bibtex
|
| 138 |
+
@misc{sarwar2025reinforcement,
|
| 139 |
+
author = {Imran Sarwar and Muhammad Rouf Mustafa},
|
| 140 |
+
title = {Reinforcement Learning Elevates Qwen2.5-3B Medical Reasoning Performance},
|
| 141 |
+
year = {2025},
|
| 142 |
+
month = {Apr},
|
| 143 |
+
day = {10},
|
| 144 |
+
publisher = {Imran Sarwar's Blog},
|
| 145 |
+
howpublished = {\url{https://www.imransarwar.com/blog-posts/Reinforcement-Learning-Elevates-Qwen2.5-Medical-Reasoning-Performance.html}},
|
| 146 |
+
note = {Accessed: 2025-04-09}
|
| 147 |
+
}
|
| 148 |
+
```
|
| 149 |
+
|
| 150 |
+
```bibtex
|
| 151 |
+
@misc{Qwen2.5-3B-R1-MedicalReasoner,
|
| 152 |
+
authors = {Imran Sarwar, Muhammad Rouf Mustafa},
|
| 153 |
+
title = {Qwen 2.5-3B Meets Deepseek R1: A Fine-Tuned Medical Reasoning Model for Enhanced Diagnostics},
|
| 154 |
+
year = {2025},
|
| 155 |
+
publisher = {Hugging Face},
|
| 156 |
+
url = {https://huggingface.co/iimran/Qwen2.5-3B-R1-MedicalReasoner}
|
| 157 |
+
}
|
| 158 |
+
```
|
| 159 |
+
|
| 160 |
+
## Disclaimer
|
| 161 |
+
|
| 162 |
This model is intended for research and educational purposes only. It should not be used as the sole basis for clinical decision-making. All outputs should be validated by qualified healthcare professionals.
|