Contrast Everything: A Hierarchical Contrastive Framework for Medical Time-Series

Yihe Wang, Yu Han, Haishuai Wang, Xiang Zhang

Abstract

Self-supervised learning (SSL) has emerged as a powerful tool for mitigating the scarcity of expert-labeled medical data. However, existing SSL methods for time-series often overlook the inherent hierarchical structure of clinical recordings. We present COMET (Contrast Everything), a novel framework that leverages the natural hierarchy of medical data—spanning observations, samples, trials, and patients—to learn robust representations. By contrasting data across these four levels, COMET significantly outperforms state-of-the-art baselines, particularly in low-data regimes, achieving up to a 14% improvement in F1-score with only 1% of labels available.

Introduction

The interpretation of medical time-series data, such as Electroencephalograms (EEG) and Electrocardiograms (ECG), is a specialized task requiring years of clinical training. This creates a significant bottleneck for AI in healthcare, as labeled data is both scarce and expensive. While contrastive learning has successfully bridged this gap in other domains, current approaches for time-series typically focus on a single level of granularity, such as comparing a signal segment to a perturbed version of itself.

This "flat" approach ignores the rich, multi-layered structure inherent in clinical data. A single patient often undergoes multiple recording sessions (trials), each trial contains numerous segments (samples), and each sample is composed of individual data points (observations). COMET aims to "contrast everything" across this entire hierarchy to maximize the information extracted from unlabeled datasets.

Methodology

The core of the COMET framework is its Hierarchical Contrastive Loss, which integrates four distinct levels of data consistency:

  1. Observation-level: This ensures that an individual data point and its augmented (masked) version maintain similar embeddings, capturing fine-grained local features.
  2. Sample-level: Following standard contrastive paradigms, this level ensures a signal segment is similar to its augmented counterpart while remaining distinct from other segments in the batch.
  3. Trial-level: This level assumes that different segments extracted from the same recording session (trial) should share more similarities with each other than with segments from different trials.
  4. Patient-level: This captures the underlying physiological "signature" of an individual, assuming that all recordings from the same patient should cluster together in the embedding space.

To process these signals, COMET utilizes a Dilated CNN backbone. To ensure that training batches contain the necessary hierarchical relationships (e.g., multiple samples from the same patient), the authors developed specialized shuffle functions for the data loader, enabling the model to effectively learn from these multi-layered associations.

Experimental Setup

COMET was evaluated on three diverse, multivariate medical datasets:

  • Alzheimer’s Disease (AD): EEG signals from 23 patients.
  • Myocardial Infarction (PTB): ECG signals from 198 patients.
  • Parkinson’s Disease (TDBRAIN): EEG signals from 72 patients.

Crucially, all experiments were conducted in a patient-independent setting. This means the model was tested on individuals entirely absent from the training set, providing a rigorous and realistic assessment of its clinical utility.

Results and Discussion

COMET consistently outperformed six state-of-the-art baselines, including TS2vec and TF-C, across all metrics. The most significant gains were observed in the "small data" regime:

  • Low-Label Performance: In Alzheimer’s detection, COMET outperformed the best baseline by 14% F1-score when using 10% labeled data and 13% when using only 1% labeled data. Similar trends were observed in Parkinson’s and heart attack detection.
  • Stability through Hierarchy: The research indicates that while individual levels of contrast (e.g., only patient-level) can be unstable, the combination of all four levels provides a regularization effect that enhances model robustness.
  • Representation Quality: UMAP projections demonstrate that COMET creates tighter, more distinct clusters for "Healthy" vs. "Diseased" patients compared to previous methods, even when the model has not seen labels during pre-training.

Limitations

A primary limitation is the potential for label conflicts. In patient-level consistency, the model assumes all samples from one patient are "positive" pairs. However, for conditions that manifest intermittently (e.g., occasional heart arrhythmia), some trials may be healthy while others are diseased. Treating these as identical in the embedding space could introduce noise into the training process.

Conclusion

COMET demonstrates that the inherent hierarchy of medical data acts as a powerful, "free" supervisory signal. By moving beyond single-level contrastive learning, COMET provides a more robust and label-efficient framework for medical time-series analysis. Future work will explore automated weighting for the hierarchical loss components and the integration of semi-supervised disease-level consistency.

Summary updated

BibTeX
@inproceedings{wang2023contrast,
  author = {Yihe Wang and Yu Han and Haishuai Wang and Xiang Zhang},
  title = {{Contrast Everything: A Hierarchical Contrastive Framework for Medical Time-Series}},
  booktitle = {Advances in Neural Information Processing Systems},
  year = {2023},
  url = {https://openreview.net/forum?id=sOQBHlCmzp},
}
Figure