DEV Community

Sheikh Sadi Asif
Sheikh Sadi Asif

Posted on

I Built an AI That Predicts Medical Specialties from Clinical Notes (End-to-End Deployment)

Hey DEV community πŸ‘‹

I recently built and deployed a full-stack AI system that predicts medical specialties from clinical text using ClinicalBERT, and I wanted to share the full journey from training to deployment. This is part of my project under GradienNinja / Astrolabsoft.

Link https://astrolab-medical-ai.netlify.app/


πŸš€ What I Built

I built an AI system that:

  • Takes clinical notes as input
  • Predicts the most likely medical specialty
  • Returns top 3 predictions with confidence scores
  • Runs as a fully deployed web application

Example Input

Patient is a 62-year-old male with chest pain radiating to the left arm, shortness of breath, sweating, and nausea. Symptoms worsen on exertion and improve with rest.


Example Output

Primary: Cardiovascular / Pulmonary

Confidence: 82%

Top 3 Predictions:

  • Cardiovascular / Pulmonary
  • General Medicine
  • SOAP / Clinical Notes

Tech Stack

  • Python
  • PyTorch
  • Hugging Face Transformers
  • ClinicalBERT
  • FastAPI (backend API)
  • HTML / CSS / JavaScript (frontend)
  • Netlify (frontend hosting)
  • Hugging Face Spaces (model deployment)

System Architecture

Frontend (Netlify UI)
↓
POST request (/predict)
↓
FastAPI backend (Hugging Face Space)
↓
ClinicalBERT model inference
↓
JSON response
↓
Frontend renders prediction


Why ClinicalBERT?

I used ClinicalBERT because it is pretrained on biomedical and clinical text, which gives it a strong understanding of:

  • Medical terminology
  • Symptoms and conditions
  • Clinical documentation style

This significantly improves prediction quality compared to generic NLP models.


Deployment

  • Backend: Hugging Face Spaces (FastAPI)
  • Frontend: Netlify (HTML/CSS/JS)
  • Fully API-based architecture

The system behaves like a lightweight AI SaaS product.


Challenges I Faced

  • Handling class imbalance in medical dataset
  • Long clinical notes exceeding token limits
  • Low confidence in ambiguous symptom cases
  • CORS issues between frontend and backend
  • Deployment debugging in Hugging Face Spaces

πŸ“ˆ What I Learned

This project taught me that:

  • Training a model is only 30% of the work
  • Deployment is where real engineering begins
  • Data quality matters more than model complexity
  • API design is critical for real-world AI systems
  • End-to-end thinking is required for production AI

πŸš€ Future Improvements

I plan to upgrade this system into:

  • Medical triage assistant (risk level detection)
  • Explainable AI (why model made a prediction)
  • Multi-label diagnosis support
  • Better dataset balancing
  • Hospital workflow integration

πŸ’¬ Final Thoughts

This project made me realize:

β€œBuilding AI models is easy. Building usable AI systems is hard.”

This is just the beginning of my journey in building real-world AI products.

If anyone is working on AI + healthcare systems, feel free to connect

AI #MachineLearning #NLP #HuggingFace #FastAPI #HealthcareAI #Python

Top comments (0)