bruAristimunha commited on
Commit
462b546
·
verified ·
1 Parent(s): fa0ada7

Replace with clean markdown card

Browse files
Files changed (1) hide show
  1. README.md +17 -160
README.md CHANGED
@@ -14,13 +14,12 @@ tags:
14
 
15
  # SignalJEPA_Contextual
16
 
17
- Contextual downstream architecture introduced in signal-JEPA Guetschel, P et al (2024) .
18
 
19
- > **Architecture-only repository.** This repo documents the
20
  > `braindecode.models.SignalJEPA_Contextual` class. **No pretrained weights are
21
- > distributed here** instantiate the model and train it on your own
22
- > data, or fine-tune from a published foundation-model checkpoint
23
- > separately.
24
 
25
  ## Quick start
26
 
@@ -39,178 +38,36 @@ model = SignalJEPA_Contextual(
39
  )
40
  ```
41
 
42
- The signal-shape arguments above are example defaults — adjust them
43
- to match your recording.
44
 
45
  ## Documentation
46
-
47
- - Full API reference (parameters, references, architecture figure):
48
- <https://braindecode.org/stable/generated/braindecode.models.SignalJEPA_Contextual.html>
49
- - Interactive browser with live instantiation:
50
  <https://huggingface.co/spaces/braindecode/model-explorer>
51
  - Source on GitHub: <https://github.com/braindecode/braindecode/blob/master/braindecode/models/signal_jepa.py#L489>
52
 
53
- ## Architecture description
54
-
55
- The block below is the rendered class docstring (parameters,
56
- references, architecture figure where available).
57
-
58
- <div class='bd-doc'><main>
59
- <p>Contextual downstream architecture introduced in signal-JEPA Guetschel, P et al (2024) [1]_.</p>
60
- <span style="display:inline-block;padding:2px 8px;border-radius:4px;background:#5cb85c;color:white;font-size:11px;font-weight:600;margin-right:4px;">Convolution</span>
61
-
62
- :bdg-dark-line:`Channel`<span style="display:inline-block;padding:2px 8px;border-radius:4px;background:#d9534f;color:white;font-size:11px;font-weight:600;margin-right:4px;">Foundation Model</span>
63
-
64
-
65
-
66
- This architecture is one of the variants of :class:`SignalJEPA`
67
- that can be used for classification purposes.
68
-
69
- .. figure:: https://braindecode.org/dev/_static/model/sjepa_contextual.jpg
70
- :align: center
71
- :alt: sJEPA Contextual.
72
-
73
- .. versionadded:: 0.9
74
-
75
- .. rubric:: Pretrained Weights
76
-
77
- Loads the pre-trained SSL encoder (feature encoder + transformer +
78
- channel embedding) from the shared checkpoints. Two hub IDs are
79
- available:
80
-
81
- - ``braindecode/signal-jepa``: with pre-trained channel embeddings
82
- (62 channels, ``channel_embedding='pretrain_aligned'``).
83
- - ``braindecode/signal-jepa_without-chans``: without channel embeddings.
84
- The embedding table is re-initialized from your channel locations
85
- (``channel_embedding='scratch'``, the default).
86
-
87
- .. important::
88
- **Pre-trained Weights Available**
89
-
90
- .. code:: python
91
- from braindecode.models import SignalJEPA_Contextual
92
-
93
- # Use pre-trained channel embeddings (subset of the 62 channels):
94
- model = SignalJEPA_Contextual.from_pretrained(
95
- "braindecode/signal-jepa",
96
- n_times=2048, # required: the SSL checkpoint is n_times-agnostic
97
- n_outputs=4,
98
- strict=False, # classifier head is not in the SSL checkpoint
99
- )
100
-
101
- # Arbitrary channel set:
102
- model = SignalJEPA_Contextual.from_pretrained(
103
- "braindecode/signal-jepa_without-chans",
104
- chs_info=[{"ch_name": "A", "loc": [...]}, ...],
105
- n_times=2048,
106
- n_outputs=4,
107
- strict=False,
108
- )
109
-
110
- Requires installing ``braindecode[hub]`` for Hub integration.
111
-
112
- .. rubric:: Usage
113
-
114
- .. code:: python
115
- from braindecode.models import SignalJEPA_Contextual
116
-
117
- model = SignalJEPA_Contextual(
118
- chs_info=[{"ch_name": "Fp1", "loc": [...]}, ...],
119
- input_window_seconds=16.0,
120
- sfreq=128,
121
- n_outputs=4, # e.g., 4-class classification
122
- )
123
-
124
- # Forward: (batch, n_chans, n_times) -> (batch, n_outputs)
125
- output = model(eeg_data)
126
-
127
- .. warning::
128
-
129
- Pre-trained at **128 Hz** on EEG bandpass-filtered between
130
- **0.5 and 40 Hz** and rescaled by a factor of :math:`10^{6}`
131
- (volts to microvolts). Apply the same preprocessing to your
132
- data to match the pre-training distribution.
133
-
134
- Parameters
135
- ----------
136
- n_spat_filters : int
137
- Number of spatial filters.
138
-
139
- References
140
- ----------
141
- .. [1] Guetschel, P., Moreau, T., & Tangermann, M. (2024).
142
- S-JEPA: towards seamless cross-dataset transfer through dynamic spatial attention.
143
- In 9th Graz Brain-Computer Interface Conference, https://www.doi.org/10.3217/978-3-99161-014-4-003
144
-
145
- .. rubric:: Hugging Face Hub integration
146
-
147
- When the optional ``huggingface_hub`` package is installed, all models
148
- automatically gain the ability to be pushed to and loaded from the
149
- Hugging Face Hub. Install with::
150
-
151
- pip install braindecode[hub]
152
-
153
- **Pushing a model to the Hub:**
154
-
155
- .. code::
156
- from braindecode.models import SignalJEPA_Contextual
157
-
158
- # Train your model
159
- model = SignalJEPA_Contextual(n_chans=22, n_outputs=4, n_times=1000)
160
- # ... training code ...
161
-
162
- # Push to the Hub
163
- model.push_to_hub(
164
- repo_id="username/my-signaljepa_contextual-model",
165
- commit_message="Initial model upload",
166
- )
167
-
168
- **Loading a model from the Hub:**
169
-
170
- .. code::
171
- from braindecode.models import SignalJEPA_Contextual
172
-
173
- # Load pretrained model
174
- model = SignalJEPA_Contextual.from_pretrained("username/my-signaljepa_contextual-model")
175
-
176
- # Load with a different number of outputs (head is rebuilt automatically)
177
- model = SignalJEPA_Contextual.from_pretrained("username/my-signaljepa_contextual-model", n_outputs=4)
178
-
179
- **Extracting features and replacing the head:**
180
 
181
- .. code::
182
- import torch
183
 
184
- x = torch.randn(1, model.n_chans, model.n_times)
185
- # Extract encoder features (consistent dict across all models)
186
- out = model(x, return_features=True)
187
- features = out["features"]
188
 
189
- # Replace the classification head
190
- model.reset_head(n_outputs=10)
191
 
192
- **Saving and restoring full configuration:**
193
 
194
- .. code::
195
- import json
 
196
 
197
- config = model.get_config() # all __init__ params
198
- with open("config.json", "w") as f:
199
- json.dump(config, f)
200
 
201
- model2 = SignalJEPA_Contextual.from_config(config) # reconstruct (no weights)
202
 
203
- All model parameters (both EEG-specific and model-specific such as
204
- dropout rates, activation functions, number of filters) are automatically
205
- saved to the Hub and restored when loading.
206
 
207
- See :ref:`load-pretrained-models` for a complete tutorial.</main>
208
- </div>
209
 
210
  ## Citation
211
 
212
- Please cite both the original paper for this architecture (see the
213
- *References* section above) and braindecode:
214
 
215
  ```bibtex
