Downloads · 30 days
0
niroshanyi/pacl-rri-af
pacl-rri-af is a feature extraction model from niroshanyi. Use it when you need embeddings to search or compare text. It is set up for pytorch. The card lists the license as mit.
Patient-Aware Contrastive Learning Preserves Per-Patient Structure in RR-Interval Representations
Downloads · 30 days
0
Access
Public
Updated Jun 27, 2026
Repo size
43.7 MB
Likes
0
Public
Click a slice to open those files.
.h525.8 MB · 97%
From the Hugging Face model README
Patient-Aware Contrastive Learning Preserves Per-Patient Structure in RR-Interval Representations
Official implementation and pretrained weights for Patient-Aware Contrastive Learning Preserves Per-Patient Structure in RR-Interval Representations — Accepted at GlobalSouthML: Bridging Gaps for Underrepresented Researchers in Machine Learning, ICML 2026 Workshop · July 9, 2026 · Seoul, South Korea.
📄 Paper: arXiv:2606.23570 · 💻 Code: github.com/EML-Labs/pacl-rri-af
This repository hosts a multi-scale 1D-CNN encoder trained with the Patient-Aware Contrastive Learning (PACL) objective to produce per-patient–consistent representations of RR-interval (RRI) windows derived from single-lead ECG. The frozen encoder + a lightweight logistic-regression probe distinguishes sinus rhythm (SR) from atrial fibrillation (AF) on a patient-independent test split.
window_size = 200 (normalized), shape [B, 200].[B, 128] (projection head) and L2-normalized latents [B, 128] (encoder). The latents are the recommended representation for downstream probes.checkpoints/best_model.pth (PyTorch state_dict).| Metric | Proposed (PACL) | SupCon | BCE |
|---|---|---|---|
| SR Cohesion ↑ | 0.850 ± 0.044 | 0.800 ± 0.029 | 0.772 ± 0.049 |
| AF Cohesion ↑ | 0.846 ± 0.048 | 0.921 ± 0.035 | 0.955 ± 0.019 |
| Centroid Similarity ↓ | +0.238 ± 0.200 | +0.155 ± 0.123 | −0.717 ± 0.029 |
| Global Centroid Dist. ↑ | 1.034 ± 0.100 | 1.120 ± 0.095 | 1.603 ± 0.045 |
| Global Compactness ↑ | 1.192 ± 0.124 | 1.313 ± 0.465 | 2.427 ± 0.226 |
| Per-pt. Compactness ↑ | 3.273 ± 0.433 | 2.178 ± 1.148 | 6.396 ± 0.590 |
| AUROC ↑ | 0.989 ± 0.003 | 0.983 ± 0.009 | 0.980 ± 0.012 |
PACL achieves the highest per-patient SR cohesion and 2.6× lower seed variance than SupCon on a patient-independent test split (frozen encoder + logistic regression probe).
| Class | Precision | Recall | F1 |
|---|---|---|---|
| SR | 0.970 ± 0.009 | 0.927 ± 0.020 | 0.948 ± 0.012 |
| AF | 0.936 ± 0.017 | 0.974 ± 0.008 | 0.955 ± 0.010 |
| Accuracy | — | — | 0.952 ± 0.011 |
Standard supervised contrastive learning treats all same-class segments as positives, regardless of which patient they come from. When class differences partially overlap with between-patient differences, this collapses each subject's distinct sinus rhythm (SR) baseline into a shared class prototype, removing the very structure needed to generalize to unseen patients.
PACL restricts positives to same-patient, same-class pairs:
P(i) = { j ≠ i | patient_j == patient_i AND class_j == class_i }
N(i) = { j ≠ i | class_j ≠ class_i }

