TLDR: A new study introduces the CAPE foundation model for electrocardiograms (ECGs) and investigates how data distribution impacts its performance and generalization. While pretraining on diverse, multi-center cohorts improves in-distribution accuracy, it surprisingly reduces out-of-distribution (OOD) generalization due to the model learning cohort-specific artifacts. To counter this, the researchers propose the In-Distribution Batch (IDB) strategy, which ensures training batches consist of samples from a single cohort. This approach significantly enhances OOD robustness and generalization, offering a crucial step towards developing more reliable and clinically fair AI models for heart health.
Artificial intelligence (AI) is rapidly transforming various fields, and healthcare is no exception. Electrocardiograms (ECGs), which record the heart’s electrical activity, are a prime area where AI can offer significant diagnostic and prognostic insights. However, the effectiveness of these AI models, particularly those based on contrastive learning, heavily depends on the characteristics of the data they are trained on. A recent study delves into this critical aspect, exploring how data distribution impacts the performance and generalisability of contrastive learning-based foundation models for ECGs.
The research, titled “Data distribution impacts the performance and generalisability of contrastive learning-based foundation models of electrocardiograms,” was conducted by a team of authors including Gul Rukh Khattak, Konstantinos Patlatzoglou, Joseph Barker, and many others from institutions like Imperial College London, Vanderbilt University Medical Center, and Uppsala University.
The Challenge of Generalization in Medical AI
Foundation models, pretrained on vast datasets, are designed to learn broad, generalizable representations. While powerful, they often struggle with generalization when faced with ‘out-of-distribution’ (OOD) data—data that differs significantly from what they were trained on. In medicine, this is a major hurdle. An AI model trained on patient data from one hospital or demographic might perform poorly when applied to a different population or clinical setting. This study highlights that even for ECGs, factors like patient demographics, health status, and the specific recording devices used can introduce biases that hinder a model’s ability to generalize.
Introducing the CAPE Foundation Model
To investigate these challenges, the researchers developed the Contrasting by Patient Augmented Electrocardiograms (CAPE) foundation model. CAPE uses a self-supervised pretraining strategy called contrastive learning, which teaches the model to identify similar ECGs from the same patient while distinguishing them from ECGs of other patients. The model was pretrained on a massive dataset of over five million ECGs from four diverse cohorts across North America, South America, and Asia (BIDMC, CODE, SHZS, and VUMC).
Key Findings: Diversity Helps, But Also Hurts OOD Generalization
The study systematically assessed how various factors—cohort demographics, health status, and population diversity—influenced the CAPE model’s performance on downstream prediction tasks, such as predicting patient age and sex. Initially, they found that pretraining the CAPE model on the combined, multi-center BCSV dataset (CAPE-X) yielded the best overall performance when tested on data from the same distribution. This suggests that a large and diverse dataset is beneficial for in-distribution accuracy.
However, a crucial insight emerged when evaluating ‘out-of-distribution’ (OOD) generalization. When a model trained on one cohort was tested on an entirely different external cohort, the performance of CAPE-X significantly degraded. Visual analysis using t-SNE, a technique for visualizing high-dimensional data, revealed that the CAPE-X model was encoding cohort-specific artifacts, meaning it was learning features unique to the training cohort rather than universally applicable ECG patterns. These artifacts were often linked to technical variations from different ECG acquisition devices, rather than just patient demographics.
The In-Distribution Batch (IDB) Strategy: A Solution for Robust Generalization
To address this OOD performance decline, the researchers proposed a novel training approach: the In-Distribution Batch (IDB) strategy, implemented in the CAPE-Z model. With IDB, each training batch is composed exclusively of samples from a single cohort. This ensures that when the model learns to contrast positive and negative pairs, those pairs always originate from the same data distribution. By doing so, the IDB strategy discourages the model from learning spurious, cohort-distinguishing features and instead encourages it to focus on clinically meaningful variability within each cohort.
The results were striking. CAPE-Z, utilizing the IDB strategy, showed no discernible clustering by cohort in the t-SNE visualizations, indicating improved robustness to distributional differences. Quantitatively, CAPE-Z significantly improved OOD generalization, achieving much better age and sex prediction performance on external cohorts like CODE and SHZS compared to CAPE-X. This demonstrates that carefully managing batch composition during pretraining can lead to more generalized and reliable ECG representations.
Also Read:
- Enhancing Audio Event Recognition Through Consistency Regularization
- Enhancing Clinical Reasoning in AI: A Compartmentalized Approach for Language Models
Implications for Future Medical AI
This research provides vital insights for developing clinically fair and generalizable foundation models in healthcare. It underscores that while large, diverse datasets are important, the *way* these datasets are used during pretraining is equally critical. Simply combining diverse cohorts without considering their underlying distributional differences can inadvertently lead to models that perform well in-distribution but fail to generalize to real-world, heterogeneous clinical data. The IDB strategy offers a practical method to mitigate this issue, paving the way for more robust and equitable AI systems in medicine.
For more detailed information, you can access the full research paper here.