216
  @article{aristimunha2025braindecode,
 
14
 
15
  # SignalJEPA_Contextual
16
 
17
+ Contextual downstream architecture introduced in signal-JEPA Guetschel, P et al (2024) [1].
18
 
19
+ > **Architecture-only repository.** Documents the
20
  > `braindecode.models.SignalJEPA_Contextual` class. **No pretrained weights are
21
+ > distributed here.** Instantiate the model and train it on your own
22
+ > data.
 
23
 
24
  ## Quick start
25
 
 
38
  )
39
  ```
40
 
41
+ The signal-shape arguments above are illustrative defaults — adjust to
42
+ match your recording.
43
 
44
  ## Documentation
45
+ - Full API reference: <https://braindecode.org/stable/generated/braindecode.models.SignalJEPA_Contextual.html>
46
+ - Interactive browser (live instantiation, parameter counts):
 
 
47
  <https://huggingface.co/spaces/braindecode/model-explorer>
48
  - Source on GitHub: <https://github.com/braindecode/braindecode/blob/master/braindecode/models/signal_jepa.py#L489>
49
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
50
 
51
+ ## Architecture
 
52
 
53
+ ![SignalJEPA_Contextual architecture](https://braindecode.org/dev/_static/model/sjepa_contextual.jpg)
 
 
 
54
 
 
 
55
 
56
+ ## Parameters
57
 
58
+ | Parameter | Type | Description |
59
+ |---|---|---|
60
+ | `n_spat_filters` | int | Number of spatial filters. |
61
 
 
 
 
62
 
63
+ ## References
64
 
65
+ 1. Guetschel, P., Moreau, T., & Tangermann, M. (2024). S-JEPA: towards seamless cross-dataset transfer through dynamic spatial attention. In 9th Graz Brain-Computer Interface Conference, https://www.doi.org/10.3217/978-3-99161-014-4-003
 
 
66
 
 
 
67
 
68
  ## Citation
69
 
70
+ Cite the original architecture paper (see *References* above) and braindecode:
 
71
 
72
  ```bibtex
73
  @article{aristimunha2025braindecode,