Downloads · 30 days
9
13% of all-time downloads
Sugandha-Chauhan/BioMistral-7B-SymptomDiagnosis
BioMistral-7B-SymptomDiagnosis is a text classification model from Sugandha-Chauhan. Use it when you need a label for a piece of text. It is set up for transformers. The card lists the license as mit.
Fine-tuned BioMistral-7B for medical symptom classification using QLoRA
Downloads · 30 days
9
13% of all-time downloads
All-time downloads
69
Public
Repo size
110 MB
Likes
0
Public
Click a slice to open those files.
.safetensors54.6 MB · 93%
From the Hugging Face model README
Fine-tuned BioMistral-7B for medical symptom classification using QLoRA
This is a fine-tuned BioMistral-7B model for classifying medical symptoms into 10 common diagnoses. The model was trained using QLoRA (Quantized Low-Rank Adaptation) on a curated dataset of 10,000 symptom-diagnosis pairs, achieving 99.1% accuracy on the test set.
This model is for educational and research purposes ONLY.
| Class ID | Diagnosis | Example Symptoms |
|---|---|---|
| 0 | Acute Bronchitis | cough, chest pain, shortness of breath, mucus production |
| 1 | Anxiety | anxiety and nervousness, rapid heartbeat, shortness of breath, panic attacks |
| 2 | Conjunctivitis due to Allergy | eye redness, itchiness of eye, lacrimation, watery eyes |
| 3 | Eczema | skin rash, skin dryness, itching of skin, abnormal appearing skin |
| 4 | Infectious Gastroenteritis | nausea, vomiting, diarrhea, abdominal cramps |
| 5 | Pneumonia | fever, cough, difficulty breathing, chest pain |
| 6 | Psoriasis | abnormal appearing skin, skin lesion, skin rash |
| 7 | Spondylosis | back pain, neck pain, neck stiffness, limited mobility |
| 8 | Sprain or Strain | joint pain, swelling, bruising, limited movement |
| 9 | Strep Throat | sore throat, fever, difficulty swallowing, swollen lymph nodes |
| Metric | Score |
|---|---|
| Overall Accuracy | 99.1% |
| Precision (weighted) | 99.11% |
| Recall (weighted) | 99.10% |
| F1-Score (weighted) | 99.10% |
| Test Loss | 0.0313 |
| Diagnosis | Accuracy | Precision | Recall | F1-Score | Support |
|---|---|---|---|---|---|
| Acute Bronchitis | 97.0% | 97.98% | 97.0% | 97.49% | 100 |
| Anxiety | 100.0% | 100.0% | 100.0% | 100.0% | 100 |
| Conjunctivitis | 100.0% | 100.0% | 100.0% | 100.0% | 100 |
| Eczema | 100.0% | 100.0% | 100.0% | 100.0% | 100 |
| Gastroenteritis | 100.0% | 100.0% | 100.0% | 100.0% | 100 |
| Pneumonia | 98.0% | 96.08% | 98.0% | 97.03% | 100 |
| Psoriasis | 100.0% | 100.0% | 100.0% | 100.0% | 100 |
| Spondylosis | 100.0% | 97.09% | 100.0% | 98.52% | 100 |
| Sprain or Strain | 97.0% | 100.0% | 97.0% | 98.48% | 100 |
| Strep Throat | 99.0% | 100.0% | 99.0% | 99.50% | 100 |
Error Analysis:
| Metric | Score |
|---|---|
| Validation Accuracy | 97.7% |
| Validation Loss | 0.0576 |
LoRA Config:
- Task Type: SEQ_CLS (Sequence Classification)
- Rank (r): 16
- Alpha: 32
- Dropout: 0.1
- Target Modules: ['q_proj', 'v_proj', 'k_proj', 'o_proj']
- Bias: none
- Trainable Parameters: 13,672,448 (0.19% of total)
BitsAndBytes Config:
- Load in 4-bit: True
- Quantization Type: nf4
- Compute dtype: float16
- Double Quantization: True
Total Parameters: 7,124,373,504
Trainable Parameters: 13,672,448 (0.1919%)
Memory Footprint: ~4.5 GB (4-bit quantized)
Total Samples: 10,000 symptom-diagnosis pairs
| Split | Samples | Percentage |
|---|---|---|
| Train | 8,000 | 80% |
| Validation | 1,000 | 10% |
| Test | 1,000 | 10% |
Data Format:
{
"text": "cough ,fever and difficulty breathing",
"diagnosis": "pneumonia",
"label": 5 # Mapped to class ID
}
Important: Symptoms follow specific formatting:
symptom1 ,symptom2and before last symptom"nausea ,vomiting ,diarrhea and abdominal cramps"| Parameter | Value |
|---|---|
| Training Regime | Supervised Fine-tuning |
| Epochs | 10 (early stopped at epoch 4) |
| Batch Size (per device) | 8 |
| Gradient Accumulation Steps | 4 |
| Effective Batch Size | 32 |
| Learning Rate | 2e-4 |
| Learning Rate Scheduler | Linear |
| Warmup Steps | 100 |
| Weight Decay | 0.01 |
| Max Sequence Length | 128 |
| Optimizer | AdamW (8-bit paged) |
| Early Stopping Patience | 3 epochs |
| FP16 Training | Enabled |
| Step | Train Loss | Val Loss | Val Acc | Val F1 |
|---|---|---|---|---|
| 100 | 0.3509 | 0.3096 | 93.4% | 93.3% |
| 200 | 0.2489 | 0.3245 | 96.4% | 96.4% |
| 300 | 0.1496 | 0.1042 | 96.9% | 96.9% |
| 400 | 0.0973 | 0.0994 | 96.8% | 96.8% |
| 500 | 0.1595 | 0.1555 | 97.5% | 97.5% |
| 600 | 0.0907 | 0.0850 | 97.3% | 97.3% |
| 700 | 0.1784 | 0.0576 | 97.7% | 97.7% |
| 800 | 0.0646 | 0.0857 | 97.7% | 97.7% |
| 900 | 0.0559 | 0.1474 | 97.7% | 97.7% |
| 1000 | 0.0732 | 0.0958 | 96.7% | 96.7% |
Best Checkpoint: Step 700 (lowest validation loss: 0.0576)
pip install transformers peft torch bitsandbytes accelerate
from transformers import AutoTokenizer, AutoModelForSequenceClassification, BitsAndBytesConfig
from peft import PeftModel
import torch
# Model configuration
MODEL_NAME = "Sugandha-Chauhan/BioMistral-7B-SymptomDiagnosis"
BASE_MODEL = "BioMistral/BioMistral-7B"
# Quantization config (for efficient inference)
bnb_config = BitsAndBytesConfig(
load_in_4bit=True,
bnb_4bit_quant_type="nf4",
bnb_4bit_compute_dtype=torch.float16,
bnb_4bit_use_double_quant=True,
)
# Load base model
model = AutoModelForSequenceClassification.from_pretrained(
BASE_MODEL,
num_labels=10,
quantization_config=bnb_config,
device_map="auto",
trust_remote_code=True,
torch_dtype=torch.float16
)
# Load LoRA adapters
model = PeftModel.from_pretrained(model, MODEL_NAME)
tokenizer = AutoTokenizer.from_pretrained(MODEL_NAME)
if tokenizer.pad_token is None:
tokenizer.pad_token = tokenizer.eos_token
model.config.pad_token_id = tokenizer.pad_token_id
model.eval()
print("Model loaded successfully!")
# Diagnosis class mapping
DIAGNOSIS_CLASSES = {
0: "acute bronchitis",
1: "anxiety",
2: "conjunctivitis due to allergy",
3: "eczema",
4: "infectious gastroenteritis",
5: "pneumonia",
6: "psoriasis",
7: "spondylosis",
8: "sprain or strain",
9: "strep throat"
}
def predict_diagnosis(symptoms_text):
"""
Predict diagnosis from symptoms
Args:
symptoms_text: str, formatted symptoms
e.g., "nausea ,vomiting ,diarrhea and fever"
Returns:
diagnosis: str, predicted diagnosis name
confidence: float, prediction confidence (0-1)
"""
# Tokenize
inputs = tokenizer(
symptoms_text,
return_tensors="pt",
padding=True,
truncation=True,
max_length=128
)
# Move to device
device = next(model.parameters()).device
inputs = {k: v.to(device) for k, v in inputs.items()}
# Predict
with torch.no_grad():
outputs = model(**inputs)
logits = outputs.logits
# Get probabilities
probabilities = torch.softmax(logits, dim=-1)
confidence, predicted_class = torch.max(probabilities, dim=-1)
# Map to diagnosis
diagnosis = DIAGNOSIS_CLASSES[predicted_class.item()]
confidence_score = confidence.item()
return diagnosis, confidence_score
# Example usage
symptoms = "nausea ,vomiting ,diarrhea and abdominal cramps"
diagnosis, confidence = predict_diagnosis(symptoms)
print(f"Diagnosis: {diagnosis}")
print(f"Confidence: {confidence:.1%}")
Output:
Diagnosis: infectious gastroenteritis
Confidence: 100.0%
def batch_predict(symptoms_list):
"""Predict multiple symptom texts at once"""
inputs = tokenizer(
symptoms_list,
return_tensors="pt",
padding=True,
truncation=True,
max_length=128
)
device = next(model.parameters()).device
inputs = {k: v.to(device) for k, v in inputs.items()}
with torch.no_grad():
outputs = model(**inputs)
logits = outputs.logits
probabilities = torch.softmax(logits, dim=-1)
confidences, predicted_classes = torch.max(probabilities, dim=-1)
results = []
for pred_class, conf in zip(predicted_classes, confidences):
results.append({
'diagnosis': DIAGNOSIS_CLASSES[pred_class.item()],
'confidence': conf.item()
})
return results
# Example
symptoms_batch = [
"fever ,cough and difficulty breathing",
"anxiety and nervousness ,rapid heartbeat and shortness of breath",
"skin rash ,itching of skin and abnormal appearing skin"
]
results = batch_predict(symptoms_batch)
for i, result in enumerate(results):
print(f"{i+1}. {result['diagnosis']} ({result['confidence']:.1%})")
CRITICAL: The model expects symptoms in a specific format matching its training data.
# Space BEFORE comma, 'and' before last symptom
"nausea ,vomiting ,diarrhea and abdominal cramps"
"cough ,fever and difficulty breathing"
"eye redness ,itchiness of eye and lacrimation"
# No spaces before commas
"nausea, vomiting, diarrhea, fever" # Will likely fail
# Missing 'and' before last symptom
"nausea ,vomiting ,diarrhea ,fever" # Suboptimal
# Capitalized
"Nausea ,Vomiting ,Diarrhea and Fever" # Wrong case
symptom1 ,symptom2)and before the last symptomIf you use this model in your research or applications, please cite:
@misc{chauhan2025biomistral_symptom_classifier,
title={BioMistral-7B Symptom-to-Diagnosis Classifier},
author={Sugandha Chauhan},
year={2025},
publisher={Hugging Face},
howpublished={\url{https://huggingface.co/Sugandha-Chauhan/BioMistral-7B-SymptomDiagnosis}},
note={Fine-tuned with QLoRA for medical symptom classification}
}
For questions, issues, or feedback:
Last Updated: November 2025
Model Version: 1.0