sweatSmile commited on
Commit
a1eff34
Β·
verified Β·
1 Parent(s): 1ac7234

Update README.md

Browse files
Files changed (1) hide show
  1. README.md +234 -3
README.md CHANGED
@@ -1,3 +1,234 @@
1
- ---
2
- license: apache-2.0
3
- ---
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ---
2
+ license: gemma
3
+ base_model: google/gemma-2-2b-it
4
+ tags:
5
+ - gemma
6
+ - gemma2
7
+ - medical
8
+ - healthcare
9
+ - medical-qa
10
+ - fine-tuned
11
+ - lora
12
+ - instruct
13
+ - 4bit
14
+ language:
15
+ - en
16
+ library_name: transformers
17
+ pipeline_tag: text-generation
18
+ datasets:
19
+ - lavita/ChatDoctor-HealthCareMagic-100k
20
+ ---
21
+
22
+ # Gemma-2-2B Medical Q&A Assistant πŸ₯
23
+
24
+ This is a fine-tuned version of [google/gemma-2-2b-it](https://huggingface.co/google/gemma-2-2b-it) specialized for medical question answering. The model has been trained on real patient-doctor conversations to provide helpful, accurate medical information with appropriate safety disclaimers.
25
+
26
+ ## 🎯 Model Details
27
+
28
+ - **Base Model**: Gemma-2-2B-Instruct (2B parameters)
29
+ - **Fine-tuning Method**: LoRA (Low-Rank Adaptation)
30
+ - **Quantization**: 4-bit (nf4) for efficient training and inference
31
+ - **Dataset**: ChatDoctor-HealthCareMagic (1,500 curated samples)
32
+ - **Domain**: Medical Q&A, Healthcare Information
33
+ - **Use Case**: Medical information assistant, health education, preliminary medical guidance
34
+
35
+ ## πŸ”§ Training Configuration
36
+
37
+ ### LoRA Parameters
38
+ - **Rank (r)**: 8
39
+ - **Alpha**: 16
40
+ - **Dropout**: 0.1
41
+ - **Target Modules**: All linear layers
42
+
43
+ ### Training Hyperparameters
44
+ - **Epochs**: 3
45
+ - **Learning Rate**: 2e-5
46
+ - **Batch Size**: 4 per device
47
+ - **Max Sequence Length**: 1024 tokens (for detailed medical responses)
48
+ - **Scheduler**: Cosine with 10% warmup
49
+ - **Optimizer**: AdamW with weight decay (0.01)
50
+ - **Precision**: BF16
51
+ - **Gradient Clipping**: 1.0
52
+
53
+ ### Training Infrastructure
54
+ - **Hardware**: Single GPU (T4/V100/A100)
55
+ - **Training Time**: ~30-45 minutes
56
+ - **Framework**: TRL + Transformers + PEFT
57
+
58
+ ## πŸ“Š Dataset
59
+
60
+ The model was fine-tuned on a curated subset of the [ChatDoctor-HealthCareMagic-100k](https://huggingface.co/datasets/lavita/ChatDoctor-HealthCareMagic-100k) dataset, which contains:
61
+ - Real patient questions from HealthCareMagic platform
62
+ - Professional doctor responses
63
+ - Diverse medical topics (symptoms, treatments, medications, preventive care)
64
+ - Privacy-preserved and ethically sourced data
65
+
66
+ **Training Samples**: 1,500 high-quality medical Q&A pairs
67
+
68
+ ## πŸ’» Usage
69
+
70
+ ### Basic Inference
71
+
72
+ ```python
73
+ from transformers import AutoModelForCausalLM, AutoTokenizer
74
+
75
+ model_name = "sweatSmile/Gemma-2-2B-MedicalQA-Assistant"
76
+ tokenizer = AutoTokenizer.from_pretrained(model_name)
77
+ model = AutoModelForCausalLM.from_pretrained(model_name)
78
+
79
+ # Format your medical query
80
+ prompt = """<start_of_turn>user
81
+ I've been experiencing persistent headaches for the past week. What could be causing this?<end_of_turn>
82
+ <start_of_turn>model
83
+ """
84
+
85
+ inputs = tokenizer(prompt, return_tensors="pt")
86
+ outputs = model.generate(
87
+ **inputs,
88
+ max_new_tokens=256,
89
+ temperature=0.7,
90
+ top_p=0.9,
91
+ do_sample=True
92
+ )
93
+
94
+ response = tokenizer.decode(outputs[0], skip_special_tokens=True)
95
+ print(response)
96
+ ```
97
+
98
+ ### 4-bit Quantized Inference (Recommended)
99
+
100
+ ```python
101
+ from transformers import AutoModelForCausalLM, AutoTokenizer, BitsAndBytesConfig
102
+ import torch
103
+
104
+ quantization_config = BitsAndBytesConfig(
105
+ load_in_4bit=True,
106
+ bnb_4bit_quant_type="nf4",
107
+ bnb_4bit_compute_dtype=torch.float16
108
+ )
109
+
110
+ model = AutoModelForCausalLM.from_pretrained(
111
+ "sweatSmile/Gemma-2-2B-MedicalQA-Assistant",
112
+ quantization_config=quantization_config,
113
+ device_map="auto"
114
+ )
115
+ tokenizer = AutoTokenizer.from_pretrained("sweatSmile/Gemma-2-2B-MedicalQA-Assistant")
116
+ ```
117
+
118
+ ## 🩺 Example Outputs
119
+
120
+ **Query**: "What are the common symptoms of diabetes?"
121
+
122
+ **Response**:
123
+ > Common symptoms of Type 2 diabetes include frequent urination, increased thirst, unexplained weight loss, fatigue, blurred vision, slow-healing wounds, and tingling or numbness in hands or feet. If you're experiencing multiple symptoms, it's important to get your blood sugar levels checked. Early detection and management are crucial.
124
+ >
125
+ > βš•οΈ Disclaimer: This information is for educational purposes only. Please consult a qualified healthcare professional for medical advice.
126
+
127
+ ---
128
+
129
+ **Query**: "How can I manage high blood pressure naturally?"
130
+
131
+ **Response**:
132
+ > Natural management of high blood pressure includes: regular exercise (30 minutes daily), reducing sodium intake, maintaining healthy weight, limiting alcohol, managing stress through meditation or yoga, eating potassium-rich foods (bananas, leafy greens), and ensuring adequate sleep. However, these should complement, not replace, prescribed medications.
133
+ >
134
+ > βš•οΈ Disclaimer: This information is for educational purposes only. Please consult a qualified healthcare professional for medical advice.
135
+
136
+ ## ⚠️ Important Limitations & Safety
137
+
138
+ ### Medical Disclaimers
139
+ - 🚨 **NOT A REPLACEMENT FOR PROFESSIONAL MEDICAL ADVICE**: This model provides general health information only
140
+ - 🚨 **Always consult a qualified healthcare provider** for diagnosis and treatment
141
+ - 🚨 **Emergency situations**: Call emergency services immediately for urgent medical conditions
142
+ - 🚨 **Individual variation**: Medical advice must be personalized to your specific situation
143
+
144
+ ### Model Limitations
145
+ - Trained on 1,500 samples - may not cover all medical scenarios
146
+ - Limited to English language medical terminology
147
+ - May not reflect the most recent medical research (knowledge cutoff dependent on base model)
148
+ - Cannot perform physical examinations or order diagnostic tests
149
+ - May occasionally generate plausible-sounding but incorrect information (hallucinations)
150
+ - Not validated against clinical benchmarks
151
+
152
+ ### Appropriate Use Cases βœ…
153
+ - General health education and information
154
+ - Understanding common medical terms and conditions
155
+ - Preliminary research before doctor's appointments
156
+ - Health literacy improvement
157
+ - Medical training assistance (with supervision)
158
+
159
+ ### Inappropriate Use Cases ❌
160
+ - Self-diagnosis or self-treatment
161
+ - Emergency medical situations
162
+ - Replacing professional medical consultations
163
+ - Making critical healthcare decisions
164
+ - Prescribing medications or treatments
165
+ - Mental health crisis intervention
166
+
167
+ ## πŸŽ“ Intended Use
168
+
169
+ This model is designed for:
170
+ - **Educational purposes**: Teaching and learning about common health conditions
171
+ - **Health information access**: Providing accessible medical knowledge
172
+ - **Research**: Medical AI and NLP research
173
+ - **Prototyping**: Building healthcare chatbot prototypes
174
+ - **Medical training**: Supplementary tool for medical students (with instructor oversight)
175
+
176
+ ## πŸ“ˆ Performance Notes
177
+
178
+ - **Strengths**: Common conditions, preventive care, general wellness advice, medical terminology
179
+ - **Best performance on**: Questions similar to training distribution (patient-doctor Q&A format)
180
+ - **Quantization**: 4-bit quantization maintains ~95% of full precision performance with significant memory savings
181
+
182
+ ## πŸ”¬ Technical Specifications
183
+
184
+ | Specification | Value |
185
+ |--------------|-------|
186
+ | Base Architecture | Gemma 2 (Google) |
187
+ | Model Size | 2B parameters |
188
+ | Quantization | 4-bit (nf4) |
189
+ | Context Window | 8,192 tokens |
190
+ | Training Tokens | ~1.5M medical tokens |
191
+ | LoRA Rank | 8 |
192
+ | LoRA Alpha | 16 |
193
+ | Trainable Parameters | ~4.2M (0.2% of base) |
194
+
195
+ ## πŸ“ Citation
196
+
197
+ ```bibtex
198
+ @misc{gemma2-medical-qa-2025,
199
+ author = {sweatSmile},
200
+ title = {Gemma-2-2B Medical Q&A Assistant},
201
+ year = {2025},
202
+ publisher = {HuggingFace},
203
+ journal = {HuggingFace Model Hub},
204
+ howpublished = {\url{https://huggingface.co/sweatSmile/Gemma-2-2B-MedicalQA-Assistant}}
205
+ }
206
+ ```
207
+
208
+ ## πŸ™ Acknowledgments
209
+
210
+ - **Base Model**: Google's Gemma team for the excellent Gemma-2-2B-Instruct model
211
+ - **Dataset**: ChatDoctor team and HealthCareMagic for the medical Q&A dataset
212
+ - **Framework**: HuggingFace TRL, Transformers, and PEFT libraries
213
+
214
+ ## πŸ“œ License
215
+
216
+ This model inherits the [Gemma License](https://ai.google.dev/gemma/terms) from the base model. The fine-tuned weights are released under the same terms.
217
+
218
+ **Usage Restrictions**: Please review Google's Gemma Terms of Use, particularly regarding healthcare applications.
219
+
220
+ ## βš–οΈ Ethical Considerations
221
+
222
+ - Model outputs should always include medical disclaimers
223
+ - Designed to encourage users to seek professional medical advice
224
+ - Training data sourced ethically from publicly available patient-doctor interactions
225
+ - No personally identifiable information (PII) in training data
226
+ - Built with safety alignment from base Gemma-2 model
227
+
228
+ ## πŸ”„ Version History
229
+
230
+ - **v1.0** (Current): Initial release with 1.5k samples, LoRA fine-tuning
231
+
232
+ ---
233
+
234
+ **Disclaimer**: This model is a research prototype and educational tool. It is not intended for clinical use or as a substitute for professional medical advice, diagnosis, or treatment. Always seek the advice of your physician or other qualified health provider with any questions you may have regarding a medical condition.