Gaykar commited on
Commit
79c05cd
·
verified ·
1 Parent(s): eae63d8

Update README.md

Browse files
Files changed (1) hide show
  1. README.md +213 -97
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
- <!-- Provide a quick summary of what the model is/does. -->
 
14
 
 
15
 
 
16
 
17
- ## Model Details
18
 
19
- ### Model Description
20
 
21
- <!-- Provide a longer summary of what this model is. -->
22
 
 
23
 
 
24
 
25
- - **Developed by:** [More Information Needed]
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 Sources [optional]
34
 
35
- <!-- Provide the basic links for the model. -->
36
 
37
- - **Repository:** [More Information Needed]
38
- - **Paper [optional]:** [More Information Needed]
39
- - **Demo [optional]:** [More Information Needed]
40
 
41
- ## Uses
42
 
43
- <!-- Address questions around how the model is intended to be used, including the foreseeable users of the model and those affected by the model. -->
 
 
 
 
 
 
44
 
45
- ### Direct Use
46
 
47
- <!-- This section is for the model use without fine-tuning or plugging into a larger ecosystem/app. -->
48
 
49
- [More Information Needed]
50
 
51
- ### Downstream Use [optional]
52
 
53
- <!-- This section is for the model use when fine-tuned for a task, or when plugged into a larger ecosystem/app -->
 
 
 
54
 
55
- [More Information Needed]
56
 
57
  ### Out-of-Scope Use
58
 
59
- <!-- This section addresses misuse, malicious use, and uses that the model will not work well for. -->
 
 
 
 
 
 
 
60
 
61
- [More Information Needed]
62
 
63
  ## Bias, Risks, and Limitations
64
 
65
- <!-- This section is meant to convey both technical and sociotechnical limitations. -->
66
 
67
- [More Information Needed]
 
 
 
 
 
 
 
 
 
 
 
 
68
 
69
  ### Recommendations
70
 
71
- <!-- This section is meant to convey recommendations with respect to the bias, risk, and technical limitations. -->
 
 
 
72
 
73
- Users (both direct and downstream) should be made aware of the risks, biases and limitations of the model. More information needed for further recommendations.
74
 
75
  ## How to Get Started with the Model
76
 
77
- Use the code below to get started with the model.
78
 
79
- [More Information Needed]
80
 
81
- ## Training Details
 
 
82
 
83
- ### Training Data
 
 
84
 
85
- <!-- This should link to a Dataset Card, perhaps with a short stub of information on what the training data is all about as well as documentation related to data pre-processing or additional filtering. -->
 
86
 
87
- [More Information Needed]
88
 
89
- ### Training Procedure
90
 
91
- <!-- This relates heavily to the Technical Specifications. Content here should link to that section when it is relevant to the training procedure. -->
92
 
93
- #### Preprocessing [optional]
 
94
 
95
- [More Information Needed]
 
 
 
 
 
 
96
 
 
 
 
 
 
97
 
98
- #### Training Hyperparameters
 
 
 
 
 
 
 
 
 
99
 
100
- - **Training regime:** [More Information Needed] <!--fp32, fp16 mixed precision, bf16 mixed precision, bf16 non-mixed precision, fp16 non-mixed precision, fp8 mixed precision -->
 
 
101
 
102
- #### Speeds, Sizes, Times [optional]
 
 
 
 
103
 
104
- <!-- This section provides information about throughput, start/end time, checkpoint size if relevant, etc. -->
 
 
105
 
106
- [More Information Needed]
 
 
107
 
108
- ## Evaluation
 
109
 
110
- <!-- This section describes the evaluation protocols and provides the results. -->
 
111
 
112
- ### Testing Data, Factors & Metrics
113
 
114
- #### Testing Data
115
 
116
- <!-- This should link to a Dataset Card if possible. -->
117
 
118
- [More Information Needed]
119
 
120
- #### Factors
 
 
121
 
122
- <!-- These are the things the evaluation is disaggregating by, e.g., subpopulations or domains. -->
123
 
124
- [More Information Needed]
125
 
126
- #### Metrics
127
 
128
- <!-- These are the evaluation metrics being used, ideally with a description of why. -->
129
 
130
- [More Information Needed]
131
 
132
- ### Results
133
 
134
- [More Information Needed]
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
135
 
136
- #### Summary
137
 
 
138
 
 
139
 
140
- ## Model Examination [optional]
141
 
142
- <!-- Relevant interpretability work for the model goes here -->
143
 
144
- [More Information Needed]
145
 
146
- ## Environmental Impact
 
147
 
148
- <!-- Total emissions (in grams of CO2eq) and additional considerations, such as electricity usage, go here. Edit the suggested text below accordingly -->
149
 
150
- Carbon emissions can be estimated using the [Machine Learning Impact calculator](https://mlco2.github.io/impact#compute) presented in [Lacoste et al. (2019)](https://arxiv.org/abs/1910.09700).
151
 
152
- - **Hardware Type:** [More Information Needed]
153
- - **Hours used:** [More Information Needed]
154
- - **Cloud Provider:** [More Information Needed]
155
- - **Compute Region:** [More Information Needed]
156
- - **Carbon Emitted:** [More Information Needed]
157
 
158
- ## Technical Specifications [optional]
159
 
160
- ### Model Architecture and Objective
 
 
 
 
161
 
162
- [More Information Needed]
163
 
164
- ### Compute Infrastructure
 
 
 
 
165
 
166
- [More Information Needed]
167
 
168
- #### Hardware
169
 
170
- [More Information Needed]
171
 
172
- #### Software
173
 
174
- [More Information Needed]
 
 
 
 
175
 
176
- ## Citation [optional]
177
 
178
- <!-- If there is a paper or blog post introducing the model, the APA and Bibtex information for that should go in this section. -->
179
 
180
- **BibTeX:**
181
 
182
- [More Information Needed]
 
 
183
 
184
- **APA:**
185
 
186
- [More Information Needed]
187
 
188
- ## Glossary [optional]
189
 
190
- <!-- If relevant, include terms and calculations in this section that can help readers understand the model or model card. -->
191
 
192
- [More Information Needed]
 
 
193
 
194
- ## More Information [optional]
195
 
196
- [More Information Needed]
197
 
198
- ## Model Card Authors [optional]
199
 
200
- [More Information Needed]
201
 
202
- ## Model Card Contact
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