A 12-lead electrocardiogram records the same heartbeat from twelve electrical viewpoints. That makes it an unusually good fit for self-supervised learning, where a model learns from unlabeled data by being trained so that two "views" of one recording look alike. The leads themselves can serve as those views: the limb leads and the chest leads should agree about the heart's rhythm and overall state. They should not be forced to agree about everything, though. Some findings appear only in particular leads, and pulling the two views fully together teaches the model to discard exactly that information. This note proposes two changes. First, produce both views in one encoder pass by blocking attention between two random groups of leads, which roughly halves pretraining compute relative to standard two-pass contrast. Second, apply contrast only to a learned subset of embedding dimensions, chosen by a dimension-wise gate. Such a gate is a vector of per-feature weights, unlike a single scalar weight on the whole embedding. The remaining dimensions stay free to encode lead-specific detail.
This matters because clinical ECG labels are scarce and expensive, and the best label-efficient method in the material is costly. Self-supervised representation learning from 12-lead ECG data found that latent forecasting with Contrastive Predictive Coding (CPC) beats instance-discrimination methods (SimCLR, BYOL, SwAV) on PTB-XL. The same authors note that CPC is computationally heavier, and their convolutional backbone treats all twelve leads uniformly. The proposal asks whether a lead-structured, single-pass contrast that touches only some dimensions can match or beat CPC at 1–10% labels for less compute. It also asks whether this can hold up better when individual leads are corrupted.
Core Claim
Cross-lead contrast is a cheap and physiologically meaningful pretext task for ECG, but only if two conditions hold. The two views must come from the same forward pass, and the invariance it imposes must be confined to a gated subspace. Concretely, the encoder represents each lead-time segment as its own token. At each pretraining step the twelve leads are split at random into groups $A$ and $B$. An attention mask stops tokens in $A$ from attending to tokens in $B$, and vice versa, so a single pass yields two independent group embeddings $z_A, z_B \in \mathbb{R}^d$. A gate $g \in [0,1]^d$ selects the dimensions that enter the contrastive loss. The gate is a learned function of the pooled embedding, constrained so that $\sum_i g_i = k$ for a fixed budget $k < d$:
$$\mathcal{L} = \mathrm{InfoNCE}\big(g \odot z_A,\; g \odot z_B\big) + \lambda\, \mathcal{L}_{\text{rec}}\big((1-g)\odot z\big).$$
Here $\odot$ is element-wise multiplication. $\mathcal{L}_{\text{rec}}$ is a light masked-segment reconstruction loss computed from the ungated dimensions of the full embedding $z$ in the same pass, which keeps those dimensions informative. $\lambda$ weights the two terms.
The gate is computed once per sample, not once per token pair. It therefore avoids the $d$-fold memory blow-up that the research file identifies as the main obstacle to dimension-wise attention inside pairwise attention matrices.
The new element is the combination of single-pass view construction and invariance restricted to a learned subspace. Prior work does each piece separately.
CSE-SFP builds two views in one pass using the causal mask of decoder-only language models. That approach cannot transfer to bidirectional multichannel encoders. We use lead-group masking instead.
ADCLR proves that unrestricted bidirectional attention between query and context patches causes collapse, and avoids it with one-way attention. This result constrains our design. Information flowing between $A$ and $B$ inside the encoder would make the contrast trivially solvable, so the mask must be strict until pooling.
Channel-Wise Contrastive Learning contrasts individual convolutional channels to resist noisy labels. It applies contrast to every channel, uses supervised labels, and does not address compute. DIABLO shows that dimension-wise selection before pooling suppresses noisy dimensions, but only in supervised metric learning. Our method supplies the mechanism they lack: selection of which dimensions the self-supervised invariance applies to.
Research Program
The backbone is a lead-tokenized transformer at 100 Hz. Deep Learning for ECG Analysis: Benchmarks and Insights from PTB-XL reports that 500 Hz brings no significant diagnostic gain over 100 Hz, which keeps token counts manageable. The cross-group mask is applied in all encoder layers during pretraining. Group embeddings are formed by dimension-wise gated pooling over each group's tokens. For downstream use the mask is removed. To reduce the mismatch this creates, pretraining uses the mask on most steps and full attention, with only the reconstruction loss, on the rest.
The program has three parts.
- Build and tune the objective. This includes the budget $k$, the form of the gate (soft with a sum constraint, or a hard top-$k$ selection with a straight-through estimator), and the lead-partition distribution. Partitions can be uniform random splits or anatomically motivated ones such as limb versus chest leads.
- Measure cost. We will record wall-clock time per epoch, peak memory, and total pretraining GPU-hours against two-pass contrast, CPC, and masked autoencoding.
- Test the hypothesis behind the gate. Rhythm statements should be largely lead-invariant, while form and localized diagnostic statements are more lead-specific. If the gate works as intended, linear probes on the gated subspace should carry most of the rhythm information. Probes on the ungated subspace should carry a disproportionate share of form and localized information. If both subspaces look the same, the gate is just a regularizer and the mechanistic claim fails.
Baselines
The naive reference point is a supervised model trained from scratch on each label fraction with the same transformer. For calibration, the PTB-XL benchmark paper reports supervised ensembles reaching macro AUC of roughly 0.939 on diagnostic statements with full labels.
The strongest existing method is CPC as reported by Mehari and Strodthoff. They report a fine-tuned macro AUC of 0.9418 on PTB-XL against 0.9318 for the best purely supervised baseline, and 0.927 under linear evaluation with a frozen encoder. We will reproduce CPC on our unlabeled pretraining pool with their convolutional backbone. We will also run it with our transformer, if feasible, so that a backbone difference cannot explain the result. All methods get the same pretraining data, the same GPU-hour cap, and the same hyperparameter-search budget on the validation fold.
Beating CPC means one of two outcomes at 1% and 10% labels:
- higher macro AUC at equal compute, outside the spread over seeds and label-subset resamples; or
- equal macro AUC at no more than about 60% of CPC's pretraining GPU-hours.
The third baseline is standard two-pass contrast with the same lead-group views, where each group is encoded in its own pass. It isolates the cost claim: single-pass should match its accuracy at about half its encoder compute.
The fourth is a pure masked-autoencoding baseline on the same backbone, the paradigm behind Brant and MRM.
The key ablations remove or degrade the gate:
- set $g = 1$, so all dimensions are contrasted and the reconstruction term disappears;
- use a fixed random subset of $k$ dimensions;
- replace the vector gate with a scalar per-lead weight, the coarse alternative that dimension-wise attention is supposed to improve on.
Why not just…?
Why not just use masked autoencoding, which is already single-pass and needs no negatives? This is the most serious threat. MRM reaches 88.5% CheXpert AUC at 1% labels with reconstruction alone, close to the 88.8% of the much heavier contrastive MGCA (MGCA). For ECG, the file contains no reported result on Lacuna for a masked-autoencoding baseline on PTB-XL in the low-label regime, so the question is open. Our method spends nearly the same compute as masked autoencoding, so the comparison at matched GPU-hours decides it directly. If masked autoencoding alone matches us on macro AUC and on lead-corruption robustness, the contrastive half adds nothing. We would report that and fall back to the gated-pooling component.
Why not just contrast the full embedding with lead-group views, as in ordinary multi-view contrast? Full invariance across leads should erase lead-specific morphology. That is the failure the gate exists to prevent. The $g=1$ ablation tests it. The prediction is that the ablation matches us on rhythm statements and loses on form and localized diagnostic statements. If there is no per-class gap, the gate is unnecessary.
Why not just shrink the projection head or use fewer negatives to cut cost? These change the similarity computation, which is not the dominant cost. Encoder forward passes are, as the multi-branch analyses in the file document for speech and point clouds. Gradient Cache addresses memory for large batches but adds about 20% runtime, so it moves cost rather than removing it. We report peak memory and wall-clock time separately so that a reader can see which term the single-pass design actually saves.
Why not just add a per-lead quality weight (scalar attention) to CPC? This is the cheapest way to handle corrupted leads. It is weaker than the gate because it must discard or keep a whole lead rather than individual features, the "spotlight versus equalizer" distinction drawn in the file. The scalar-gate ablation and the corruption test below settle whether this distinction matters for ECG.
Proposed Experiments
Pretraining and label fractions. Pretraining uses unlabeled training-fold records from PTB-XL, plus ICBEB2018 for a larger pool, with all labels withheld. Fine-tuning and linear evaluation use 1%, 10%, and 100% label subsets of PTB-XL's patient-stratified training folds, with five label-subset resamples per fraction. Metrics are macro AUC over all statements and separately over diagnostic, form, and rhythm subsets, with per-class AUC for rare classes. Mehari and Strodthoff found these rare classes are where self-supervision helps most.
Transfer. ICBEB2018 tests transfer. The PTB-XL benchmark paper reports that PTB-XL pretraining lets a model match a from-scratch model using only a fraction of target data, though no specific score is reported in the file. All methods therefore run on identical ICBEB splits.
Decisive checks. There are four.
- Compute–accuracy frontier against CPC. We compare macro AUC against GPU-hours. The method wins if its frontier lies above CPC's at 1% and 10% labels.
- Lead-corruption robustness. At test time we inject baseline wander, muscle noise, or flat-line detachment into one to three leads. We measure the drop in AUC for our method, the scalar-gate ablation, CPC, and masked autoencoding. The prediction is a smaller drop for the dimension-gated model.
- Subspace probe. This is the rhythm-versus-form probe from the Research Program, which tests whether the gate actually separates shared from lead-specific information.
- Mask-removal mismatch. We compare downstream accuracy with the mask kept versus removed, to confirm that pretraining with lead isolation does not leave the encoder unable to use cross-lead interactions.
If check 1 and check 2 both fail against masked autoencoding, the proposal is falsified as stated.
References
- Self-supervised representation learning from 12-lead ECG data
- CSE-SFP: Enabling Unsupervised Sentence Representation Learning via a Single Forward Pass
- Patch-Level Contrasting without Patch Correspondence for Accurate and Dense Contrastive Representation Learning
- Channel-Wise Contrastive Learning for Learning with Noisy Labels
- DIABLO: Dictionary-based attention block for deep metric learning
- Deep Learning for ECG Analysis: Benchmarks and Insights from PTB-XL
- Brant: Foundation Model for Intracranial Neural Signal
- Advancing Radiograph Representation Learning with Masked Record Modeling
- Multi-Granularity Cross-modal Alignment for Generalized Medical Visual Representation Learning
- Scaling Deep Contrastive Learning Batch Size with Almost Constant Peak Memory Usage