vhdm/clinicalbert-ms-autoimmune-neuro
015
π§ 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
βοΈ 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).
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)
Test (n = 493)
β
Final configuration: Aggregation = logit_topk(k=3)βTemperature = 1.372βThreshold β 1.0
π§ Inference Example
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
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,
)