Downloads · 30 days
199
33% of all-time downloads
anaschahid/medical-specialty-classifier
medical-specialty-classifier is a text classification model from anaschahid. Use it when you need a label for a piece of text. The card lists the license as apache-2.0.
This model is a fine-tuned version of microsoft/BiomedNLP-PubMedBERT-base-uncased-abstract-fulltext for classifying medical text into different medical specialties. This model uses class weights to handle imbalanced d…
Downloads · 30 days
199
33% of all-time downloads
All-time downloads
609
Public
Parameters
109M
438 MB on disk
Likes
0
Public
Click a slice to open those files.
.safetensors438 MB · 100%
From the Hugging Face model README
This model is a fine-tuned version of microsoft/BiomedNLP-PubMedBERT-base-uncased-abstract-fulltext for classifying medical text into different medical specialties. This model uses class weights to handle imbalanced data and was trained on an augmented dataset, ensuring better performance across all medical specialties, including rare ones.
This model classifies medical texts/posts into the following medical specialties:
Cardiology, Dentistry, Dermatology, Endocrinology, Gastroenterology, Infectious Disease, Nephrology, Neurology, Ophthalmology, Orthopedics, Otorhinolaryngology, Pulmonology, Urology
The training dataset was augmented using nlpaug via synonym replacement to improve model accuracy and decrease overfitting.
The following class weights were applied during training:
Cardiology: 1.4356
Dentistry: 4.0576
Dermatology: 1.1171
Endocrinology: 1.5485
Gastroenterology: 0.3864
Infectious Disease: 1.2777
Nephrology: 7.0353
Neurology: 1.0701
Ophthalmology: 1.6641
Orthopedics: 0.2808
Otorhinolaryngology: 0.9669
Pulmonology: 2.0021
Urology: 2.6795
The following confusion matrices show the model's classification performance across all medical specialties:

Confusion matrix showing raw prediction counts and percentages for each medical specialty

Normalized confusion matrix showing prediction accuracy rates by true class
Training progress and performance metrics throughout the fine-tuning process:

Training and validation loss curves showing model convergence


Accuracy and F1-score progression during training
from transformers import BertTokenizer, BertForSequenceClassification
import torch
# Load the model and tokenizer
model = BertForSequenceClassification.from_pretrained("anaschahid/medical-specialty-classifier")
tokenizer = BertTokenizer.from_pretrained("anaschahid/medical-specialty-classifier")
# Example usage
def classify_medical_text(text):
inputs = tokenizer(text, return_tensors="pt", truncation=True, padding=True, max_length=512)
with torch.no_grad():
outputs = model(**inputs)
predicted_class_id = torch.argmax(outputs.logits, dim=-1).item()
predicted_specialty = model.config.id2label[predicted_class_id]
return predicted_specialty
# Example
text = "patient has a broken leg from a fall"
specialty = classify_medical_text(text)
print(f"Predicted specialty: {specialty}")
This model is intended for research and educational purposes in the medical domain. It should not be used for actual medical diagnosis or treatment decisions.
If you use this model in your research, please cite:
@misc{fine-tuned-biomedbert-medical-specialty-augmented,
title={Fine-tuned BiomedNLP-PubMedBERT for Medical Specialty Classification with Data Augmentation},
author={Anas Chahid},
year={2025},
howpublished={\url{https://huggingface.co/anaschahid/medical-specialty-classifier}},
note={Medical specialty classification with augmented training data and class weights}
}