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

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

21 Oct 2023NeurIPS 2023 11arXiv:2310.14017archive 2025-07-28

Yihe Wang, Yu Han, Haishuai Wang, Xiang Zhang

Contrastive representation learning is crucial in medical time series analysis as it alleviates dependency on labor-intensive, domain-specific, and scarce expert annotations. However, existing contrastive learning methods primarily focus on one single data level, which fails to fully exploit the intricate nature of medical time series. To address this issue, we present COMET, an innovative hierarchical framework that leverages data consistencies at all inherent levels in medical time series. Our meticulously designed model systematically captures data consistency from four potential levels: observation, sample, trial, and patient levels. By developing contrastive loss at multiple levels, we can learn effective representations that preserve comprehensive data consistency, maximizing information utilization in a self-supervised manner. We conduct experiments in the challenging patient-independent setting. We compare COMET against six baselines using three diverse datasets, which include ECG signals for myocardial infarction and EEG signals for Alzheimer's and Parkinson's diseases. The results demonstrate that COMET consistently outperforms all baselines, particularly in setup with 10% and 1% labeled data fractions across all datasets. These results underscore the significant impact of our framework in advancing contrastive representation learning techniques for medical time series. The source code is available at https://github.com/DL4mHealth/COMET.

PaperPDFConference PDFCodeCode Syntology ranMethod as code

In Syntology View this paper on Syntology, its page in Syntology's graph. That page adds which of its functions are also present in other papers' code Syntology holds, with dates, and its dated run record as JSON and a README badge. It also lists the repositories linked to the paper, the abstract and the calls for agents.

Open this paper in Syntology's Atlas, the map of the papers in Syntology's graph and their citations.

For agents, on Syntology's MCP service (how to connect):

Code

Syntology 42 code samples: 41 from 5 repositories linked to this paper, 1 identical to code harvested from another paper's repository. Across all 42: 36 ran (of which 6 constructed an object rather than computing a result; 23 with no instrument failure: 1 honoured, 2 violated, 20 with no contract checked; 13 where Syntology's instrument failed) · 6 unverified. Where Syntology's instrument failed: 8 where our contract draft was wrong; 5 where the contract check could not run; failures of Syntology's instrument, not of the code.

By repository: official repository: 21 samples from 1 repository, 19 ran (10 with no instrument failure; 9 where Syntology's instrument failed); found in paper text by Syntology: 20 samples from 4 repositories, 16 ran (13 with no instrument failure; 3 where Syntology's instrument failed); 1 identical to code first harvested elsewhere. The run record, sample by sample. “Ran” means executed on a synthesized input, not that the code is correct or reproduces the paper.

Levels written between 2026-09-22 and 2026-09-26 (UTC): the dates Syntology's graph wrote each sample's verification level, not when the code executed.

dl4mhealth/comet officialmentioned in papermentioned on GitHubpytorchMITSyntology: 21 samples, 19 ran (9 instrument-failed) · 2 unverified report

Repository list and official/mentioned flags are the archive's, frozen 2025-07-28. Reachability, where shown, is from one Syntology probe window (2026-09-16 to 2026-09-18); repositories not probed show nothing. GitHub stars are not tracked.

Code Syntology ran Syntology

