File size: 4,309 Bytes
92f14ba
 
 
 
468f6a4
 
92f14ba
 
 
 
 
 
 
 
 
 
 
 
 
 
468f6a4
92f14ba
468f6a4
92f14ba
468f6a4
 
 
92f14ba
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
076b35e
 
92f14ba
076b35e
 
92f14ba
076b35e
 
92f14ba
 
468f6a4
92f14ba
 
 
076b35e
92f14ba
076b35e
92f14ba
 
 
 
076b35e
92f14ba
076b35e
 
 
92f14ba
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
468f6a4
92f14ba
468f6a4
92f14ba
468f6a4
92f14ba
468f6a4
92f14ba
468f6a4
 
 
 
 
92f14ba
468f6a4
 
92f14ba
 
 
 
468f6a4
 
92f14ba
 
 
468f6a4
 
 
 
 
 
 
 
92f14ba
468f6a4
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
---
language:
- en
library_name: pytorch
license: mit
pipeline_tag: time-series-forecasting
tags:
- cgm
- continuous-glucose-monitor
- self-supervised-learning
- jepa
- time-series
- masked-prediction
- biosignal
- healthcare
- pretrained-encoder
---

# CGM-JEPA Pretrained Encoders

This repository contains frozen self-supervised encoder weights from the paper [CGM-JEPA: Learning Consistent Continuous Glucose Monitor Representations via Predictive Self-Supervised Pretraining](https://huggingface.co/papers/2605.00933). 

The repo contains the **exact checkpoints used to produce Tables 1–8 of the paper** for both the paper's main contributions (CGM-JEPA, X-CGM-JEPA) and the two re-pretrained baselines (GluFormer, TS2Vec).

- **Code:** [github.com/cruiseresearchgroup/CGM-JEPA](https://github.com/cruiseresearchgroup/CGM-JEPA)
- **Pretraining Dataset:** [`CRUISEResearchGroup/CGM-JEPA-Pretraining`](https://huggingface.co/datasets/CRUISEResearchGroup/CGM-JEPA-Pretraining)
- **Downstream Splits:** [`CRUISEResearchGroup/CGM-JEPA-Downstream`](https://huggingface.co/datasets/CRUISEResearchGroup/CGM-JEPA-Downstream)

## Quick start

```bash
huggingface-cli download CRUISEResearchGroup/CGM-JEPA --local-dir Output
```

Then from the [code repository](https://github.com/cruiseresearchgroup/CGM-JEPA):

```bash
# Reproduce paper Tables 1–6
python scripts/run_all_eval.py
```

The downstream eval will load all four checkpoints automatically from the subdirectories below.

## Layout

```
.
β”œβ”€β”€ cgm_jepa/
β”‚   β”œβ”€β”€ model.safetensors
β”‚   └── config.json
β”œβ”€β”€ x_cgm_jepa/
β”‚   β”œβ”€β”€ model.safetensors
β”‚   └── config.json
└── baselines/
    β”œβ”€β”€ gluformer.pt
    └── ts2vec.pkl
```

`cgm_jepa/` and `x_cgm_jepa/` use the standard `PyTorchModelHubMixin` layout β€” `model.safetensors` for weights, `config.json` for architecture hyperparameters β€” so they load via the standard `from_pretrained` one-liner.

## Loading examples

### CGM-JEPA / X-CGM-JEPA β€” `from_pretrained` one-liner

`Encoder` is a `PyTorchModelHubMixin` subclass, so the architecture hyperparameters and weights load in a single call directly from this repo:

```python
from models.encoder import Encoder

encoder = Encoder.from_pretrained("CRUISEResearchGroup/CGM-JEPA", subfolder="cgm_jepa")
encoder.eval()

# X-CGM-JEPA: same call, different subfolder
encoder_x = Encoder.from_pretrained("CRUISEResearchGroup/CGM-JEPA", subfolder="x_cgm_jepa")
```

### Standalone PyTorch β€” GluFormer

```python
import torch
import torch.nn as nn
from models.gluformer.gluformer import GluFormer

vocab_size = 278
gluformer = GluFormer(
    vocab_size=vocab_size,
    embed_dim=96,
    nhead=6,
    num_layers=3,
    dim_feedforward=192,
    max_seq_length=25000,
    dropout=0.0,
    pad_token=vocab_size,
)
gluformer.load_state_dict(
    torch.load("Output/baselines/gluformer.pt", map_location="cpu")["encoder"]
)
gluformer.output_head = nn.Identity()   # discard the LM head for embedding extraction
gluformer.eval()
```

## Architectures

### `cgm_jepa` and `x_cgm_jepa`

Both use the same `models.encoder.Encoder` class with identical hyperparameters; only the pretraining objective differs. At downstream / inference time only the temporal encoder is used.

| Field | Value |
|---|---|
| `patch_size` | 12 |
| `encoder_kernel_size` | 3 |
| `encoder_embed_dim` | 96 |
| `encoder_nhead` | 6 |
| `encoder_num_layers` | 3 |

**Input**: a tensor of shape `(B, num_patches, patch_size)` (raw glucose values, z-scored).
**Output**: per-patch embedding of shape `(B, num_patches, embed_dim)`.

## Intended use

- **Frozen feature extraction** from raw CGM windows (24-hour, 5-min sampled, 288 timesteps).
- **Linear-probe evaluation**, especially for the metabolic subphenotyping tasks (IR / Ξ²-cell dysfunction) described in the paper.
- **Comparison baseline** for new CGM representation methods.

## Citation

```bibtex
@article{muhammad2026cgm,
  title   = {CGM-JEPA: Learning Consistent Continuous Glucose Monitor Representations via Predictive Self-Supervised Pretraining},
  author  = {Muhammad, Hada Melino and Li, Zechen and Salim, Flora and Metwally, Ahmed A},
  journal = {arXiv preprint arXiv:2605.00933},
  year    = {2026}
}
```

## License
Released under the **MIT license**.