This project fine-tunes a domain-specific transformer model, ClinicalBERT, to predict diseases from natural language symptom descriptions.
Unlike traditional models that rely on keyword matching, ClinicalBERT captures the deep semantic understanding of patient complaints — enabling a more accurate and context-aware diagnosis pipeline.
The dataset contains structured mappings between symptoms and diagnosed diseases:
dataset.csv: Symptom descriptions and labelssymptom_description.csv: Full definitions of symptomssymptom_precaution.csv: Suggested precautions for each diseaseSymptom_severity.csv: Severity levels for all known symptoms
✅ Diseases are evenly distributed to avoid bias during training.
- Convert symptom keywords into natural human-like sentences
- Encode disease labels using
LabelEncoder - Tokenize with
Bio_ClinicalBERTtokenizer - Fine-tune ClinicalBERT using Hugging Face
Trainer - Evaluate using Accuracy, Precision, Recall, F1-score
- Save model, tokenizer, and label encoder
- Load fine-tuned ClinicalBERT, tokenizer, and label encoder
- Accept natural symptom inputs like:
"I've been throwing up and my joints hurt, I don’t feel like eating" - Predict Top 3 Diseases with confidence scores
- Visualize predictions with:
- ✅ SHAP graphs for symptom-level explainability
- ✅ LIME explanations to interpret prediction logic
- ✅ Cosine similarity heatmap of disease embeddings
After 10 epochs of training, the model achieved:
| Metric | Value |
|---|---|
| Accuracy | 100% ✅ |
| Precision | 100% ✅ |
| Recall | 100% ✅ |
| F1 Score | 100% ✅ |
📌 Reasons:
- Clear, natural symptom phrasing
- Balanced dataset
- Domain-specific medical language model (ClinicalBERT)
Input:
"Acidity, headache, and depression with loss of appetite"
Prediction:
Top Predicted Diseases:
Typhoid (21.6%) Migraine (15.4%) Malaria (11.5%
✔️ Followed by SHAP explanation plot + cosine similarity heatmap
- SHAP Plot: Highlights which words contributed most to the prediction
- LIME: Shows token-level influence on classification
- Cosine Similarity Heatmap: Reveals disease embedding closeness (e.g., Typhoid and Malaria are similar)
- Model: Bio_ClinicalBERT
- Data: Publicly available symptom-disease datasets from Kaggle
- Frameworks: