sabber commited on
Commit
dc00e76
·
verified ·
1 Parent(s): f4fe0f2

Upload README.md with huggingface_hub

Browse files
Files changed (1) hide show
  1. README.md +364 -0
README.md ADDED
@@ -0,0 +1,364 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ---
2
+ language:
3
+ - en
4
+ license: apache-2.0
5
+ library_name: peft
6
+ tags:
7
+ - medical
8
+ - radiology
9
+ - text-generation
10
+ - summarization
11
+ - clinical-nlp
12
+ - healthcare
13
+ - lora
14
+ - medphi
15
+ - impression-generation
16
+ base_model: microsoft/Phi-3.5-mini-instruct
17
+ datasets:
18
+ - private
19
+ pipeline_tag: text-generation
20
+ model-index:
21
+ - name: medphi-radiology-summary-adapter
22
+ results:
23
+ - task:
24
+ type: text-generation
25
+ name: Medical Impression Generation
26
+ metrics:
27
+ - name: ROUGE-1
28
+ type: rouge
29
+ value: 0.4146
30
+ - name: ROUGE-2
31
+ type: rouge
32
+ value: 0.2818
33
+ - name: ROUGE-L
34
+ type: rouge
35
+ value: 0.3720
36
+ ---
37
+
38
+ # MediPhi Radiology Summary Adapter
39
+
40
+ This is a LoRA adapter fine-tuned on Microsoft's [Phi-3.5-mini-instruct](https://huggingface.co/microsoft/Phi-3.5-mini-instruct) for automated radiology impression generation. The model generates concise clinical impressions from detailed radiology findings across multiple imaging modalities.
41
+
42
+ ## Model Description
43
+
44
+ - **Model Type:** LoRA Adapter for Causal Language Model
45
+ - **Base Model:** microsoft/Phi-3.5-mini-instruct (3B parameters)
46
+ - **Trainable Parameters:** 0.33% (via LoRA)
47
+ - **Language:** English
48
+ - **Domain:** Medical/Clinical Radiology
49
+ - **Task:** Text Generation (Abstractive Summarization)
50
+ - **License:** Apache 2.0
51
+
52
+ ### Model Purpose
53
+
54
+ This model automates the generation of radiological impressions (summary conclusions) from detailed clinical findings. It has been trained on 30,135 de-identified radiology reports from 6 clinical institutions, covering multiple imaging modalities including MR, CT, CR, US, XR, and Nuclear Medicine.
55
+
56
+ ## Key Features
57
+
58
+ - **Multi-Modality Support:** Trained on MR, CT, CR, US, XR, and NM imaging reports
59
+ - **Multi-Clinic Adaptation:** Handles diverse institutional reporting styles
60
+ - **Efficient Fine-tuning:** Uses 4-bit quantization with LoRA for memory efficiency
61
+ - **Clinical Focus:** Optimized for medically substantial findings (minimum 100 characters)
62
+ - **Production Ready:** Validated across 1,915 test samples with systematic evaluation
63
+
64
+ ## Training Data
65
+
66
+ ### Dataset Statistics
67
+
68
+ - **Total Reports:** 30,135 de-identified radiology reports
69
+ - **After Quality Filtering:** 12,559 high-quality reports (41.7% retention)
70
+ - **Training Split:**
71
+ - Train: 8,865 samples (70%)
72
+ - Validation: 1,879 samples (15%)
73
+ - Test: 1,915 samples (15%)
74
+
75
+ ### Modality Distribution
76
+
77
+ | Modality | Train Count | Percentage |
78
+ |----------|------------|-----------|
79
+ | MR (Magnetic Resonance) | ~9,500 | 59.9% |
80
+ | CT (Computed Tomography) | ~1,900 | 17.7% |
81
+ | CR (Computed Radiography) | ~1,700 | 7.3% |
82
+ | US (Ultrasound) | ~1,700 | 7.1% |
83
+ | XR (X-Ray) | ~700 | 2.9% |
84
+ | NM (Nuclear Medicine) | ~100 | 1.1% |
85
+
86
+ ### Data Preprocessing
87
+
88
+ The preprocessing pipeline includes:
89
+ - **Quality Filtering:** Minimum 100 characters for findings, 20 for impressions
90
+ - **Text Cleaning:** Electronic signature removal, whitespace normalization
91
+ - **Length Constraints:** Max 3,000 characters (findings), 1,000 (impressions)
92
+ - **Stratified Splitting:** Maintains clinic-modality distribution across splits
93
+ - **Format:** JSONL with chat-based messages structure
94
+
95
+ ## Training Details
96
+
97
+ ### Training Configuration
98
+
99
+ - **Framework:** PyTorch with Hugging Face Transformers
100
+ - **Fine-tuning Method:** LoRA (Low-Rank Adaptation)
101
+ - **Quantization:** 4-bit NF4 with double quantization
102
+ - **Compute:** Single RTX 4090 GPU (24GB VRAM)
103
+ - **Training Duration:** ~2 hours
104
+ - **Cost:** <$2 on RunPod
105
+
106
+ ### LoRA Hyperparameters
107
+
108
+ ```python
109
+ {
110
+ "r": 8,
111
+ "lora_alpha": 32,
112
+ "target_modules": ["o_proj", "qkv_proj", "gate_up_proj", "down_proj"],
113
+ "lora_dropout": 0.05,
114
+ "bias": "none",
115
+ "task_type": "CAUSAL_LM"
116
+ }
117
+ ```
118
+
119
+ ### Training Hyperparameters
120
+
121
+ ```python
122
+ {
123
+ "num_train_epochs": 1,
124
+ "per_device_train_batch_size": 2,
125
+ "gradient_accumulation_steps": 16, # effective batch size = 32
126
+ "learning_rate": 2e-4,
127
+ "weight_decay": 0.001,
128
+ "warmup_ratio": 0.03,
129
+ "lr_scheduler_type": "cosine",
130
+ "max_seq_length": 1024,
131
+ "optim": "adamw_torch",
132
+ "gradient_checkpointing": True,
133
+ "max_grad_norm": 0.3
134
+ }
135
+ ```
136
+
137
+ ## Performance
138
+
139
+ ### Overall Metrics
140
+
141
+ | Metric | Base Model | Fine-Tuned | Improvement |
142
+ |--------|-----------|-----------|-------------|
143
+ | ROUGE-1 | 0.3465 | **0.4146** | +19.6% |
144
+ | ROUGE-2 | 0.1800 | **0.2818** | +56.6% |
145
+ | ROUGE-L | 0.2727 | **0.3720** | +36.4% |
146
+
147
+ ### Performance by Modality
148
+
149
+ | Modality | Base ROUGE-1 | Fine-Tuned ROUGE-1 | Improvement |
150
+ |----------|-------------|-------------------|-------------|
151
+ | MR | 0.4642 | **0.6274** | **+35.1%** |
152
+ | CR | 0.3283 | **0.3970** | +20.9% |
153
+ | XR | 0.2859 | **0.3812** | +33.3% |
154
+ | CT | 0.2836 | **0.2978** | +5.0% |
155
+ | US | 0.3073 | **0.3394** | +10.4% |
156
+ | NM | 0.3440 | 0.2872 | -16.6% |
157
+
158
+ **Key Insights:**
159
+ - Highest-volume modalities (MR, CR, XR) show strongest improvements
160
+ - MR imaging achieves 35.1% improvement—the largest performance gain
161
+ - 85% of clinical cases fall in high-performing modalities
162
+
163
+ ## Usage
164
+
165
+ ### Installation
166
+
167
+ ```bash
168
+ pip install torch transformers peft bitsandbytes accelerate
169
+ ```
170
+
171
+ ### Basic Usage
172
+
173
+ ```python
174
+ from peft import AutoPeftModelForCausalLM
175
+ from transformers import AutoTokenizer
176
+
177
+ # Load model and tokenizer
178
+ model = AutoPeftModelForCausalLM.from_pretrained(
179
+ "sabber/medphi-radiology-summary-adapter",
180
+ torch_dtype="auto",
181
+ device_map="auto"
182
+ )
183
+ tokenizer = AutoTokenizer.from_pretrained("sabber/medphi-radiology-summary-adapter")
184
+
185
+ # Prepare input
186
+ findings = """
187
+ [CLINIC: clinic_1] [MODALITY: MR] FINDINGS: The brain parenchyma demonstrates
188
+ normal signal intensity without evidence of acute infarction, mass effect, or
189
+ midline shift. The ventricular system and sulci are normal in size and configuration
190
+ for patient age. No abnormal enhancement is identified following contrast administration.
191
+ """
192
+
193
+ messages = [
194
+ {"role": "system", "content": """You are an expert radiologist assistant specializing in generating accurate and concise medical impressions from radiology findings.
195
+
196
+ Your task is to:
197
+ 1. Analyze the findings: Carefully review all clinical findings
198
+ 2. Generate focused impressions: Create clear, prioritized conclusions
199
+ 3. Maintain clinical accuracy: Ensure significant findings are appropriately characterized
200
+ 4. Use appropriate medical terminology: Follow standard radiological conventions
201
+ 5. Adapt communication style: Match institutional reporting style"""},
202
+ {"role": "user", "content": findings + "\n\nIMPRESSION:"}
203
+ ]
204
+
205
+ # Generate impression
206
+ inputs = tokenizer.apply_chat_template(
207
+ messages,
208
+ tokenize=True,
209
+ add_generation_prompt=False,
210
+ return_tensors="pt"
211
+ ).to(model.device)
212
+
213
+ outputs = model.generate(
214
+ inputs,
215
+ max_new_tokens=512,
216
+ temperature=0.7,
217
+ top_p=0.9,
218
+ do_sample=True,
219
+ pad_token_id=tokenizer.eos_token_id
220
+ )
221
+
222
+ response = tokenizer.decode(outputs[0], skip_special_tokens=True)
223
+ print(response)
224
+ ```
225
+
226
+ ### Pipeline Usage
227
+
228
+ ```python
229
+ from transformers import pipeline
230
+
231
+ # Create text generation pipeline
232
+ pipe = pipeline(
233
+ "text-generation",
234
+ model=model,
235
+ tokenizer=tokenizer,
236
+ max_new_tokens=512,
237
+ temperature=0.7,
238
+ top_p=0.9,
239
+ do_sample=True
240
+ )
241
+
242
+ # Generate impression
243
+ findings_text = "[CLINIC: clinic_1] [MODALITY: CT] FINDINGS: ..."
244
+ result = pipe(findings_text)
245
+ print(result[0]['generated_text'])
246
+ ```
247
+
248
+ ### Merging Adapter with Base Model
249
+
250
+ ```python
251
+ from peft import AutoPeftModelForCausalLM
252
+
253
+ # Load and merge
254
+ model = AutoPeftModelForCausalLM.from_pretrained(
255
+ "sabber/medphi-radiology-summary-adapter",
256
+ torch_dtype="auto",
257
+ device_map="auto"
258
+ )
259
+ merged_model = model.merge_and_unload()
260
+
261
+ # Save merged model
262
+ merged_model.save_pretrained("medphi-radiology-merged")
263
+ tokenizer.save_pretrained("medphi-radiology-merged")
264
+ ```
265
+
266
+ ## Input Format
267
+
268
+ The model expects inputs in the following format:
269
+
270
+ ```
271
+ [CLINIC: <clinic_id>] [MODALITY: <modality_code>] FINDINGS: <detailed_findings>
272
+
273
+ IMPRESSION:
274
+ ```
275
+
276
+ **Supported Modalities:**
277
+ - `MR` - Magnetic Resonance Imaging
278
+ - `CT` - Computed Tomography
279
+ - `CR` - Computed Radiography
280
+ - `US` - Ultrasound
281
+ - `XR` - X-Ray
282
+ - `NM` - Nuclear Medicine
283
+
284
+ **Clinic IDs:** `clinic_1` through `clinic_6`
285
+
286
+ ## Limitations and Bias
287
+
288
+ ### Limitations
289
+
290
+ 1. **Training Data Scope:** Model trained on reports from 6 specific clinical institutions
291
+ 2. **Modality Imbalance:** Performance varies by modality; best on high-volume types (MR, CT, CR)
292
+ 3. **Language:** English only
293
+ 4. **Clinical Validation:** Requires human radiologist review before clinical use
294
+ 5. **Nuclear Medicine:** Shows degraded performance (-16.6%) due to limited training samples
295
+
296
+ ### Bias Considerations
297
+
298
+ - **Institutional Bias:** May reflect reporting styles of the 6 training institutions
299
+ - **Modality Bias:** 60% of training data is MR imaging, which may bias outputs
300
+ - **Geographic Bias:** Training data from specific geographic regions
301
+ - **Sample Filtering:** Quality filtering may introduce bias toward certain finding types
302
+
303
+ ### Ethical Considerations
304
+
305
+ - **Not for Clinical Diagnosis:** This model is a research tool and should NOT be used for clinical decision-making without expert radiologist review
306
+ - **Data Privacy:** Trained on de-identified data only
307
+ - **Accountability:** Human radiologists must review and validate all generated impressions
308
+ - **Transparency:** Users should be informed when AI-generated content is used
309
+
310
+ ## Intended Use
311
+
312
+ ### Primary Use Cases
313
+
314
+ ✅ **Research:** Studying automated radiology report generation
315
+ ✅ **Education:** Teaching radiology reporting conventions
316
+ ✅ **Augmentation:** Assisting radiologists with draft impression generation
317
+ ✅ **Analysis:** Understanding clinical language patterns in radiology
318
+
319
+ ### Out-of-Scope Use
320
+
321
+ ❌ **Autonomous Diagnosis:** Not validated for unsupervised clinical use
322
+ ❌ **Non-Radiology Domains:** Not trained for other medical specialties
323
+ ❌ **Non-English Reports:** Only trained on English language reports
324
+ ❌ **Rare Conditions:** May not handle uncommon pathologies well
325
+
326
+ ## Citation
327
+
328
+ If you use this model in your research, please cite:
329
+
330
+ ```bibtex
331
+ @misc{medphi-radiology-adapter,
332
+ author = {Sabber Ahamed},
333
+ title = {MediPhi Radiology Summary Adapter: LoRA Fine-tuning for Automated Impression Generation},
334
+ year = {2025},
335
+ publisher = {Hugging Face},
336
+ howpublished = {\url{https://huggingface.co/sabber/medphi-radiology-summary-adapter}},
337
+ note = {Fine-tuned on 30,135 de-identified radiology reports across 6 clinical institutions}
338
+ }
339
+ ```
340
+
341
+ ## Model Card Authors
342
+
343
+ Sabber Ahamed
344
+
345
+ ## Model Card Contact
346
+
347
+ For questions or issues, please open an issue on the [model repository](https://huggingface.co/sabber/medphi-radiology-summary-adapter/discussions).
348
+
349
+ ## Acknowledgments
350
+
351
+ - **Base Model:** Microsoft Phi-3.5-mini-instruct team
352
+ - **Framework:** Hugging Face Transformers, PEFT, and TRL libraries
353
+ - **Compute:** RunPod for GPU infrastructure
354
+ - **Data:** Contributing clinical institutions (anonymized)
355
+
356
+ ## Additional Resources
357
+
358
+ - **Paper:** [Link to technical report if available]
359
+ - **Code Repository:** [Link to training code repository]
360
+ - **Demo:** [Link to demo if available]
361
+
362
+ ---
363
+
364
+ **Disclaimer:** This model is provided for research and educational purposes only. It is not approved for clinical use. All outputs must be reviewed and validated by qualified healthcare professionals before any clinical application.