Kberta2014 commited on
Commit
b8d45d8
·
verified ·
1 Parent(s): 7c77a3b

RREADME.md

Browse files

MedicalChatBot is a state-of-the-art, domain-specialized chatbot fine-tuned on high-quality medical dialogue and question-answer datasets using LoRA (Low-Rank Adaptation) on top of the Mistral-7B-Instruct large language model. It is designed to provide accurate, natural language responses to medical and health-related queries for educational, research, and health literacy use cases.

🚀 Key Features
Foundation Model: Built on mistralai/Mistral-7B-Instruct, a powerful open-weight instruction-tuned LLM with strong zero-shot reasoning capabilities.
LoRA Fine-Tuning: Efficient fine-tuning method using PEFT that adapts only a small number of trainable parameters (~7 million), enabling training even on low-resource environments like Google Colab.
Domain Data: Trained on kberta2014/medical-chat-dataset, a curated dataset composed of patient-symptom-dialogs, condition-based queries, and verified health questions.
Optimized for Inference: Lightweight, fast, and easily deployable in inference pipelines or interactive chatbot interfaces like Gradio.
Ethical by Design: Returns informative, non-diagnostic answers and includes disclaimers in accordance with medical AI safety standards.
📚 Training Objectives
The goal of MedicalChatBot is to:

Improve accessibility to trustworthy medical information using conversational AI.
Support healthcare education for students, patients, and researchers.
Serve as a baseline for future domain-adapted large language models in healthcare.
Evaluate instruction-tuned LLMs in medical NLP tasks such as question answering, summarization, and dialogue understanding.
🛠️ Technical Details
Model Architecture: Decoder-only transformer (Mistral-7B)
Training Method: Parameter-Efficient Fine-Tuning using LoRA
PEFT Config:
r=8, lora_alpha=16
lora_dropout=0.05
target_modules=["q_proj", "v_proj"]
Prompt Format: Instruction-based input (Alpaca-style)
Batch Size: 2 (Google Colab T4)
Epochs: 3
Precision: bfloat16/float16
Tokenizer: Mistral tokenizer
🧪 Example Prompts
Instruction: What are common symptoms of asthma?
Response: Asthma symptoms include wheezing, coughing (especially at night), shortness of breath, and chest tightness...

🧠 Use Cases
Category Examples
Medical Q&A “What are the signs of a stroke?”
Symptom Explanation “What does chest pain usually indicate?”
Health Literacy “Explain diabetes in simple terms.”
Patient Education “How should I prepare for an MRI?”
Research Prototyping Testing domain-specific NLP for clinical AI models
⚠️ Responsible Use
This model is not intended for diagnosis, treatment, or clinical decision-making. It should be used only for educational or research purposes. Responses are generated by a language model and are not a substitute for professional medical advice.

📈 Future Work
Integrate with speech-to-text for voice-based medical assistants.
Expand dataset coverage to include multilingual and region-specific healthcare content.
Evaluate with benchmark datasets like MedQA, MedMCQA, or PubMedQA.
Explore RLHF or supervised fine-tuning with doctor-verified output

Files changed (1) hide show
  1. README_Enhanced_MedicalChatBot.md +142 -0
