Update README.md
Browse files
README.md
CHANGED
|
@@ -6,202 +6,318 @@ tags:
|
|
| 6 |
- base_model:adapter:microsoft/phi-2
|
| 7 |
- lora
|
| 8 |
- transformers
|
|
|
|
|
|
|
|
|
|
| 9 |
---
|
| 10 |
|
| 11 |
# Model Card for Model ID
|
| 12 |
|
| 13 |
-
|
|
|
|
| 14 |
|
|
|
|
| 15 |
|
|
|
|
| 16 |
|
| 17 |
-
|
| 18 |
|
| 19 |
-
### Model Description
|
| 20 |
|
| 21 |
-
<!-- Provide a longer summary of what this model is. -->
|
| 22 |
|
|
|
|
| 23 |
|
|
|
|
| 24 |
|
| 25 |
-
|
| 26 |
-
- **Funded by [optional]:** [More Information Needed]
|
| 27 |
-
- **Shared by [optional]:** [More Information Needed]
|
| 28 |
-
- **Model type:** [More Information Needed]
|
| 29 |
-
- **Language(s) (NLP):** [More Information Needed]
|
| 30 |
-
- **License:** [More Information Needed]
|
| 31 |
-
- **Finetuned from model [optional]:** [More Information Needed]
|
| 32 |
|
| 33 |
-
### Model
|
| 34 |
|
| 35 |
-
|
| 36 |
|
| 37 |
-
|
| 38 |
-
|
| 39 |
-
- **Demo [optional]:** [More Information Needed]
|
| 40 |
|
| 41 |
-
|
| 42 |
|
| 43 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 44 |
|
| 45 |
-
|
| 46 |
|
| 47 |
-
|
| 48 |
|
| 49 |
-
|
| 50 |
|
| 51 |
-
###
|
| 52 |
|
| 53 |
-
|
|
|
|
|
|
|
|
|
|
| 54 |
|
| 55 |
-
|
| 56 |
|
| 57 |
### Out-of-Scope Use
|
| 58 |
|
| 59 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 60 |
|
| 61 |
-
|
| 62 |
|
| 63 |
## Bias, Risks, and Limitations
|
| 64 |
|
| 65 |
-
|
| 66 |
|
| 67 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 68 |
|
| 69 |
### Recommendations
|
| 70 |
|
| 71 |
-
|
|
|
|
|
|
|
|
|
|
| 72 |
|
| 73 |
-
|
| 74 |
|
| 75 |
## How to Get Started with the Model
|
| 76 |
|
| 77 |
-
|
| 78 |
|
| 79 |
-
|
| 80 |
|
| 81 |
-
|
|
|
|
|
|
|
| 82 |
|
| 83 |
-
#
|
|
|
|
|
|
|
| 84 |
|
| 85 |
-
|
|
|
|
| 86 |
|
| 87 |
-
|
| 88 |
|
| 89 |
-
### Training Procedure
|
| 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 |
-
|
| 151 |
|
| 152 |
-
|
| 153 |
-
-
|
| 154 |
-
|
| 155 |
-
|
| 156 |
-
|
| 157 |
|
| 158 |
-
|
| 159 |
|
| 160 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 161 |
|
| 162 |
-
|
| 163 |
|
| 164 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 165 |
|
| 166 |
-
|
| 167 |
|
| 168 |
-
|
| 169 |
|
| 170 |
-
|
| 171 |
|
| 172 |
-
##
|
| 173 |
|
| 174 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 175 |
|
| 176 |
-
|
| 177 |
|
| 178 |
-
|
| 179 |
|
| 180 |
-
|
| 181 |
|
| 182 |
-
|
|
|
|
|
|
|
| 183 |
|
| 184 |
-
|
| 185 |
|
| 186 |
-
|
| 187 |
|
| 188 |
-
|
| 189 |
|
| 190 |
-
|
| 191 |
|
| 192 |
-
|
|
|
|
|
|
|
| 193 |
|
| 194 |
-
|
| 195 |
|
| 196 |
-
|
| 197 |
|
| 198 |
-
|
| 199 |
|
| 200 |
-
|
| 201 |
|
| 202 |
-
|
| 203 |
|
| 204 |
-
[More Information Needed]
|
| 205 |
-
### Framework versions
|
| 206 |
|
| 207 |
-
- PEFT 0.18.1
|
|
|
|
| 6 |
- base_model:adapter:microsoft/phi-2
|
| 7 |
- lora
|
| 8 |
- transformers
|
| 9 |
+
license: cc-by-nc-4.0
|
| 10 |
+
datasets:
|
| 11 |
+
- Gaykar/DrugData
|
| 12 |
---
|
| 13 |
|
| 14 |
# Model Card for Model ID
|
| 15 |
|
| 16 |
+
This model is a LoRA-based fine-tuned variant of Microsoft Phi-2, designed to generate concise, medical-style textual descriptions of drugs.
|
| 17 |
+
Given a drug name as input, the model produces a short, single-paragraph description following an instruction-style prompt format.
|
| 18 |
|
| 19 |
+
The training pipeline consists of two stages:
|
| 20 |
|
| 21 |
+
Continued Pretraining (CPT) on domain-relevant medical and pharmaceutical text to adapt the base model to the language and terminology of the domain.
|
| 22 |
|
| 23 |
+
Supervised Fine-Tuning (SFT) using structured drug name–description pairs to guide the model toward consistent formatting and domain-specific writing style.
|
| 24 |
|
|
|
|
| 25 |
|
|
|
|
| 26 |
|
| 27 |
+
This model is intended **strictly for educational and research purposes** and must not be used for real-world medical, clinical, or decision-making applications.
|
| 28 |
|
| 29 |
+
---
|
| 30 |
|
| 31 |
+
## Model Details
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 32 |
|
| 33 |
+
### Model Description
|
| 34 |
|
| 35 |
+
This model is a parameter-efficient fine-tuned version of the Microsoft Phi-2 language model, adapted to generate concise medical drug descriptions from drug names. The training pipeline consists of two stages:
|
| 36 |
|
| 37 |
+
1. **Continued Pretraining (CPT)** to adapt the base model to drug and medical terminology.
|
| 38 |
+
2. **Supervised Fine-Tuning (SFT)** using instruction-style input–output pairs.
|
|
|
|
| 39 |
|
| 40 |
+
LoRA adapters were used during fine-tuning to reduce memory usage and training cost while preserving base model knowledge.
|
| 41 |
|
| 42 |
+
- **Developed by:** Atharva Gaykar
|
| 43 |
+
- **Funded by:** Not applicable
|
| 44 |
+
- **Shared by:** Atharva Gaykar
|
| 45 |
+
- **Model type:** Causal Language Model (LoRA-adapted)
|
| 46 |
+
- **Language(s) (NLP):** English
|
| 47 |
+
- **License:** CC-BY-NC 4.0
|
| 48 |
+
- **Finetuned from model:** microsoft/phi-2
|
| 49 |
|
| 50 |
+
---
|
| 51 |
|
| 52 |
+
## Uses
|
| 53 |
|
| 54 |
+
This model is designed to generate concise medical-style descriptions of drugs given their names.
|
| 55 |
|
| 56 |
+
### Direct Use
|
| 57 |
|
| 58 |
+
- Educational demonstrations of instruction-following language models
|
| 59 |
+
- Academic research on medical-domain adaptation
|
| 60 |
+
- Experimentation with CPT + SFT pipelines
|
| 61 |
+
- Studying hallucination behavior in domain-specific LLMs
|
| 62 |
|
| 63 |
+
The model should only be used in **non-production, educational, or research settings**.
|
| 64 |
|
| 65 |
### Out-of-Scope Use
|
| 66 |
|
| 67 |
+
This model is **not designed or validated** for:
|
| 68 |
+
|
| 69 |
+
- Medical diagnosis or treatment planning
|
| 70 |
+
- Clinical decision support systems
|
| 71 |
+
- Dosage recommendations or prescribing guidance
|
| 72 |
+
- Patient-facing healthcare applications
|
| 73 |
+
- Professional medical, pharmaceutical, or regulatory use
|
| 74 |
+
- Any real-world deployment where incorrect medical information could cause harm
|
| 75 |
|
| 76 |
+
---
|
| 77 |
|
| 78 |
## Bias, Risks, and Limitations
|
| 79 |
|
| 80 |
+
This model was developed **solely for educational purposes** and **must not be used in real-world medical or clinical decision-making**.
|
| 81 |
|
| 82 |
+
### Known Limitations
|
| 83 |
+
|
| 84 |
+
- May hallucinate incorrect drug indications or mechanisms
|
| 85 |
+
- Generated descriptions may be incomplete or outdated
|
| 86 |
+
- Does not verify outputs against authoritative medical sources
|
| 87 |
+
- Does not understand patient context, dosage, or drug interactions
|
| 88 |
+
- Output quality is sensitive to prompt phrasing
|
| 89 |
+
|
| 90 |
+
### Risks
|
| 91 |
+
|
| 92 |
+
- Misinterpretation of outputs as medical advice
|
| 93 |
+
- Overconfidence in fluent but inaccurate responses
|
| 94 |
+
- Potential propagation of misinformation if misused
|
| 95 |
|
| 96 |
### Recommendations
|
| 97 |
|
| 98 |
+
- Always verify outputs using trusted medical references
|
| 99 |
+
- Use only in controlled, non-production environments
|
| 100 |
+
- Clearly disclose limitations in any downstream use
|
| 101 |
+
- Avoid deployment in safety-critical or healthcare systems
|
| 102 |
|
| 103 |
+
---
|
| 104 |
|
| 105 |
## How to Get Started with the Model
|
| 106 |
|
| 107 |
+
This repository contains **LoRA adapter weights**, not a full model.
|
| 108 |
|
| 109 |
+
Example usage (conceptual):
|
| 110 |
|
| 111 |
+
```python
|
| 112 |
+
from transformers import AutoModelForCausalLM, AutoTokenizer
|
| 113 |
+
from peft import PeftModel
|
| 114 |
|
| 115 |
+
# Load base model and tokenizer
|
| 116 |
+
base_model = AutoModelForCausalLM.from_pretrained("microsoft/phi-2")
|
| 117 |
+
tokenizer = AutoTokenizer.from_pretrained("microsoft/phi-2")
|
| 118 |
|
| 119 |
+
# Load LoRA adapter
|
| 120 |
+
model = PeftModel.from_pretrained(base_model, "Gaykar/Phi2-drug_data")
|
| 121 |
|
| 122 |
+
model.eval()
|
| 123 |
|
|
|
|
| 124 |
|
| 125 |
+
import torch
|
| 126 |
|
| 127 |
+
# Drug to evaluate
|
| 128 |
+
drug_name = "Paracetamol"
|
| 129 |
|
| 130 |
+
# Build evaluation prompt
|
| 131 |
+
eval_prompt = (
|
| 132 |
+
"Generate exactly ONE sentence describing the drug.\n"
|
| 133 |
+
"Do not include headings or extra information.\n\n"
|
| 134 |
+
f"Drug Name: {drug_name}\n"
|
| 135 |
+
"Description:"
|
| 136 |
+
)
|
| 137 |
|
| 138 |
+
# Tokenize prompt
|
| 139 |
+
model_input = tokenizer(
|
| 140 |
+
eval_prompt,
|
| 141 |
+
return_tensors="pt"
|
| 142 |
+
).to(model.device)
|
| 143 |
|
| 144 |
+
# Generate output (greedy decoding)
|
| 145 |
+
with torch.no_grad():
|
| 146 |
+
output = model.generate(
|
| 147 |
+
**model_input,
|
| 148 |
+
do_sample=False,
|
| 149 |
+
num_beams=1, # Greedy decoding (This decision is critical for this model because it operates in the medical domain, where factual consistency and determinism are more important than linguistic diversity.)
|
| 150 |
+
max_new_tokens=120,
|
| 151 |
+
repetition_penalty=1.1,
|
| 152 |
+
eos_token_id=tokenizer.eos_token_id
|
| 153 |
+
)
|
| 154 |
|
| 155 |
+
# Remove prompt tokens
|
| 156 |
+
prompt_length = model_input["input_ids"].shape[1]
|
| 157 |
+
generated_tokens = output[0][prompt_length:]
|
| 158 |
|
| 159 |
+
# Decode generated text only
|
| 160 |
+
generated_text = tokenizer.decode(
|
| 161 |
+
generated_tokens,
|
| 162 |
+
skip_special_tokens=True
|
| 163 |
+
).strip()
|
| 164 |
|
| 165 |
+
# Enforce single-sentence output
|
| 166 |
+
if "." in generated_text:
|
| 167 |
+
generated_text = generated_text.split(".")[0] + "."
|
| 168 |
|
| 169 |
+
print(" DRUG NAME:", drug_name)
|
| 170 |
+
print(" MODEL GENERATED DESCRIPTION:")
|
| 171 |
+
print(generated_text)
|
| 172 |
|
| 173 |
+
#Example output
|
| 174 |
+
DRUG NAME (EVAL): Paracetamol
|
| 175 |
|
| 176 |
+
MODEL GENERATED DESCRIPTION:
|
| 177 |
+
Paracetamol (acetaminophen) is a non-narcotic analgesic and antipyretic used to relieve mild to moderate pain and reduce fever.
|
| 178 |
|
| 179 |
+
````
|
| 180 |
|
| 181 |
+
---
|
| 182 |
|
| 183 |
+
## Training Details
|
| 184 |
|
| 185 |
+
### Training Data
|
| 186 |
|
| 187 |
+
* **Dataset:** Gaykar/DrugData
|
| 188 |
+
* Structured drug name–description pairs
|
| 189 |
+
* Used for both CPT (domain adaptation) and SFT (instruction following)
|
| 190 |
|
| 191 |
+
### Training Procedure
|
| 192 |
|
| 193 |
+
#### Continued Pretraining (CPT)
|
| 194 |
|
| 195 |
+
The base model was further trained on domain-relevant medical and drug-related text to improve familiarity with terminology and style. CPT focused on next-token prediction without instruction formatting.
|
| 196 |
|
| 197 |
+
#### Supervised Fine-Tuning (SFT)
|
| 198 |
|
| 199 |
+
After CPT, the model was fine-tuned using instruction-style prompts to generate concise medical descriptions from drug names.
|
| 200 |
|
| 201 |
+
#### Training Hyperparameters
|
| 202 |
|
| 203 |
+
**CPT Hyperparameters**
|
| 204 |
+
|
| 205 |
+
| Hyperparameter | Value |
|
| 206 |
+
| ----------------------- | ------------------- |
|
| 207 |
+
| Batch size (per device) | 1 |
|
| 208 |
+
| Effective batch size | 8 |
|
| 209 |
+
| Epochs | 4 |
|
| 210 |
+
| Learning rate | 2e-4 |
|
| 211 |
+
| Precision | FP16 |
|
| 212 |
+
| Optimizer | Paged AdamW (8-bit) |
|
| 213 |
+
| Logging steps | 10 |
|
| 214 |
+
| Checkpoint saving | Every 500 steps |
|
| 215 |
+
| Checkpoint limit | 2 |
|
| 216 |
+
|
| 217 |
+
**SFT Hyperparameters**
|
| 218 |
+
|
| 219 |
+
| Hyperparameter | Value |
|
| 220 |
+
| ----------------------- | ------------------- |
|
| 221 |
+
| Batch size (per device) | 4 |
|
| 222 |
+
| Gradient accumulation | 1 |
|
| 223 |
+
| Effective batch size | 4 |
|
| 224 |
+
| Epochs | 5 |
|
| 225 |
+
| Learning rate | 2e-5 |
|
| 226 |
+
| LR scheduler | Linear |
|
| 227 |
+
| Warmup ratio | 6% |
|
| 228 |
+
| Weight decay | 1e-4 |
|
| 229 |
+
| Max gradient norm | 1.0 |
|
| 230 |
+
| Precision | FP16 |
|
| 231 |
+
| Optimizer | Paged AdamW (8-bit) |
|
| 232 |
+
| Checkpoint saving | Every 50 steps |
|
| 233 |
+
| Checkpoint limit | 2 |
|
| 234 |
+
| Experiment tracking | Weights & Biases |
|
| 235 |
|
| 236 |
+
---
|
| 237 |
|
| 238 |
+
## Evaluation
|
| 239 |
|
| 240 |
+
### Testing Data
|
| 241 |
|
| 242 |
+
Drug names sampled from the same dataset were used for evaluation. Outputs were assessed for factual correctness using an external LLM-based evaluation approach.
|
| 243 |
|
| 244 |
+
### Metrics
|
| 245 |
|
| 246 |
+
**Evaluation Method:** LLM-as-a-Judge (Chatgpt -Web seacrch available. )
|
| 247 |
|
| 248 |
+
* Binary classification: Factually Correct / Hallucinated
|
| 249 |
+
* Three evaluation batches
|
| 250 |
|
| 251 |
+
### Results
|
| 252 |
|
| 253 |
+
**Batch 1**
|
| 254 |
|
| 255 |
+
| Category | Count | Percentage |
|
| 256 |
+
| --------------------- | ----- | ---------- |
|
| 257 |
+
| Total Drugs Evaluated | 25 | 100% |
|
| 258 |
+
| Factually Correct | 24 | 96% |
|
| 259 |
+
| Hallucinated / Failed | 1 | 4% |
|
| 260 |
|
| 261 |
+
**Batch 2**
|
| 262 |
|
| 263 |
+
| Category | Count | Percentage |
|
| 264 |
+
| --------------------- | ----- | ---------- |
|
| 265 |
+
| Total Drugs Evaluated | 25 | 100% |
|
| 266 |
+
| Factually Correct | 22 | 88% |
|
| 267 |
+
| Hallucinated / Failed | 3 | 12% |
|
| 268 |
|
| 269 |
+
**Batch 3**
|
| 270 |
|
| 271 |
+
| Category | Count | Percentage |
|
| 272 |
+
| --------------------- | ----- | ---------- |
|
| 273 |
+
| Total Drugs Evaluated | 22 | 100% |
|
| 274 |
+
| Factually Correct | 15 | 68% |
|
| 275 |
+
| Hallucinated / Failed | 0 | 0% |
|
| 276 |
|
| 277 |
+
#### Summary
|
| 278 |
|
| 279 |
+
Since this model was fine-tuned (SFT+CPT) using LoRA rather than full-parameter fine-tuning, eliminating hallucinations entirely is challenging. While LoRA enables efficient training and strong instruction-following behavior, it does not fully overwrite the base model’s internal knowledge. Despite this limitation, the model performs well for educational and research-oriented drug description generation tasks.
|
| 280 |
|
| 281 |
+
---
|
| 282 |
|
| 283 |
+
## Environmental Impact
|
| 284 |
|
| 285 |
+
* **Hardware Type:** NVIDIA T4 GPU
|
| 286 |
+
* **Hours used:** Not recorded
|
| 287 |
+
* **Cloud Provider:** Google Colab
|
| 288 |
+
* **Compute Region:** Not specified
|
| 289 |
+
* **Carbon Emitted:** Not estimated
|
| 290 |
|
| 291 |
+
---
|
| 292 |
|
| 293 |
+
## Technical Specifications
|
| 294 |
|
| 295 |
+
### Model Architecture and Objective
|
| 296 |
|
| 297 |
+
* Base model: Microsoft Phi-2
|
| 298 |
+
* Objective: Instruction-following text generation
|
| 299 |
+
* Adaptation method: LoRA (PEFT)
|
| 300 |
|
| 301 |
+
### Compute Infrastructure
|
| 302 |
|
| 303 |
+
#### Hardware
|
| 304 |
|
| 305 |
+
* NVIDIA T4 GPU
|
| 306 |
|
| 307 |
+
#### Software
|
| 308 |
|
| 309 |
+
* Transformers
|
| 310 |
+
* PEFT
|
| 311 |
+
* PyTorch
|
| 312 |
|
| 313 |
+
---
|
| 314 |
|
| 315 |
+
## Model Card Contact
|
| 316 |
|
| 317 |
+
Atharva Gaykar
|
| 318 |
|
| 319 |
+
### Framework Versions
|
| 320 |
|
| 321 |
+
* PEFT 0.18.0
|
| 322 |
|
|
|
|
|
|
|
| 323 |
|
|
|