CoolFace
Modelpublic

vhdm/clinicalbert-ms-autoimmune-neuro

sourceHugging Faceapache-2.0updated 11mo agoView on Hugging Face
0likes15downloads
Model Card

🧠 ClinicalBERT-MS-Autoimmune-Neuro

A fine-tuned version of [emilyalsentzer/Bio_ClinicalBERT](https://huggingface.co/emilyalsentzer/Bio_ClinicalBERT) for detecting autoimmune neurological disease signals from clinical text notes.

Maintainer: Vahid Mahmoudian Repository: vhdm/clinicalbert-ms-autoimmune-neuro Status: Research / Proof-of-Concept β€” not for standalone clinical use

πŸ” Model Summary

PropertyValue
Base modelemilyalsentzer/Bio_ClinicalBERT
TaskBinary text classification (autoimmune-neurological vs non-autoimmune)
LanguageEnglish clinical notes
DomainNeurology / Autoimmune disorders
DatasetInternal β€œMS-autoimmune” corpus (split into train, valid, test)
Sequence length512 tokens per chunk
HardwareNVIDIA H100
Mixed precisionbf16
Trainer seed42
Epochs4
Learning rate2 Γ— 10⁻⁡
Optimizeradamw_torch
Batch sizestrain = 24, eval = 48
Warmup ratio0.1
Best metricrecall

βš™οΈ Training Log (chunk-level)

Below metrics are auto-generated by Hugging Face Trainer using the raw validation set (before note aggregation, calibration, or threshold tuning).

StepTrain LossVal LossAccuracyPrecisionRecallF1AUC
2000.6550.6270.6600.8000.03770.07200.6259
8000.3310.3730.8400.8820.6280.7330.8856
16000.2750.3600.8510.8540.6910.7640.9040
24000.2910.3330.8580.8780.6890.7720.9121
34000.2200.3580.8610.8510.7310.7860.9169
46000.1690.4320.8560.8280.7440.7840.9172

Final Trainer metrics (chunk-level):

These are raw chunk-level metrics for monitoring during training β€” not the final evaluation used for deployment.

🧩 Note-Level Aggregated Evaluation (final tuned results)

After post-processing with:

  • β€”Aggregation: logit_topk (k = 3)
  • β€”Calibration: temperature scaling (T = 1.372)
  • β€”Threshold: tuned on validation (FΞ² = 1.5 β†’ thr β‰ˆ 1.000)
  • β€”Inference logic: per-note probability = mean(logit(top-k chunks))

Validation (n = 493)

MetricValue
Precision0.9118
Recall0.9394
F10.9254
Accuracy0.9493
ROC-AUC0.9688

Test (n = 493)

MetricValue
Precision0.9618
Recall0.9207
F10.9408
Accuracy0.9615
ROC-AUC0.9786

βœ… Final configuration: Aggregation = logit_topk(k=3) Temperature = 1.372 Threshold β‰ˆ 1.0


🧠 Inference Example

python
from transformers import AutoTokenizer, AutoModelForSequenceClassification
import torch, numpy as np

repo = "vhdm/clinicalbert-ms-autoimmune-neuro"
tok = AutoTokenizer.from_pretrained(repo)
model = AutoModelForSequenceClassification.from_pretrained(repo)

texts = ["Patient reports numbness in lower limbs...", "MRI shows demyelination consistent with MS."]
inputs = tok(texts, padding=True, truncation=True, return_tensors="pt")

with torch.no_grad():
    logits = model(**inputs).logits
probs = torch.softmax(logits, dim=-1).numpy()[:, 1]

# logit_topk aggregation (k=3)
probs = np.clip(probs, 1e-6, 1-1e-6)
logits_ = np.log(probs) - np.log(1-probs)
k = 3
idx = np.argsort(logits_)[-min(k, len(logits_)):]
mean_logit = logits_[idx].mean()
note_score = 1.0 / (1.0 + np.exp(-mean_logit))

T = 1.372  # temperature
note_score_cal = 1.0 / (1.0 + np.exp(-mean_logit / T))
thr = 1.0  # tuned threshold

pred = int(note_score_cal >= thr)
print({"score": note_score_cal, "prediction": pred})

πŸ§ͺ Reproducibility

python
TrainingArguments(
  output_dir="./runs/clinicalbert_ms",
  learning_rate=2e-5,
  per_device_train_batch_size=24,
  per_device_eval_batch_size=48,
  num_train_epochs=5,
  weight_decay=0.01,
  bf16=True,
  optim="adamw_torch",
  warmup_ratio=0.1,
  seed=42,
  evaluation_strategy="steps",
  save_strategy="steps",
  logging_steps=50,
  eval_steps=200,
  save_steps=200,
  save_total_limit=3,
  load_best_model_at_end=True,
  metric_for_best_model="recall",
  greater_is_better=True,
)