42 samples harvested: 36 ran (of which 6 constructed an object rather than computing a result; 23 with no instrument failure: 1 honoured, 2 violated, 20 with no contract checked; 13 where Syntology's instrument failed) · 6 unverified. “Where Syntology's instrument failed” counts failures of Syntology's instrument, not of the code. Syntology's record for this page last changed ; when this build read Syntology's graph is in the build record. That date is not when the samples ran.

1ran · honoured contract
2ran · violated contract
8ran · our draft was wrong
5ran; the contract check could not run
20ran
6unverified

Licence: 4 of the 42 samples are pointer only, meaning Syntology does not serve that copy's text. For 2 of them, this paper's copy is under a permissive licence and cleared, but the stored copy of the same code that Syntology serves is not; the licence label's tooltip gives Syntology's recorded reason. This page shows no code text for any sample; each one links to its file in the repository.

Harvested from 5 repositories linked to this paper, official or community; the list below is grouped by repository, each group headed by its name and what it is to the paper. 1 sample is listed last, in a group without a repository. “Ran” means the sample executed on a synthesized input. It does not mean the output is correct, and nothing here reproduces the paper's results. A line beginning “fixture:” under a sample that ran gives the arguments Syntology's fixture called the sample with, each as name:type/rank/element kind (? where none was recorded), and the type of what the fixture's run returned, exactly as the harness recorded them; the arguments and the returned type were recorded by two separate runs of the same fixture. No output value is shown, and a returned type says nothing about whether the output was right. “Level recorded” gives the UTC date when Syntology's graph wrote the sample's verification level, not when the code executed; where the level was written before Syntology's graph kept that date, the row says “level recorded, date not recorded”. For 6 samples that ran, the graph records a signature this page does not show: for a class the fixture built without calling, the harness called the object with inputs it made up itself, so the recorded signature is the harness's probe, not the fixture's arguments. “Honoured” and “violated” refer to a contract Syntology drafted from the code itself. “Our draft was wrong” and “the contract check could not run” are failures of Syntology's instrument, not of the code: the sample ran on Syntology's synthesized input, and then the drafted contract did not describe it, or the check itself raised an error (RAISES), lacked a dependency (DEP_MISSING) or ran out of time (TIMEOUT); hover the label for which. A metamorphic tier, where shown, is evidence of the output's shape, not that the sample implements the method.

Each sample ends with its code_sha256. A sample's code_sha256 is Syntology's identity for that exact code. It is printed in full (16 hexadecimal characters for every sample in this build), and get_code(code_sha256="…") takes it exactly as printed. An agent calls it on Syntology's MCP service (how to connect); click an identity to copy that call.

Repository labels, per sample. official repository: The archive marks this repository official for the paper. named in the paper: The archive records that the paper mentions this repository; it is not marked official. community (archive-listed): In the archive's code links for this paper, not marked official and not recorded as mentioned in the paper. found in paper text by Syntology: Syntology found this repository in the paper's own text; whether it is the authors' implementation is not asserted. community: Not in the archive's code links for this paper; a community repository Syntology harvested. Samples are grouped by repository: a repository marked official first, then by how directly the repository is tied to the paper, then in the archive's order; never by how many ran. Licence labels name the repository's licence as recorded at harvest. “Pointer only” means Syntology does not serve that copy's text, for one of six reasons: no licence file was found; the licence was not identified; the licence is recorded as permissive but that copy's record is not marked cleared; the licence is outside the permissive list Syntology serves text under (MIT, Apache-2.0, BSD and similar); this paper's copy was not located, so its licence is not recorded; or this paper's copy is cleared, but the stored copy of the same code that Syntology serves is not. Some licences outside that list permit redistribution, such as WTFPL, and GPL-3.0 under its conditions; they are simply not on the list. Hover a licence label for the reason. File links open the file on GitHub at the default branch, which may have changed since the harvest.

A function or class name links to its page when the name occurs in the harvested code of at least 5 papers; the name is a string, not an identity. A census tag appears when Syntology's census ran implementations with that name on one shared input per bucket: it gives how many were compared, from how many papers, and how many distinct outputs they produced, and names this sample's bucket when this sample was one of them.

dl4mhealth/comet official repository 21 samples, 19 ran (9 instrument-failed) · 2 unverified
MyBatchSampler comet.py ran MIT (permissive) · efe1ff11e7f6a9b7 · report fixture: returned generator · level recorded 2026-09-24
TSEncoder in 5 papers comet.py ran fingerprinted MIT (permissive) · 535006b4dc141e1a · report fixture: signature x:Tensor/3/float, mask:NoneType/0/? · returned Tensor · level recorded 2026-09-24
batch_shuffle_feature_label comet.py ran · our draft was wrong MIT (permissive) · 827011853812f006 · report fixture: signature X:ndarray/2/float, y:ndarray/2/float, batch_size:int/0/int · returned tuple · level recorded 2026-09-24
contrastive_loss in 80 papers
census: 11 implementations from 18 papers, 7 distinct outputs across 3 buckets, one shared input per bucket
comet.py ran; the contract check could not run (RAISES) MIT (permissive) · 016be840858ae4f4 · report fixture: signature z1:Tensor/3/float, z2:Tensor/3/float, loss_func:callable/0/?, id:Tensor/1/float, hierarchical:bool/0/bool, factor:float/0/float · returned Tensor · level recorded 2026-09-24
fit_knn tasks/_eval_protocols.py ran; the contract check could not run (RAISES) MIT (permissive) here; the stored copy is pointer only · befe203f4fa96ee5 · report fixture: signature features:ndarray/2/float, y:ndarray/1/int · returned Pipeline · level recorded 2026-09-26
fit_svm tasks/_eval_protocols.py ran MIT (permissive) · c62d56549152cab0 · report fixture: signature features:ndarray/2/float, y:ndarray/1/int, MAX_SAMPLES:int/0/int · returned SVC · level recorded 2026-09-24
generate_binomial_mask in 8 papers comet.py ran · violated contract fingerprinted MIT (permissive) · 7077c48726f289f1 · report fixture: signature B:int/0/int, T:int/0/int, C:int/0/int, p:float/0/float · returned Tensor · level recorded 2026-09-22
generate_continuous_mask in 7 papers comet.py ran · violated contract fingerprinted MIT (permissive) · 9cd8a0cb1b50b24b · report fixture: signature B:int/0/int, T:int/0/int, C:int/0/int, n:int/0/int, l:float/0/float · returned Tensor · level recorded 2026-09-22
id_contrastive_loss comet.py ran · our draft was wrong MIT (permissive) · bba058f7876cca50 · report fixture: signature z1:Tensor/3/float, z2:Tensor/3/float, id:Tensor/1/int · returned Tensor · level recorded 2026-09-24
load_ad dataloading/ad_preprocessing.py ran MIT (permissive) · abb87f4aadacbffd · report fixture: signature val_ids:list/1/int, test_ids:list/1/int, data_path:str/0/str, label_path:str/0/str · returned tuple · level recorded 2026-09-24
load_ptb dataloading/ptb_preprocessing.py ran MIT (permissive) · 32ecaa526bdb3d05 · report fixture: signature train_ids:list/1/int, val_ids:list/1/int, test_ids:list/1/int, data_path:str/0/str, label_path:str/0/str · returned tuple · level recorded 2026-09-24
load_tdbrain dataloading/tdbrain_preprocessing.py ran MIT (permissive) · b5885c72d25d5f24 · report fixture: signature train_ids:list/1/int, val_ids:list/1/int, test_ids:list/1/int, data_path:str/0/str, label_path:str/0/str · returned tuple · level recorded 2026-09-24
observation_contrastive_loss comet.py ran · our draft was wrong fingerprinted MIT (permissive) · 127e5186b374c0c6 · report fixture: signature z1:Tensor/3/float, z2:Tensor/3/float · returned Tensor · level recorded 2026-09-22
patient_contrastive_loss comet.py ran · our draft was wrong MIT (permissive) · c721d4c3f9feca7a · report fixture: signature z1:Tensor/3/float, z2:Tensor/3/float, pid:Tensor/1/int · returned int · level recorded 2026-09-24
sample_contrastive_loss comet.py ran · our draft was wrong fingerprinted MIT (permissive) · a068a662fad3b92a · report fixture: signature z1:Tensor/3/float, z2:Tensor/3/float · returned Tensor · level recorded 2026-09-22
shuffle_feature_label comet.py ran; the contract check could not run (RAISES) MIT (permissive) · 84ad5a6296c54002 · report fixture: signature X:ndarray/2/float, y:ndarray/2/int, shuffle_function:str/0/str, batch_size:int/0/int · returned tuple · level recorded 2026-09-24
shuffle_feature_label utils.py ran MIT (permissive) · 925a0da719ba3129 · report fixture: signature X:ndarray/2/float, y:ndarray/2/int, shuffle_function:str/0/str, batch_size:int/0/int · returned tuple · level recorded 2026-09-24
trial_contrastive_loss comet.py ran · our draft was wrong MIT (permissive) · 9f939df27acbf98d · report fixture: signature z1:Tensor/3/float, z2:Tensor/3/float, tid:Tensor/1/int · returned int · level recorded 2026-09-24
trial_shuffle_feature_label comet.py ran · honoured contract fingerprinted MIT (permissive) · 1acb85286d268c68 · report fixture: signature X:Tensor/2/float, y:Tensor/2/int · returned tuple · level recorded 2026-09-22
COMET comet.py unverified MIT (permissive) · ae8e2b7de075b9f3 · report
fit_lr in 7 papers tasks/_eval_protocols.py unverified MIT (permissive) here; the stored copy is pointer only · 2309c20a08ac1773 · report
yuezhihan/ts2vec found in paper text by Syntology 8 samples, 6 ran (3 instrument-failed) · 2 unverified
ConvBlock in 61 papers
census: 8 implementations from 8 papers, 6 distinct outputs across 2 buckets, one shared input per bucket this sample: bucket 2 of 2, arg 1: rank 3, kind float, dtype float32
ts2vec.py ran · metamorphic tier: invariant fingerprinted MIT (permissive) · 0e30f1c230eef5dc · report fixture: signature x:Tensor/3/float · returned Tensor · level recorded 2026-09-22
DilatedConvEncoder in 8 papers ts2vec.py ran · metamorphic tier: invariant fingerprinted MIT (permissive) · c59b7deb5be0dbfa · report fixture: signature x:Tensor/3/float · returned Tensor · level recorded 2026-09-22
TSEncoder in 5 papers ts2vec.py ran MIT (permissive) · 24fd56663218d25d · report fixture: signature x:Tensor/3/float, mask:NoneType/0/? · returned Tensor · level recorded 2026-09-24
split_with_nan ts2vec.py ran · our draft was wrong fingerprinted MIT (permissive) · 271f7134c2ce540e · report fixture: signature x:ndarray/2/float, sections:int/0/int, axis:int/0/int · returned list · level recorded 2026-09-22
take_per_row ts2vec.py ran; the contract check could not run (RAISES) MIT (permissive) · e8c3e310ce1ef8a3 · report fixture: signature A:Tensor/2/float, indx:ndarray/1/int, num_elem:int/0/int · returned Tensor · level recorded 2026-09-22
torch_pad_nan in 8 papers
census: 3 implementations from 5 papers, 1 distinct output on one shared input this sample: bucket 1 of 1, arg 1: rank 2, kind float, dtype float32
ts2vec.py ran; the contract check could not run (RAISES) fingerprinted MIT (permissive) · 3e925bf8ba27d5fe · report fixture: signature arr:Tensor/2/float, left:int/0/int, right:int/0/int, dim:int/0/int · returned Tensor · level recorded 2026-09-22
TS2Vec ts2vec.py unverified MIT (permissive) · 64cc44e198273c4e · report
centerize_vary_length_series ts2vec.py unverified MIT (permissive) · a0b6f98fa3e2d24e · report
emadeldeen24/TS-TCC found in paper text by Syntology 6 samples, 6 ran (0 instrument-failed) · 0 unverified
Attention in 344 papers
census: 13 implementations from 12 papers, 10 distinct outputs across 4 buckets, one shared input per bucket
models/TC.py ran · metamorphic tier: deterministic MIT (permissive) · 617e0645b9972b67 · report fixture: returned Attention · level recorded 2026-09-22
FeedForward in 198 papers models/TC.py ran · metamorphic tier: deterministic MIT (permissive) · 234836bb032d8d76 · report fixture: returned FeedForward · level recorded 2026-09-22
Residual in 24 papers models/TC.py ran · metamorphic tier: deterministic fingerprinted MIT (permissive) · 8907e91277107509 · report fixture: returned Residual · level recorded 2026-09-22
Seq_Transformer models/TC.py ran MIT (permissive) · 92c655e3fea1cdc0 · report fixture: returned Seq_Transformer · level recorded 2026-09-22
TC models/TC.py ran · metamorphic tier: deterministic MIT (permissive) · e8e0063a34a8e06f · report fixture: returned TC · level recorded 2026-09-22
Transformer in 173 papers models/TC.py ran · metamorphic tier: deterministic MIT (permissive) · 2b59ed1d60ed9658 · report fixture: returned Transformer · level recorded 2026-09-22
wickstrom/mixupcontrastivelearning found in paper text by Syntology 5 samples, 3 ran (0 instrument-failed) · 2 unverified
mixup_batch src/mcl/trainer.py ran fingerprinted MIT (permissive) · ab3068c33cd47e9d · report fixture: signature x:Tensor/2/float, alpha:float/0/float · returned tuple · level recorded 2026-09-24
resolve_device in 16 papers src/mcl/trainer.py ran MIT (permissive) · e5bafae5d8f3c7d7 · report fixture: signature device:NoneType/0/? · returned str · level recorded 2026-09-24
to_numpy3d src/mcl/data.py ran MIT (permissive) · 8eec0828aa4f64f6 · report fixture: signature X:ndarray/2/float · returned ndarray · level recorded 2026-09-24
load_dataset in 276 papers src/mcl/data.py unverified MIT (permissive) · 48272503a70e16a5 · report
train in 522 papers src/mcl/trainer.py unverified MIT (permissive) · f5c0c05f7535c06b · report
danikiyasseh/CLOCS found in paper text by Syntology 1 sample, 1 ran (0 instrument-failed) · 0 unverified
cnn_network_contrastive prepare_network.py ran licence not identified · pointer only · 146273205666e8bd · report fixture: signature x:Tensor/4/float · returned Tensor · level recorded 2026-09-24
Repository not located 1 sample, 1 ran (1 instrument-failed) · 0 unverified
1 sample is identical to code Syntology harvested from another paper's repository; this paper's own copy was not located, so no repository is named and no licence is recorded.
pad_nan_to_target in 7 papers repository not located ran · our draft was wrong fingerprinted licence of this copy not recorded · 5254eb44ce12370e · report fixture: signature array:ndarray/2/float, target_length:int/0/int, axis:int/0/int, both_side:bool/0/bool · returned ndarray · level recorded 2026-09-22

Method as code Syntology

What Syntology's graph records as this paper's claimed method, lifted into code: each assembly names its bricks (functions and classes), each with its own role and its own verification level. An assembly is not a check that the code implements the method correctly or reproduces the paper's results. Levels are each brick's own verification level in Syntology's graph (level 0: no recorded run), listed brick by brick and never combined into one level; “ran” means the brick executed on a synthesized input, not that its output is correct, and the instrument figure counts failures of Syntology's instrument, not of the code. Where a model read the code against the paper's claim, each assembly's label verdict is one model's judgement, kept in this page's JSON twin; it is not calibrated, so no card prints it. Siblings are assemblies lifted from this paper in the same batch for the same method: alternative readings kept side by side; none replaces or supersedes another.

4 assemblies on this paper: 4 harvested, 0 generated, listed in 1 groups (siblings lifted in one batch form one group).

4 sibling assemblies for COMET (harvested), lifted in the same batch on 2026-09-09: alternative readings kept side by side; none replaces or supersedes another.

harvested Assembly for COMET (graph method: COMET). 7 bricks; individually on a fixture: 7 ran (of which 7 constructed an object rather than computing a result; 7 with no instrument failure: 0 honoured, 0 violated, 7 with no contract checked; 0 where Syntology's instrument failed) · 0 unverified; every one of the 7 samples that ran constructed an object rather than computing a result. The assembly has not been run end-to-end.

one of 4 siblings

  1. TC entry · level 1 · ran · e8e0063a34a8e06f
  2. Seq_Transformer model · level 1 · ran · 92c655e3fea1cdc0
  3. Transformer model · level 1 · ran · 2b59ed1d60ed9658
  4. Attention model · level 1 · ran · 617e0645b9972b67
  5. FeedForward model · level 1 · ran · 234836bb032d8d76
  6. PreNorm helper · level 1 · ran · 9b66b60a7704b891
  7. Residual helper · level 1 · ran · 8907e91277107509

harvested Assembly for COMET (graph method: COMET). 15 bricks; individually on a fixture: 13 ran (of which 1 constructed an object rather than computing a result; 6 with no instrument failure: 0 honoured, 2 violated, 4 with no contract checked; 7 where Syntology's instrument failed) · 2 unverified. The assembly has not been run end-to-end.

one of 4 siblings

  1. TS2Vec entry · level 0 · unverified · 64cc44e198273c4e
  2. TSEncoder model · level 1 · ran · 24fd56663218d25d
  3. centerize_vary_length_series helper · level 0 · unverified · a0b6f98fa3e2d24e
  4. hierarchical_contrastive_loss loss · level 1 · ran; the contract check could not run · 50140c8208c033ca
  5. split_with_nan helper · level 1 · ran · our draft was wrong · 271f7134c2ce540e
  6. take_per_row helper · level 1 · ran; the contract check could not run (RAISES) · e8c3e310ce1ef8a3
  7. torch_pad_nan helper · level 1 · ran; the contract check could not run (RAISES) · 3e925bf8ba27d5fe
  8. DilatedConvEncoder model · level 1 · ran · c59b7deb5be0dbfa
  9. generate_binomial_mask helper · level 1 · ran · violated contract · fd10054ec4772b80
  10. generate_continuous_mask helper · level 1 · ran · violated contract · acda587a1d1be3bf
  11. instance_contrastive_loss loss · level 1 · ran; the contract check could not run · c2f2651c9a2df200
  12. temporal_contrastive_loss loss · level 1 · ran; the contract check could not run · 72ddf2810ea340c7
  13. pad_nan_to_target helper · level 1 · ran · our draft was wrong · 5254eb44ce12370e
  14. ConvBlock helper · level 1 · ran · 0e30f1c230eef5dc
  15. SamePadConv helper · level 1 · ran · a31cbb317f35ad9d

harvested Assembly for COMET (graph method: COMET). 1 brick; individually on a fixture: 1 ran (of which 0 constructed an object rather than computing a result; 1 with no instrument failure: 0 honoured, 0 violated, 1 with no contract checked; 0 where Syntology's instrument failed) · 0 unverified. The assembly has not been run end-to-end.

one of 4 siblings

  1. cnn_network_contrastive entry · level 1 · ran · 146273205666e8bd

harvested Assembly for COMET (graph method: COMET). 17 bricks; individually on a fixture: 16 ran (of which 1 constructed an object rather than computing a result; 8 with no instrument failure: 1 honoured, 2 violated, 5 with no contract checked; 8 where Syntology's instrument failed) · 1 unverified. The assembly has not been run end-to-end.

one of 4 siblings

  1. COMET entry · level 0 · unverified · ae8e2b7de075b9f3
  2. MyBatchSampler helper · level 1 · ran · efe1ff11e7f6a9b7
  3. TSEncoder model · level 1 · ran · 535006b4dc141e1a
  4. contrastive_loss loss · level 1 · ran; the contract check could not run (RAISES) · 016be840858ae4f4
  5. observation_contrastive_loss loss · level 1 · ran · our draft was wrong · 127e5186b374c0c6
  6. patient_contrastive_loss loss · level 1 · ran · our draft was wrong · c721d4c3f9feca7a
  7. sample_contrastive_loss loss · level 1 · ran · our draft was wrong · a068a662fad3b92a
  8. shuffle_feature_label helper · level 1 · ran; the contract check could not run (RAISES) · 84ad5a6296c54002
  9. trial_contrastive_loss loss · level 1 · ran · our draft was wrong · 9f939df27acbf98d
  10. DilatedConvEncoder model · level 1 · ran · c59b7deb5be0dbfa
  11. generate_binomial_mask helper · level 1 · ran · violated contract · 7077c48726f289f1
  12. generate_continuous_mask helper · level 1 · ran · violated contract · 9cd8a0cb1b50b24b
  13. id_contrastive_loss loss · level 1 · ran · our draft was wrong · bba058f7876cca50
  14. batch_shuffle_feature_label helper · level 1 · ran · our draft was wrong · 827011853812f006
  15. trial_shuffle_feature_label helper · level 1 · ran · honoured contract · 1acb85286d268c68
  16. ConvBlock helper · level 1 · ran · 0e30f1c230eef5dc
  17. SamePadConv helper · level 1 · ran · a31cbb317f35ad9d

Each brick ends with its code_sha256, Syntology's identity for that exact code; click one to copy the get_code call that returns it. For agents, on Syntology's MCP service: assembly(arxiv_id="2310.14017") returns these assemblies with each brick's role and wiring (how to connect).

Tasks

Contrastive LearningEEGRepresentation LearningTime SeriesTime Series Analysis

Results from the paper archive 2025-07-28

No leaderboard rows for this paper in the archive.

Methods

Contrastive LearningFocus

Report a problem or propose a change · a person checks every report against the paper or source before anything changes; decisions are listed on /corrections