Same-class segments from different patients are excluded from P(i). This preserves each patient's individual SR structure while still pushing SR and AF apart.
The model is a plain PyTorch nn.Module (not a transformers model). Clone the repository for the source, then load the checkpoint.
git clone https://github.com/EML-Labs/pacl-rri-af.git
cd pacl-rri-af
pip install -r requirements.txt
Requirements: Python 3.9+, PyTorch 2.x, numpy, scikit-learn, hydra. Exact pinned versions are in requirements.txt.
import torch
from src.Model import Model
device = torch.device("cuda" if torch.cuda.is_available() else "cpu")
# Architecture must match the training config (configs/model/model.yaml)
model = Model(latent_dim=128, projection_dim=128, dropout=0.12).to(device)
state_dict = torch.load("checkpoints/best_model.pth", map_location=device, weights_only=True)
model.load_state_dict(state_dict)
model.eval()
# RR-interval window: [B, window_size=200], normalized
rr_window = torch.randn(4, 200, device=device)
with torch.no_grad():
embeddings, latents = model(rr_window)
# embeddings: [B, 128] (L2-normalized projection head output)
# latents: [B, 128] (L2-normalized encoder output -> use this for probes)
The full evaluation (frozen encoder → logistic-regression probe → SR/AF metrics) is driven by Hydra:
python main.py
Environment: Single NVIDIA RTX 2080, ~3 minutes per run (5 seeds × 3 losses = 15 runs total). Seeds used: 1, 42, 102, 2026, 9999.
This work uses the IRIDIA-AF dataset, comprising long-term single-lead ECG recordings from 167 patients with paroxysmal AF. Episodes are retained when AF duration ≥ 1 hr and the immediately preceding SR duration ≥ 4 hr. Splits are patient-level (119/24/24 train/val/test); after quality filtering, 154/27/24 episodes remain.
RR intervals are extracted per recording and segmented into windows of window_size = 200 with stride = 50. Two preprocessed HDF5 splits (Data/*_train.h5, Data/*_test.h5) ship with the repository for the test pipeline.
Direct numerical comparison is limited by dataset and evaluation differences. † Cross-validation with within-patient data mixing inflates reported metrics. ‡ MIT-BIH AF contains no episodes satisfying our quality criteria (AF ≥ 1h, preceding SR ≥ 4h).
| Study | Method | Dataset | Validation | Sensitivity | Specificity | Accuracy |
|---|---|---|---|---|---|---|
| Udawat & Singh (2022) | HRV + ML | MIT-BIH AF | CV† | 95.16% | 92.46% | 94.43% |
| Andersen et al. (2019) | CNN + RNN | 3 dbs | 5-fold CV† | 98.98% | 96.95% | — |
| Andersen et al. (2019) | CNN + RNN | Unseen Pt. holdout | — | 86.04% | 98.96% | — |
| Faust et al. (2018) | LSTM | MIT-BIH‡ | 10-fold CV† | — | — | 98.51% |
| Ours | CNN + MLP | IRIDIA-AF | Pt. holdout | 97.40 ± 0.80% | 92.72 ± 2.01% | 95.17 ± 1.07% |
The proposed representations exceed Andersen et al.'s patient-holdout sensitivity by over 11 percentage points using only a frozen encoder and a logistic regression probe.
Intended use. Research on patient-robust representation learning for subject-structured physiological signals, and SR-vs-AF discrimination from RR intervals as a downstream probe.
Out of scope. This model is a research artifact, not a medical device. It must not be used for clinical diagnosis, screening, or treatment decisions.
Limitations.
The PACL objective does not depend on the encoder or the signal type. It requires only subject identifiers in each mini-batch. The same positive-pair construction is expected to apply to other subject-structured physiological signals — EEG, EMG, PPG — wherever class differences partially overlap with between-subject differences.
If you find this work useful, please cite:
@inproceedings{niroshan2026pacl,
title = {Patient-Aware Contrastive Learning Preserves Per-Patient Structure
in RR-Interval Representations},
author = {Niroshan, Yasantha and Wimalasiri, Wimalasiri and Hettiarachchi, Chathuranga},
booktitle = {GlobalSouthML: Bridging Gaps for Underrepresented Researchers in Machine Learning,
ICML 2026 Workshop},
year = {2026},
eprint = {2606.23570},
archivePrefix = {arXiv},
primaryClass = {cs.LG}
}
MIT License. See LICENSE for details.