sugan04/healthbot-crs
1
๐ฅ HealthBot-CRS โ Clinical Response System
Group: DSA2021018 Live Demo: https://sugan04-healthbot-crs.hf.space โ ๏ธ Research Prototype โ Not a substitute for professional medical advice.
๐ Problem Statement
Patients often struggle to access quick, reliable answers to health-related questions outside of clinical settings. HealthBot-CRS addresses this by building an intelligent, ML-powered Clinical Response System that classifies patient intent, retrieves the most relevant medical response, and delivers it through a conversational chatbot interface โ complete with multilingual text-to-speech support.
๐๏ธ Dataset
- Source: ChatDoctor-HealthCareMagic-100k
- Size: 100,000 patient-doctor Q&A pairs
- Working sample: 5,000 rows (stratified, for development)
- Intent categories:
emergency,symptom_inquiry,medication_inquiry,diagnostics,lifestyle,mental_health,general_inquiry
๐๏ธ System Architecture
Raw Data (100k Q&A)
โ
01. Data Loading & Cleaning (NLTK, Regex)
โ
02. Feature Engineering (TF-IDF + SBERT + SpaCy NER)
โ
03. Clustering (K-Means on SBERT embeddings)
โ
04. Classification (LR, RF, SVM, GB, MLP)
โ
05. Recommender System (SVD, NMF, KNN โ Surprise-style hybrid)
โ
06. Evaluation & Error Analysis (F1, ROC, Confusion Matrix)
โ
08. Flask API + Chat UI (deployed on Hugging Face Spaces)โ๏ธ Tech Stack & Libraries
๐ ML Pipeline
Step 1 โ Data Loading (01_data_loading.py)
- Loaded 100k records from HuggingFace datasets
- Cleaned text: lowercased, removed URLs, emails, special characters
- Rule-based intent labelling across 7 categories
- Filtered low-quality rows (too short/long)
- Final sample: 5,000 rows saved to
data/healthbot_sample.csv
Step 2 โ Feature Engineering (02_feature_engineering.py)
- TF-IDF: 5,000 features, bigrams, sublinear TF weighting
- SBERT:
all-MiniLM-L6-v2sentence embeddings (384 dimensions) - SpaCy NER: Medical entity extraction (symptoms, medications, conditions)
- Combined feature matrix: TF-IDF + SBERT โ input to classifiers
Step 3 โ Clustering (03_clustering.py)
- Applied K-Means on SBERT embeddings
- Optimal K selected via Elbow method and Silhouette score
- Cluster labels used as user profiles for the recommender system
Step 4 โ Classification (04_classification.py)
- Trained 5 classifiers on combined TF-IDF + SBERT features:
- Logistic Regression, Random Forest, SVM, Gradient Boosting, MLP
- Best model selected automatically at runtime by weighted F1 score
Step 5 โ Recommender System (05_recommender.py)
- Built implicit rating matrix from cluster ร intent interactions
- Trained SVD, NMF, and KNN collaborative filtering models
- Hybrid scoring:
ฮฑ ร content-based + (1-ฮฑ) ร collaborative filtering
Step 6 โ Evaluation (06_evaluation.py, 06b_error_analysis.py)
- Metrics: Weighted F1, Precision, Recall, Accuracy
- Confusion matrix, ROC curves per intent class
- Error analysis: low-confidence predictions and misclassified intents
๐ Results
Best model is auto-selected at runtime. Hybrid recommender combines SBERT cosine similarity with CF ratings for improved retrieval quality.
๐ก Innovativeness
- Hybrid CB+CF Retrieval: Combines content-based SBERT similarity with collaborative filtering โ most chatbots use only one approach
- Multilingual TTS: Real-time French translation + voice output via Web Speech API and MyMemory API
- Live Deployment: Fully containerized with Docker and hosted on Hugging Face Spaces
- Clinical NER: SpaCy-based medical entity extraction to enrich feature representation
๐ How to Run Locally
# 1. Clone the repo
git clone https://huggingface.co/spaces/sugan04/healthbot-crs
cd healthbot-crs
# 2. Install dependencies
pip install -r requirements.txt
python -m spacy download en_core_web_sm
# 3. Run full ML pipeline
python 01_data_loading.py
python 02_feature_engineering.py
python 03_clustering.py
python 04_classification.py
python 05_recommender.py
python 06_evaluation.py
# 4. Launch chatbot API
python 08_chatbot.py --api
# 5. Open in browser
# http://localhost:7860๐ File Structure
healthbot-crs/
โโโ 01_data_loading.py # Data loading & cleaning
โโโ 02_feature_engineering.py # TF-IDF, SBERT, SpaCy NER
โโโ 03_clustering.py # K-Means clustering
โโโ 04_classification.py # 5 classifier models
โโโ 05_recommender.py # SVD/NMF/KNN recommender
โโโ 06_evaluation.py # Metrics & ROC curves
โโโ 06b_error_analysis.py # Error analysis
โโโ 08_chatbot.py # Flask API + CLI chatbot
โโโ HealthBot_CRS_Chat.html # Chat UI
โโโ HealthBot_CRS_Demo.html # Landing page
โโโ requirements.txt
โโโ Dockerfile
โโโ data/
โ โโโ healthbot_sample.csv
โ โโโ healthbot_clustered.csv
โโโ outputs/
โโโ models/ # Trained .pkl files
โโโ plots/ # Visualizations
โโโ results/ # Embeddings & matrices๐ฅ Group
DSA_202101_8 Course: Data Science & Analytics Deployment: https://sugan04-healthbot-crs.hf.space
