EHR Representation Learning with Multi-Granularity Cauchy-Schwarz Contrastive Learning

Keyne Kassapa Oei, Shujian Yu, Qing Liu, Robert JenssenarXiv 2026

TL;DR

Electronic health record (EHR) models usually learn by guessing masked medical codes or predicting future events within a single patient's timeline, ignoring how patients and visits relate to one another. EHR-CSS fixes this by introducing a multi-granularity contrastive learning framework that models graded clinical similarities across patients, visits, and medical codes using a Cauchy–Schwarz Sequence (CSS) loss. The result is a single pretrained representation that outperforms state-of-the-art baselines on both few-shot (EHRSHOT) and fully supervised (MIMIC-IV) clinical prediction benchmarks.

What Problem Does This Paper Address?

Self-supervised learning has become a go-to strategy for turning messy, longitudinal EHRs into useful clinical predictions. Existing approaches generally fall into two camps, each with a blind spot:

  1. Generative methods (like BEHRT or CLMBR) reconstruct masked codes or predict future events. Because their training signals come solely from within each individual patient's record, they never explicitly model clinical relationships across different patients or visits.
  2. Contrastive methods can capture these relationships, but they typically force them into binary "positive" or "negative" pairs. In medicine, similarity isn't binary—two patients might share a few chronic conditions without being identical, and treating every non-matching pair as a hard negative throws away valuable nuance.

The authors ask: Can we combine prediction-based learning at the medical-code level with graded, continuous clinical similarity at the visit and patient levels—without needing outcome labels or specialized graph structures?

Methods

EHR-CSS encodes an observed prefix of a patient's visit history (summing medical-code, age, segment, and visit-position embeddings) using a shared bidirectional Transformer, while withholding the next visit as a prediction target. Averaging the resulting code-level representations within each visit produces visit-level representations, and averaging across visits produces patient-level representations.

Figure 2. EHR-CSS input and multi-granularity representation pipeline. The symbol µ denotes average. The observed prefix is encoded into medical-code, visit, and patient representations. Projection networks map these representations to the five objective-specific anchor spaces. The withheld visit defines the next-visit target. A causal pass through the shared encoder supports dense next-code prediction.

The core novelty lies in how the model is trained across five objectives spanning three granularities:

  • Patient & Visit Objectives (What's New): Instead of binary pairs, the authors construct graded target distributions using medical-code co-occurrence (via positive pointwise mutual information, or PPMI, combined with exact code identity) and a locally scaled Gaussian RBF kernel. For the visit objective, they also add a temporal decay term—assuming that clinically similar visits closer in time are more likely to belong to the same clinical episode.
  • Medical-Code Objectives: Three objectives handle fine-grained clinical events: masked-code prediction, next-visit code prediction (weighted by smoothed inverse patient frequency so rare codes aren't drowned out), and dense next-code prediction (via a causal attention pass through the same encoder).
  • The CSS Loss: Rather than using KL divergence—which relies on pointwise probability ratios that can become unstable near zero—EHR-CSS adapts the Cauchy–Schwarz (CS) divergence to align the model's similarity distribution with the target distribution. Because CS divergence is invariant to positive rescaling, the normalization partition function cancels out, naturally decomposing the loss into an alignment term (pulling target-supported candidates closer) and a uniformity term (preventing representations from collapsing).

Datasets

The authors evaluate EHR-CSS on two public benchmarks using identical patient splits, vocabularies, and pretraining epochs across all compared models:

  • EHRSHOT: A few-shot evaluation benchmark covering 14 diverse clinical prediction tasks. Here, the pretrained encoder is frozen, and a linear classifier is trained on $k \in \{1, 2, 4, \dots, 256, \text{All}\}$ labeled examples per class.
  • MIMIC-IV: An acute and critical care dataset used to evaluate fully supervised fine-tuning on three hospital outcome tasks: mortality, 30-day readmission, and length of stay (LOS) $> 7$ days.

Key Insights and Ideas

  • Graded similarity beats binary pairs: Replacing binary contrastive pairs with locally scaled RBF target distributions over clinical co-occurrence gives the model a much richer signal. In ablations, switching from simpler power-scaled targets to locally scaled RBF targets improved AUROC on both EHRSHOT ($+0.014$) and MIMIC-IV ($+0.012$).
  • All five objectives pull their weight: Removing any single objective (patient, visit, masked-code, next-visit, or dense next-code) consistently lowers performance on both benchmarks, with larger drops on EHRSHOT where longer patient histories give the patient and visit objectives more to work with.
  • CS divergence outperforms KL divergence: Swapping the CSS loss for a standard forward KL-divergence loss (equivalent to soft-label cross-entropy) dropped AUROC by $0.009$ on EHRSHOT and $0.017$ on MIMIC-IV.

Key Results

  • EHRSHOT (Few-Shot & Full Supervision): EHR-CSS achieves the highest macro AUROC at every label budget from $k=4$ through $k=\text{All}$, reaching $0.744 \pm 0.003$ under full supervision (compared to $0.719 \pm 0.006$ for second-best CLMBR-T). It only trails EHRMamba slightly at extreme low-data budgets ($k=1$ and $k=2$, by $0.006$ and $0.004$), likely because 2–4 total examples capture too little within-class variation.
  • MIMIC-IV (Fine-Tuning): EHR-CSS achieves the highest overall average AUROC ($0.714 \pm 0.002$ vs. EHRMamba's $0.713 \pm 0.002$), taking first place on mortality ($0.790$) and LOS $> 7$ ($0.674$), while EHRMamba edges it out on 30-day readmission ($0.681$ vs. $0.679$).
Table 2. AUROC for mortality, readmission, and length- of-stay (LOS) prediction on MIMIC-IV [25] for EHR-CSS and selected representative baselines. Every method uses the same pretraining setup. Values are mean ± SD over three pretraining seeds. Best is in bold; second-best is underlined.

Limitations and Future Work

The authors note two main limitations. First, their evaluation is constrained by the scale and scope of public EHR datasets—EHRSHOT has relatively few patients, and MIMIC-IV focuses on acute ICU care with shorter patient histories (which reduces the benefit of patient- and visit-level objectives). Second, they kept the sequence encoder fixed as a standard Transformer to isolate the effect of the pretraining objectives. Future work could test EHR-CSS on larger, multimodal datasets and swap in more efficient recurrent or state-space encoders (like Mamba) to handle longer patient timelines.

Summary updated

BibTeX
@misc{oei2026ehr,
  author = {Keyne Kassapa Oei and Shujian Yu and Qing Liu and Robert Jenssen},
  title = {{EHR Representation Learning with Multi-Granularity Cauchy-Schwarz Contrastive Learning}},
  year = {2026},
  eprint = {2611.41419},
  archivePrefix = {arXiv},
  url = {https://arxiv.org/abs/2611.41419},
}
Figure