Depth-Aware Oversampling in Hierarchical EKG Models

Eyiara Oladipo, Mohamed S NafeaML4H 2026 Poster 2026

TL;DR

When training deep learning models on severely imbalanced medical data like 12-lead EKGs, synthetic oversampling (like SMOTE) usually beats loss-reweighting—but where in the network you synthesize matters just as much as how. In hierarchical EKG models, freezing an encoder and oversampling at intermediate layers actually hurts performance because interpolated points land in the wrong class's territory. Synthesizing on-the-fly during training fixes this by letting the encoder adapt its representations, though simply interpolating the raw, beat-aligned input signal remains remarkably effective.

What Problem Does This Paper Address?

In clinical settings, the rarest conditions are often the most critical to catch. In 12-lead EKG classification, dataset imbalance is severe—the most common diagnoses can outnumber the rarest by more than 100 to 1.

To handle this, practitioners often turn to oversampling (generating synthetic minority-class examples, e.g., via SMOTE) or loss reweighting (penalizing mistakes on rare classes more heavily). Meanwhile, hierarchical networks have become popular for structured signals like EKGs, because they mirror the data's natural organization: individual heartbeats form rhythms, and rhythms inform the final diagnosis.

Here is the gap: oversampling methods are typically designed for generic, flat architectures where "depth" is just an arbitrary layer index. Nobody had systematically asked: in a hierarchical model where each layer has a distinct structural meaning, at which depth should we oversample, and should we do it offline (on a frozen model) or on-the-fly (during training)?

Methods

The authors run a controlled study using a Hierarchical Attention Network (HAN) for 12-lead EKG classification. Each EKG recording is first denoised and segmented into $N_b$ individual heartbeats (300-sample windows around each $R$-peak), paired with their $R\text{–}R$ intervals (the time between beats).

HAN architecture showing the four oversampling depths

This architecture exposes four natural depths for oversampling:

  1. $L_1$ (Raw beats): Instead of naively averaging whole, unaligned EKG recordings (which blurs waveforms and inflates heart rates), the authors exploit the hierarchical structure to interpolate beat-by-beat at corresponding positions between a record and its same-class nearest neighbor.
  2. $L_2$ (Beat embeddings): Interpolating the sequence of learned beat-level representations (after the convolutional encoder, BiLSTM, and attention).
  3. $L_3$ (Record embeddings): Classic vector-space SMOTE on the single vector summarizing the entire recording.
  4. $L_4$ (Penultimate features): Classic vector-space SMOTE just before the final classification layer.

For neighbor search, high-dimensional representations are reduced to 32 PCA components (plus three rhythm descriptors at $L_1$ and $L_2$). They also test two integration strategies:

  • Offline Two-Stage: Train the HAN on imbalanced data, freeze the encoder up to depth $L_k$, synthesize minority samples once, and retrain the downstream layers.
  • Online On-the-fly: Synthesize minority samples during training at $L_2\text{–}L_4$ (refreshing nearest neighbors each epoch), allowing gradients to flow through the synthetic points so the encoder itself adapts.

Datasets

The study evaluates all methods on two publicly available, 500 Hz 12-lead EKG datasets (excluding multi-label records) using patient- and class-stratified 80/10/10 splits across 5 random seeds:

  • Shandong Provincial Hospital (SPH): 22,418 records across 11 diagnostic classes (10–60 seconds long).
  • Chapman–Shaoxing: 5,125 records across 7 diagnostic classes (10 seconds long).

Key Insights and Ideas

  • Interpolation beats loss reweighting: Across both datasets, interpolation-based oversampling at its best depth substantially outperforms standard cross-entropy, inverse-frequency weighting, class-balanced loss, and focal loss.
  • Two-stage performance is non-monotonic across depth: Under offline two-stage training, oversampling at the shallowest ($L_1$) and deepest ($L_4$) levels works well, while intermediate depths ($L_2$ and $L_3$) hover near the baseline.
  • Why intermediate frozen layers fail: Standard training fits a network to real examples without constraining the empty space between them. When the authors probed the frozen stage-one encoder on SPH, they found that 64% of synthetic points at $L_2$ and 41% at $L_3$ landed in neighborhoods dominated by other classes (compared to 32% at $L_4$).
  • On-the-fly synthesis rescues intermediate depths: Moving synthesis into the training loop ($L_2$ and $L_3$) recovers performance, bringing it in line with $L_1$ and $L_4$. Allowing gradients to flow through interpolated points encourages the encoder to shape representations that actually support linear interpolation. At $L_4$, where only the linear classifier lies downstream, offline synthesis is already sufficient.

Key Results

Comparison of reweighting baselines and offline synthesis on SPH
  • Overall gains: On SPH, the best interpolation depth ($L_1$, $q=0.70$) achieves a macro-F1 of 0.587 (and 0.943 AUC at $q=0.50$), outperforming the strongest reweighting baseline (Focal loss at 0.487 macro-F1) by 0.10. On Chapman–Shaoxing, interpolation leads by 0.07 macro-F1.
  • Offline vs. Online at intermediate depths: On SPH, two-stage offline synthesis at $L_2$ and $L_3$ yields macro-F1 scores of 0.486–0.502 and 0.474–0.476, respectively. Switching to on-the-fly synthesis boosts $L_2$ to 0.558 ($q=0.35$) and $L_3$ to 0.562 ($q=0.50$).
Two-stage vs on-the-fly synthesis by injection depth on SPH

Limitations and Future Work

The authors note several caveats:

  • Scope: Experiments cover a single architecture family (HAN), one modality (EKG), imbalance ratios between 535:1 and 5:1, and 32 PCA components for neighbor search.
  • Tuning: Each depth and method was tuned separately under a fixed Optuna budget (40 trials), meaning some differences could reflect hyperparameter tuning or stage-one encoder variance rather than depth alone.
  • Rarest classes: Interpolation cannot invent diversity that isn't already in the data, so its benefit on the absolute rarest classes remains inconclusive.

Future work should test whether these depth-dependent dynamics hold for other hierarchical architectures, other domains, and generative (rather than interpolation-based) oversampling methods.

Summary updated

BibTeX
@inproceedings{oladipo2026depth,
  author = {Eyiara Oladipo and Mohamed S Nafea},
  title = {{Depth-Aware Oversampling in Hierarchical EKG Models}},
  booktitle = {ML4H 2026 Poster},
  year = {2026},
  url = {https://openreview.net/forum?id=QhBs9piZEf},
}
Figure