Create README.md
Browse files
README.md
ADDED
|
@@ -0,0 +1,122 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
---
|
| 2 |
+
datasets:
|
| 3 |
+
- ofir408/MedConceptsQA
|
| 4 |
+
language:
|
| 5 |
+
- en
|
| 6 |
+
metrics:
|
| 7 |
+
- accuracy
|
| 8 |
+
base_model:
|
| 9 |
+
- TinyLlama/TinyLlama-1.1B-Chat-v1.0
|
| 10 |
+
pipeline_tag: question-answering
|
| 11 |
+
library_name: transformers
|
| 12 |
+
tags:
|
| 13 |
+
- tinyllama
|
| 14 |
+
- lora
|
| 15 |
+
- instruction-tuned
|
| 16 |
+
- peft
|
| 17 |
+
- Lora
|
| 18 |
+
- merged
|
| 19 |
+
- medical
|
| 20 |
+
- healthcare
|
| 21 |
+
---
|
| 22 |
+
|
| 23 |
+
# 🩺 TinyLlama Medical Assistant (Merged LoRA)
|
| 24 |
+
|
| 25 |
+
**Author:** Nabil Faieaz
|
| 26 |
+
**Base model:** [TinyLlama/TinyLlama-1.1B-Chat-v1.0](https://huggingface.co/TinyLlama/TinyLlama-1.1B-Chat-v1.0)
|
| 27 |
+
**Fine-tuning method:** LoRA (Low-Rank Adaptation) using PEFT → merged into base weights
|
| 28 |
+
**Intended use:** Concise, factual, general medical information
|
| 29 |
+
|
| 30 |
+
---
|
| 31 |
+
|
| 32 |
+
## 📌 Overview
|
| 33 |
+
|
| 34 |
+
This model is a **fine-tuned version of TinyLlama 1.1B-Chat** adapted for **medical question answering**.
|
| 35 |
+
It has been trained to give **brief and accurate** answers to medical-related queries, following a consistent Q/A style.
|
| 36 |
+
|
| 37 |
+
Key features:
|
| 38 |
+
- ✅ LoRA fine-tuning for efficient adaptation on limited compute (T4 GPU)
|
| 39 |
+
- ✅ Merged LoRA + base into a **single standalone model** (no separate adapter needed)
|
| 40 |
+
- ✅ Optimized for short, factual answers — avoids overly verbose outputs
|
| 41 |
+
- ✅ Context-aware: warns users to seek professional medical help for urgent/personal issues
|
| 42 |
+
|
| 43 |
+
---
|
| 44 |
+
|
| 45 |
+
## ⚠️ Disclaimer
|
| 46 |
+
|
| 47 |
+
> **This model is for educational and informational purposes only.**
|
| 48 |
+
> It is **not** a substitute for professional medical advice, diagnosis, or treatment.
|
| 49 |
+
> Always consult a qualified healthcare provider for medical concerns.
|
| 50 |
+
|
| 51 |
+
---
|
| 52 |
+
|
| 53 |
+
## 🚀 Quick Start
|
| 54 |
+
|
| 55 |
+
```python
|
| 56 |
+
from transformers import AutoTokenizer, AutoModelForCausalLM
|
| 57 |
+
|
| 58 |
+
model_id = "nabilfaieaz/tinyllama-med-full"
|
| 59 |
+
|
| 60 |
+
# Load tokenizer and model
|
| 61 |
+
tokenizer = AutoTokenizer.from_pretrained(model_id)
|
| 62 |
+
if tokenizer.pad_token is None:
|
| 63 |
+
tokenizer.pad_token = tokenizer.eos_token
|
| 64 |
+
|
| 65 |
+
model = AutoModelForCausalLM.from_pretrained(
|
| 66 |
+
model_id,
|
| 67 |
+
torch_dtype="auto",
|
| 68 |
+
device_map="auto"
|
| 69 |
+
)
|
| 70 |
+
|
| 71 |
+
# Example prompt
|
| 72 |
+
system_prompt = (
|
| 73 |
+
"You are a helpful, concise medical assistant. Provide general information only, "
|
| 74 |
+
"not a diagnosis. If urgent or personal issues are mentioned, advise seeing a clinician."
|
| 75 |
+
)
|
| 76 |
+
|
| 77 |
+
question = "What is hypertension?"
|
| 78 |
+
prompt = f"{system_prompt}\n\nQuestion: {question}\nAnswer:"
|
| 79 |
+
|
| 80 |
+
inputs = tokenizer(prompt, return_tensors="pt").to(model.device)
|
| 81 |
+
outputs = model.generate(
|
| 82 |
+
**inputs,
|
| 83 |
+
max_new_tokens=128,
|
| 84 |
+
do_sample=False,
|
| 85 |
+
temperature=0.0,
|
| 86 |
+
top_p=1.0,
|
| 87 |
+
eos_token_id=tokenizer.eos_token_id,
|
| 88 |
+
pad_token_id=tokenizer.pad_token_id
|
| 89 |
+
)
|
| 90 |
+
|
| 91 |
+
print(tokenizer.decode(outputs[0], skip_special_tokens=True))
|
| 92 |
+
|
| 93 |
+
🧠 Training Details
|
| 94 |
+
Base model: TinyLlama/TinyLlama-1.1B-Chat-v1.0
|
| 95 |
+
Fine-tuning method: LoRA (via peft)
|
| 96 |
+
Target modules: q_proj, k_proj, v_proj, o_proj
|
| 97 |
+
LoRA config:
|
| 98 |
+
* r = 16
|
| 99 |
+
* alpha = 16
|
| 100 |
+
* dropout = 0.0
|
| 101 |
+
Max sequence length: 512 tokens
|
| 102 |
+
Batch size: 2 per device (gradient accumulation for effective batch)
|
| 103 |
+
Learning rate: 2e-4
|
| 104 |
+
Precision: fp16
|
| 105 |
+
Evaluation: periodic eval every 200 steps
|
| 106 |
+
Checkpoints: saved every 500 steps, final merge from checkpoint-17000
|
| 107 |
+
|
| 108 |
+
📊 Intended Use
|
| 109 |
+
Intended:
|
| 110 |
+
* Educational explanations of medical terms and concepts
|
| 111 |
+
* Study aid for medical students and healthcare professionals
|
| 112 |
+
* Healthcare-related chatbot demos
|
| 113 |
+
|
| 114 |
+
Not intended:
|
| 115 |
+
* Real-time clinical decision making
|
| 116 |
+
* Emergency medical guidance
|
| 117 |
+
* Handling sensitive personal medical data (PHI)
|
| 118 |
+
⚙️ Technical Notes
|
| 119 |
+
* The model is merged — you don’t need to separately load LoRA adapters.
|
| 120 |
+
* Works with Hugging Face transformers ≥ 4.38.
|
| 121 |
+
* Can be quantized to 4-bit (e.g., QLoRA) for local inference.
|
| 122 |
+
|