TL;DR
Predicting heart rhythm disorders from a single electrocardiogram (ECG) is like trying to guess a movie's ending from a single frame. The authors introduce SurviFormer, a transformer-based survival model that reads a patient's entire, irregularly spaced history of ECGs to predict when they might develop atrial fibrillation (AFib). While a single recent ECG is surprisingly good at ranking who is at highest risk, watching the whole movie over time yields significantly sharper, better-calibrated estimates of a patient's actual probability of developing the condition over the next five years.
What Problem Does This Paper Address?
Atrial fibrillation (AFib) is a chaotic, rapid heartbeat that affects over 50 million people globally and dramatically raises the risk of stroke. Because early AFib often flickers in and out without symptoms, doctors frequently miss it until a crisis hits. Fortunately, subtle structural changes in the heart precede AFib and leave faint footprints on routine, normal-rhythm ECGs.
Deep learning models are already good at spotting these footprints, but they suffer from two major blind spots:
- Snapshot amnesia: Most models look at just one ECG at a time, throwing away the rich longitudinal story told by routine, repeat checkups over the years.
- Binary thinking: Many models frame this as a simple yes/no classification ("Will they get AFib in 5 years?"). This approach mishandles right-censoring—what statisticians call it when a patient drops out of a study after two years without an event, leaving their five-year fate unknown.
Instead of a binary guess, clinical care needs dynamic survival analysis: a continuous risk trajectory that updates every time a new ECG is recorded and properly accounts for uneven follow-up times.
Methods
SurviFormer decouples waveform reading from temporal storytelling. First, the authors pre-train a standard 1D ResNet-50 on single ECGs to predict 5-year AFib, then freeze it. Every raw 8-lead, 10-second ECG in a patient's history is compressed into a fixed vector embedding, concatenated with the patient's age and sex.
Next comes the novel temporal machinery:
- Pairwise Relative Time Bias: Patients don't visit clinics on a metronome; visits might be days or years apart. Standard transformer positional encodings only care about order (1st, 2nd, 3rd). Instead, SurviFormer calculates the exact elapsed days between every pair of visits, passes those gaps through a tiny neural network, and adds the result directly to the causal self-attention logits. The model attends to past visits based on actual elapsed time.
- Discrete Hazard Head: Taking the final visit's context vector, the model predicts the hazard—the conditional probability of AFib occurring in each 6-month bin over a 5-year horizon, given the patient has remained AFib-free up to that bin. Multiplying the survival probabilities across bins reconstructs a full survival curve.
- Multi-Landmark Training: Rather than only training from a patient's first or last visit, the authors sample up to four intermediate visits ("landmarks") per patient as distinct prediction origins. This acts as smart data augmentation and teaches the model to predict residual risk from any point in a patient's timeline, trained via a combination of class-weighted binary cross-entropy and a pairwise ranking loss.
Datasets
No new datasets were introduced; the authors use two established clinical repositories filtered for patients with at least two normal-rhythm visits prior to any AFib documentation:
- CODE (Training & Internal Validation): A massive Brazilian multi-center cohort containing 139,640 patients (~517,000 ECGs) with a 1.9% AFib event rate and up to 7.4 years of follow-up.
- MIMIC-IV (External Validation): A critical-care cohort from a US hospital (Beth Israel Deaconess) comprising 1,838 patients with a much sicker population (10.2% AFib event rate), testing out-of-distribution generalization.
Key Insights and Ideas
- History calibrates; the latest snapshot ranks: Perhaps the most nuanced finding is that feeding SurviFormer only the single most recent ECG achieves the exact same risk-ranking ability (C-index 0.853) as feeding it the entire patient history. However, the full history meaningfully improves calibration (lowering the Integrated Brier Score from 0.038 to 0.030). Knowing the past doesn't change who is at the front of the risk line, but it gives a much truer picture of what their actual probability of illness is as the years unfold.
- Order matters: Simply averaging or max-pooling past ECG embeddings degrades performance compared to using just the latest ECG. Temporal structure is essential.
- It’s the heart, not the hospital: In electronic health records, frequent tests often just mean a patient is sick—a notorious shortcut for AI. By zeroing out ECG embeddings and testing models trained purely on age, sex, and visit timing, performance plummeted (C-index dropped from 0.853 to ~0.730). The model is genuinely reading cardiac physiology, not just clinic attendance patterns.
- Training protocol is a quiet giant: When an older recurrent baseline (DynamicDeepHit) was upgraded to use the authors' multi-landmark training protocol, its external C-index jumped from 0.517 to 0.805, tying SurviFormer on concordance!
Key Results
Models were evaluated on C-index and Time-Dependent AUC (TD-AUC) for discrimination (higher is better), and Integrated Brier Score (IBS) for absolute probability calibration (lower is better).
- Internal Test Set (CODE): SurviFormer achieved the highest discrimination with a C-index of 0.853 and mean TD-AUC of 0.867 (beating static DeepSurv at 0.828 and DeepHit at 0.839), while tying DynamicDeepHit for the best calibration (IBS of 0.030).
- External Validation (MIMIC-IV): Despite a massive shift from Brazilian outpatient clinics to US critical care, SurviFormer generalized well, posting a C-index of 0.805, mean TD-AUC of 0.848, and IBS of 0.106—outperforming static baselines (which collapsed to ~0.48–0.50 C-index) and edging out the protocol-matched recurrent baseline on TD-AUC (0.848 vs. 0.828) and IBS (0.106 vs. 0.125).
Limitations and Future Work
- ** Clinical vs. Biological Onset: The model predicts first documented AFib on a clinic ECG, not the exact moment the heart first slipped out of rhythm (since silent episodes can happen between visits).
- Statistical Ties: Confidence intervals between SurviFormer and the multi-landmark LSTM baseline overlap, meaning transformers don't claim a formal knockout victory over well-trained recurrent nets here.
- Frozen Backbone & Clinical Scope: Keeping the ResNet-50 frozen prevented end-to-end learning. For future work, the authors suggest exploring self-supervised ECG representations, testing on larger external cohorts, and adapting the framework to single-lead consumer wearables (like smartwatches), where continuous longitudinal tracking naturally lives.
Summary updated