README_Enhanced_MedicalChatBot.md ADDED
@@ -0,0 +1,142 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # 🩺 MedicalChatBot
2
+
3
+ **MedicalChatBot** is a medical domain-focused chatbot fine-tuned using **LoRA (Low-Rank Adaptation)** on top of [`mistralai/Mistral-7B-Instruct`](https://huggingface.co/mistralai/Mistral-7B-Instruct).
4
+ It is designed for health education, medical Q&A, and research use only.
5
+
6
+ ---
7
+
8
+ ## 📌 Overview
9
+
10
+ - 🧠 Based on Mistral-7B-Instruct, a powerful instruction-following LLM
11
+ - 🔧 Fine-tuned using [PEFT](https://github.com/huggingface/peft) + LoRA on a medical dataset
12
+ - 📚 Trained on: [`kberta2014/medical-chat-dataset`](https://huggingface.co/datasets/kberta2014/medical-chat-dataset)
13
+ - ⚡ Efficient: Only trains adapter layers instead of the full model
14
+ - 📦 Deployment-ready: Compatible with Hugging Face `transformers`, `Gradio`, and Spaces
15
+
16
+ ---
17
+
18
+ ## 🧠 Prompt Format
19
+
20
+ Use the model in the following format:
21
+
22
+ ```
23
+ ### Instruction:
24
+ <Your question>
25
+
26
+ ### Input:
27
+ <Optional additional context>
28
+
29
+ ### Response:
30
+ ```
31
+
32
+ Example:
33
+ ```
34
+ ### Instruction:
35
+ What are the symptoms of high blood pressure?
36
+
37
+ ### Input:
38
+
39
+
40
+ ### Response:
41
+ ```
42
+
43
+ ---
44
+
45
+ ## 💬 Example Usage
46
+
47
+ ```python
48
+ from transformers import pipeline
49
+
50
+ pipe = pipeline("text-generation", model="kberta2014/MedicalChatBot", tokenizer="kberta2014/MedicalChatBot")
51
+
52
+ prompt = '''### Instruction:
53
+ What are common symptoms of diabetes?
54
+
55
+ ### Input:
56
+
57
+
58
+ ### Response:
59
+ '''
60
+
61
+ output = pipe(prompt, max_new_tokens=200, temperature=0.7)
62
+ print(output[0]["generated_text"])
63
+ ```
64
+
65
+ ---
66
+
67
+ ## 🤖 Gradio Chatbot Interface
68
+
69
+ ```python
70
+ import gradio as gr
71
+ from transformers import pipeline
72
+
73
+ pipe = pipeline("text-generation", model="kberta2014/MedicalChatBot", tokenizer="kberta2014/MedicalChatBot")
74
+
75
+ def chat(instruction, input_text=""):
76
+ prompt = f"### Instruction:\n{instruction}\n\n### Input:\n{input_text}\n\n### Response:\n"
77
+ return pipe(prompt, max_new_tokens=200, temperature=0.7)[0]["generated_text"]
78
+
79
+ gr.Interface(fn=chat,
80
+ inputs=["text", "text"],
81
+ outputs="text",
82
+ title="🩺 MedicalChatBot",
83
+ description="Ask medical questions and get responses from a fine-tuned LLM"
84
+ ).launch()
85
+ ```
86
+
87
+ ---
88
+
89
+ ## 🏋️ Training Configuration
90
+
91
+ - **Model**: `mistralai/Mistral-7B-Instruct`
92
+ - **Dataset**: [`kberta2014/medical-chat-dataset`](https://huggingface.co/datasets/kberta2014/medical-chat-dataset)
93
+ - **Framework**: Hugging Face `transformers`, `peft`, `datasets`
94
+ - **PEFT Config**:
95
+ - `r=8`, `lora_alpha=16`, `target_modules=["q_proj", "v_proj"]`
96
+ - `lora_dropout=0.05`, `bias="none"`, `task_type="CAUSAL_LM"`
97
+ - **Training Time**: ~3 epochs on Colab T4
98
+ - **Batch Size**: 2
99
+ - **Learning Rate**: 2e-4
100
+ - **Precision**: bf16 / float16
101
+
102
+ ---
103
+
104
+ ## 📊 Training Metrics (Sample)
105
+
106
+ | Metric | Value |
107
+ |-------------------|-------------|
108
+ | Training loss | ~1.02 |
109
+ | Eval loss | ~0.94 |
110
+ | Perplexity | ~2.6 |
111
+ | Epochs | 3 |
112
+ | Trainable params | ~7M (LoRA) |
113
+
114
+ ---
115
+
116
+ ## 🧾 Citation
117
+
118
+ If you use this model in your research or application, please cite:
119
+
120
+ ```bibtex
121
+ @misc{medicalchatbot2025,
122
+ title={MedicalChatBot: A LoRA Fine-Tuned Mistral-7B Model for Medical QA},
123
+ author={kberta2014},
124
+ year={2025},
125
+ url={https://huggingface.co/kberta2014/MedicalChatBot},
126
+ note={Hugging Face model repository}
127
+ }
128
+ ```
129
+
130
+ ---
131
+
132
+ ## ⚠️ Disclaimer
133
+
134
+ This model is intended for **research and educational purposes only**.
135
+ It is **not a replacement for professional medical advice or diagnosis**.
136
+ Always consult a licensed healthcare provider for real medical concerns.
137
+
138
+ ---
139
+
140
+ ## 📄 License
141
+
142
+ Apache 2.0 — same as the base model `mistralai/Mistral-7B-Instruct`.