Diagnosis Matching — Distilled ModernBERT
A binary classifier that determines whether two free-text diagnoses written in Russian refer to the same condition.
This model is a single-transformer distillation of a complex multi-component meta-model for diagnosis matching. The original system is an AutoGluon ensemble that aggregates 16 engineered features from four distinct sectors:
| Sector | Features | Source |
|---|---|---|
| NLP (6) | edit distance, n-gram, stem, POS, lemma similarity ratios | String matching heuristics |
| RAG (2) | ICD-code prompts | Vikhr-Nemo-12B, Qwen2.5-7B |
| SIM (3) | Cosine similarity | GigaEmbed, BioSyn, Arctic-Embed2 |
| LLM (5) | Direct match prompts | Qwen2.5-7B, Vikhr-Nemo-12B, GigaChat-Max, Llama3.1:70B, Phi4:14B |
The full meta-model achieves F1 = 0.910, avg_prec = 0.948 on the held-out test set — but requires running 5 separate LLMs, 3 embedding models, and 6 handcrafted NLP features at inference time.
This distilled model compresses the entire pipeline into a single ModernBERT-base forward pass, replacing all 16 features and their upstream models with one 577 MB checkpoint.
Usage
from transformers import AutoTokenizer, AutoModelForSequenceClassification
import torch
tokenizer = AutoTokenizer.from_pretrained("sm1rk/diagnosis-matching-distilled-model")
model = AutoModelForSequenceClassification.from_pretrained("sm1rk/diagnosis-matching-distilled-model")
inputs = tokenizer("атеросклероз сонных артерий", "гиперлипидемия", return_tensors="pt")
with torch.no_grad():
prob = torch.softmax(model(**inputs).logits, dim=1)[0, 1].item()
print(f"P(match) = {prob:.4f}")
Model Details
| Base model | ModernBERT-base (22 layers, 768 hidden, 12 heads) |
| Task | Binary sequence classification |
| Language | Russian |
| Max length | 8192 tokens |
| Size | 577 MB (float32, safetensors) |
Input: a pair of free-text diagnoses (diagnosis_1, diagnosis_2). Output: match probability P(match) ∈ [0, 1].
Intended Use
Matching semantically equivalent diagnoses expressed in different wording — e.g., clinical records, discharge summaries, billing codes. Not intended for clinical decision support.