This is a LoRA adapter fine-tuned on Microsoft's MediPhi-Instruct for medical question-answering. The model is designed to provide comprehensive, accurate answers to questions about medical diseases, conditions, and health-related topics.
Model Description
Model Type: LoRA Adapter for Causal Language Model
Base Model: microsoft/MediPhi-Instruct (3.8B parameters)
Trainable Parameters: 0.328% (12.5M parameters via LoRA)
Language: English
Domain: Medical/Healthcare
Task: Question Answering, Conversational AI
License: Apache 2.0
Model Purpose
This model serves as a medical assistant chatbot capable of answering user queries about medical conditions, diseases, symptoms, treatments, and genetic disorders. It has been fine-tuned on 16,406 medical Q&A pairs covering a wide range of health topics including rare genetic disorders and common medical conditions.
Key Features
Medical Domain Expertise: Trained on diverse medical Q&A covering diseases and conditions
Comprehensive Responses: Generates detailed explanations including definitions, causes, symptoms, and treatments
Step-by-Step Reasoning: Employs structured thinking for medical information delivery
Efficient Fine-tuning: Uses 4-bit quantization with LoRA for memory efficiency
Patient Education Focus: Optimized for explaining complex medical concepts clearly
Training Data
Dataset Statistics
Total Q&A Pairs: 16,406 medical question-answer pairs
Dataset Size: 21 MB
Data Splits:
Train: 12,304 samples (75%)
Validation: 2,051 samples (12.5%)
Test: 2,051 samples (12.5%)
Data Coverage
The dataset covers a wide range of medical topics including:
Rare Genetic Disorders: Tourette syndrome, Denys-Drash syndrome, etc.
Common Conditions: Dry eye syndrome, immunodeficiency disorders
Medical Concepts: Genetic inheritance patterns, diagnostic methods
Treatment Information: Management strategies, preventive care
Data Format
python
1{2"messages":[3{4"role":"system",5"content":"You are a knowledgeable medical assistant. Provide accurate information about medical conditions and diseases. Always think step by step."6},7{8"role":"user",9"content":"What is [medical condition]?"10},11{12"role":"assistant",13"content":"[Comprehensive medical explanation]"14}15]16}
Training Details
Training Configuration
Framework: PyTorch with Hugging Face Transformers
Fine-tuning Method: LoRA (Low-Rank Adaptation) with SFT (Supervised Fine-Tuning)
Quantization: 4-bit NF4 with double quantization
Compute: Single RTX 5090 GPU (16 vCPU, 141 GB RAM)
1from peft import AutoPeftModelForCausalLM
2from transformers import AutoTokenizer
34# Load model and tokenizer5model = AutoPeftModelForCausalLM.from_pretrained(6"sabber/medphi-medical-qa-adapter",7 torch_dtype="auto",8 device_map="auto"9)10tokenizer = AutoTokenizer.from_pretrained("sabber/medphi-medical-qa-adapter")1112# Prepare conversation13messages =[14{15"role":"system",16"content":"You are a knowledgeable medical assistant. Provide accurate information about medical conditions and diseases. Always think step by step."17},18{19"role":"user",20"content":"What is Type 2 Diabetes and what are its main symptoms?"21}22]2324# Tokenize and generate25inputs = tokenizer.apply_chat_template(26 messages,27 tokenize=True,28 add_generation_prompt=True,29 return_tensors="pt"30).to(model.device)3132outputs = model.generate(33 inputs,34 max_new_tokens=512,35 temperature=0.7,36 top_p=0.9,37 do_sample=True,38 pad_token_id=tokenizer.eos_token_id
39)4041response = tokenizer.decode(outputs[0], skip_special_tokens=True)42print(response)
Pipeline Usage
python
1from transformers import pipeline
23# Create conversational pipeline4pipe = pipeline(5"text-generation",6 model=model,7 tokenizer=tokenizer,8 max_new_tokens=512,9 temperature=0.7,10 top_p=0.9,11 do_sample=True12)1314# Ask medical question15messages =[16{"role":"system","content":"You are a knowledgeable medical assistant. Provide accurate information about medical conditions and diseases. Always think step by step."},17{"role":"user","content":"What causes high blood pressure?"}18]1920result = pipe(messages)21print(result[0]['generated_text'][-1]['content'])
Multi-Turn Conversation
python
1conversation_history =[2{3"role":"system",4"content":"You are a knowledgeable medical assistant. Provide accurate information about medical conditions and diseases. Always think step by step."5}6]78# First question9conversation_history.append({"role":"user","content":"What is asthma?"})10response = generate_response(conversation_history)11conversation_history.append({"role":"assistant","content": response})1213# Follow-up question14conversation_history.append({"role":"user","content":"What triggers asthma attacks?"})15response = generate_response(conversation_history)16print(response)
Merging Adapter with Base Model
python
1from peft import AutoPeftModelForCausalLM
23# Load and merge4model = AutoPeftModelForCausalLM.from_pretrained(5"sabber/medphi-medical-qa-adapter",6 torch_dtype="auto",7 device_map="auto"8)9merged_model = model.merge_and_unload()1011# Save merged model12merged_model.save_pretrained("medphi-medical-qa-merged")13tokenizer.save_pretrained("medphi-medical-qa-merged")
System Prompt
The model uses the following system prompt for optimal performance:
You are a knowledgeable medical assistant. Provide accurate information about
medical conditions and diseases. Always think step by step.
This prompt encourages:
Structured reasoning: Step-by-step explanations
Accuracy focus: Emphasis on providing correct medical information
Training Data Scope: Model trained on 16,406 Q&A pairs; may not cover all medical conditions
Not a Medical Professional: Cannot replace professional medical advice or diagnosis
Language: English only
Clinical Validation: Outputs should be reviewed by healthcare professionals before clinical application
Rare Conditions: Performance may vary for extremely rare or newly discovered conditions
Quantization Effects: 4-bit quantization may affect precision in certain edge cases
Bias Considerations
Dataset Bias: Training data may reflect biases present in medical literature
Language Bias: Trained exclusively on English medical content
Regional Bias: May reflect medical practices and terminology from specific regions
Completeness: May provide more detailed responses for well-documented conditions
Ethical Considerations
Not for Diagnosis: This model should NOT be used for self-diagnosis or medical decision-making
Professional Review Required: All outputs must be reviewed by qualified healthcare professionals
Patient Safety: Users should always consult with licensed medical professionals for health concerns
Transparency: Users should be informed when AI-generated medical content is provided
Privacy: Do not share personally identifiable health information when using this model
Intended Use
Primary Use Cases
✅ Medical Education: Teaching medical concepts and terminology
✅ Patient Information: Providing general information about conditions and diseases
✅ Research Assistant: Helping researchers understand medical concepts
✅ Content Generation: Creating draft content for medical education materials
✅ Conversational AI: Building medical information chatbots and assistants
Out-of-Scope Use
❌ Clinical Diagnosis: Not validated for diagnostic purposes
❌ Treatment Planning: Not suitable for creating treatment plans
❌ Emergency Response: Not appropriate for emergency medical situations
❌ Prescription Decisions: Cannot be used for medication recommendations
❌ Mental Health Crisis: Not designed for crisis intervention or counseling
❌ Legal/Medical Records: Not validated for official medical documentation
Evaluation Benchmarks
The model has been prepared for evaluation on standard medical benchmarks:
MEDQA: Medical Question Answering benchmark
MEDMCQA: Multiple Choice Medical Questions
PubMedQA: Biomedical literature question answering
MMLU Medical Subsets:
Anatomy
Clinical Knowledge
College Medicine
Medical Genetics
Professional Medicine
Note: Comprehensive benchmark results will be added as evaluation completes.
Future Improvements
Suggested enhancements based on current limitations:
Increase LoRA Rank: Higher rank for greater model capacity
Full Precision Training: Use FP32 or FP16 instead of 4-bit quantization
Data Augmentation: Expand training data with more diverse medical sources
Error Analysis: Systematic analysis of model failure cases
Benchmark Evaluation: Complete evaluation on medical QA benchmarks
Multi-lingual Support: Extend to support multiple languages
Clinical Validation: Formal evaluation by medical professionals
Model Architecture
Base Model: MediPhi-Instruct (Phi-3.5-mini-instruct)
Key Components:
Parameters: 3.8 billion
Vocabulary Size: 32,064 tokens
Hidden Dimension: 3,072
Layers: 32 Phi3DecoderLayers
Attention: Multi-head self-attention with rotary positional embeddings
Activation: SiLU (Swish) activation function
Normalization: RMSNorm layer normalization
LoRA Target Modules:
o_proj - Output projection in attention
qkv_proj - Query-Key-Value projection in attention
gate_up_proj - Gate and up projection in MLP
down_proj - Down projection in MLP
Citation
If you use this model in your research, please cite:
bibtex
1@misc{medphi-medical-qa-adapter,
2 author = {Sabber Ahamed},
3 title = {MediPhi Medical QA Adapter: LoRA Fine-tuning for Medical Question Answering},
4 year = {2025},
5 publisher = {Hugging Face},
6 howpublished = {\url{https://huggingface.co/sabber/medphi-medical-qa-adapter}},
7 note = {Fine-tuned on 16,406 medical Q&A pairs for patient education and medical information retrieval}
8}
Please also cite the base MediPhi model:
bibtex
1@article{medphi2024,
2 title={MediPhi: A Medical Language Model},
3 author={Microsoft Research},
4 journal={arXiv preprint},
5 year={2024}
6}
Framework: Hugging Face Transformers, PEFT, and TRL libraries
Compute: GPU infrastructure for model training
Community: Open-source ML and medical NLP communities
Additional Resources
Training Code: Available in project repository
Evaluation Scripts: Provided for reproducibility
Documentation: Comprehensive README with implementation details
Medical Disclaimer: This model is provided for educational and research purposes only. It is NOT approved for clinical use, medical diagnosis, or treatment planning. All medical information should be verified by qualified healthcare professionals. In case of medical emergencies, contact emergency services immediately. Always consult with licensed medical professionals for health concerns and treatment decisions.
Technical Disclaimer: This model may generate incorrect or incomplete information. Users should verify all outputs and use appropriate safeguards when deploying in production environments. The model's responses should be reviewed and validated before any public-facing use.