bruAristimunha commited on
Commit
940ee58
·
verified ·
1 Parent(s): df78b1a

Replace with clean markdown card

Browse files
Files changed (1) hide show
  1. README.md +23 -174
README.md CHANGED
@@ -9,19 +9,16 @@ tags:
9
  - neuroscience
10
  - braindecode
11
  - foundation-model
12
- - transformer
13
- - sleep-staging
14
  ---
15
 
16
  # InterpolatedBIOT
17
 
18
  Channel-interpolating wrapper around :class:`BIOT`.
19
 
20
- > **Architecture-only repository.** This repo documents the
21
  > `braindecode.models.InterpolatedBIOT` class. **No pretrained weights are
22
- > distributed here** instantiate the model and train it on your own
23
- > data, or fine-tune from a published foundation-model checkpoint
24
- > separately.
25
 
26
  ## Quick start
27
 
@@ -40,191 +37,43 @@ model = InterpolatedBIOT(
40
  )
41
  ```
42
 
43
- The signal-shape arguments above are example defaults — adjust them
44
- to match your recording.
45
 
46
  ## Documentation
47
-
48
- - Full API reference (parameters, references, architecture figure):
49
- <https://braindecode.org/stable/generated/braindecode.models.InterpolatedBIOT.html>
50
- - Interactive browser with live instantiation:
51
  <https://huggingface.co/spaces/braindecode/model-explorer>
52
  - Source on GitHub: <https://github.com/braindecode/braindecode/blob/master/braindecode/models/interpolated.py#L1>
53
 
54
- ## Architecture description
55
-
56
- The block below is the rendered class docstring (parameters,
57
- references, architecture figure where available).
58
-
59
- <div class='bd-doc'><main>
60
- <p>Channel-interpolating wrapper around :class:`BIOT`.</p>
61
- <p>:bdg-dark-line:`Channel`</p>
62
- <p>Accepts arbitrary user <span class="docutils literal">chs_info</span> and projects them to the
63
- backbone's canonical channel set via
64
- :class:`~braindecode.modules.ChannelInterpolationLayer`.</p>
65
- <p>For all other parameters and behavior see the backbone
66
- documentation reproduced below.</p>
67
- <p>BIOT from Yang et al (2023) [Yang2023]_</p>
68
- <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>
69
-
70
-
71
-
72
- .. figure:: https://braindecode.org/dev/_static/model/biot.jpg
73
- :align: center
74
- :alt: BioT
75
-
76
- BIOT: Cross-data Biosignal Learning in the Wild.
77
-
78
- BIOT is a foundation model for biosignal classification. It is
79
- a wrapper around the `BIOTEncoder` and `ClassificationHead` modules.
80
-
81
- It is designed for N-dimensional biosignal data such as EEG, ECG, etc.
82
- The method was proposed by Yang et al. [Yang2023]_ and the code is
83
- available at [Code2023]_
84
-
85
- The model is trained with a contrastive loss on large EEG datasets
86
- TUH Abnormal EEG Corpus with 400K samples and Sleep Heart Health Study
87
- 5M. Here, we only provide the model architecture, not the pre-trained
88
- weights or contrastive loss training.
89
-
90
- The architecture is based on the `LinearAttentionTransformer` and
91
- `PatchFrequencyEmbedding` modules.
92
- The `BIOTEncoder` is a transformer that takes the input data and outputs
93
- a fixed-size representation of the input data. More details are
94
- present in the `BIOTEncoder` class.
95
-
96
- The `ClassificationHead` is an ELU activation layer, followed by a simple
97
- linear layer that takes the output of the `BIOTEncoder` and outputs
98
- the classification probabilities.
99
-
100
- .. important::
101
- **Pre-trained Weights Available**
102
-
103
- This model has pre-trained weights available on the Hugging Face Hub.
104
- You can load them using:
105
-
106
- .. code:: python
107
- from braindecode.models import BIOT
108
-
109
- # Load the original pre-trained model from Hugging Face Hub
110
- # For 16-channel models:
111
- model = BIOT.from_pretrained("braindecode/biot-pretrained-prest-16chs")
112
-
113
- # For 18-channel models:
114
- model = BIOT.from_pretrained("braindecode/biot-pretrained-shhs-prest-18chs")
115
- model = BIOT.from_pretrained("braindecode/biot-pretrained-six-datasets-18chs")
116
-
117
- To push your own trained model to the Hub:
118
-
119
- .. code:: python
120
- # After training your model
121
- model.push_to_hub(
122
- repo_id="username/my-biot-model", commit_message="Upload trained BIOT model"
123
- )
124
-
125
- Requires installing ``braindecode[hug]`` for Hub integration.
126
-
127
- .. versionadded:: 0.9
128
-
129
- Parameters
130
- ----------
131
- embed_dim : int, optional
132
- The size of the embedding layer, by default 256
133
- num_heads : int, optional
134
- The number of attention heads, by default 8
135
- num_layers : int, optional
136
- The number of transformer layers, by default 4
137
- activation: nn.Module, default=nn.ELU
138
- Activation function class to apply. Should be a PyTorch activation
139
- module class like ``nn.ReLU`` or ``nn.ELU``. Default is ``nn.ELU``.
140
- return_feature: bool, optional
141
- Changing the output for the neural network. Default is single tensor
142
- when return_feature is True, return embedding space too.
143
- Default is False.
144
- hop_length: int, optional
145
- The hop length for the torch.stft transformation in the
146
- encoder. The default is 100.
147
- sfreq: int, optional
148
- The sfreq parameter for the encoder. The default is 200
149
-
150
- References
151
- ----------
152
- .. [Yang2023] Yang, C., Westover, M.B. and Sun, J., 2023, November. BIOT:
153
- Biosignal Transformer for Cross-data Learning in the Wild. In Thirty-seventh
154
- Conference on Neural Information Processing Systems, NeurIPS.
155
- .. [Code2023] Yang, C., Westover, M.B. and Sun, J., 2023. BIOT
156
- Biosignal Transformer for Cross-data Learning in the Wild.
157
- GitHub https://github.com/ycq091044/BIOT (accessed 2024-02-13)
158
-
159
- .. rubric:: Hugging Face Hub integration
160
-
161
- When the optional ``huggingface_hub`` package is installed, all models
162
- automatically gain the ability to be pushed to and loaded from the
163
- Hugging Face Hub. Install with::
164
-
165
- pip install braindecode[hub]
166
-
167
- **Pushing a model to the Hub:**
168
-
169
- .. code::
170
- from braindecode.models import BIOT
171
-
172
- # Train your model
173
- model = BIOT(n_chans=22, n_outputs=4, n_times=1000)
174
- # ... training code ...
175
-
176
- # Push to the Hub
177
- model.push_to_hub(
178
- repo_id="username/my-biot-model",
179
- commit_message="Initial model upload",
180
- )
181
-
182
- **Loading a model from the Hub:**
183
-
184
- .. code::
185
- from braindecode.models import BIOT
186
-
187
- # Load pretrained model
188
- model = BIOT.from_pretrained("username/my-biot-model")
189
-
190
- # Load with a different number of outputs (head is rebuilt automatically)
191
- model = BIOT.from_pretrained("username/my-biot-model", n_outputs=4)
192
-
193
- **Extracting features and replacing the head:**
194
 
195
- .. code::
196
- import torch
197
 
198
- x = torch.randn(1, model.n_chans, model.n_times)
199
- # Extract encoder features (consistent dict across all models)
200
- out = model(x, return_features=True)
201
- features = out["features"]
202
 
203
- # Replace the classification head
204
- model.reset_head(n_outputs=10)
205
 
206
- **Saving and restoring full configuration:**
207
 
208
- .. code::
209
- import json
 
 
 
 
 
 
 
210
 
211
- config = model.get_config() # all __init__ params
212
- with open("config.json", "w") as f:
213
- json.dump(config, f)
214
 
215
- model2 = BIOT.from_config(config) # reconstruct (no weights)
216
 
217
- All model parameters (both EEG-specific and model-specific such as
218
- dropout rates, activation functions, number of filters) are automatically
219
- saved to the Hub and restored when loading.
220
 
221
- See :ref:`load-pretrained-models` for a complete tutorial.</main>
222
- </div>
223
 
224
  ## Citation
225
 
226
- Please cite both the original paper for this architecture (see the
227
- *References* section above) and braindecode:
228
 
229
  ```bibtex
230
  @article{aristimunha2025braindecode,
 
9
  - neuroscience
10
  - braindecode
11
  - foundation-model
 
 
12
  ---
13
 
14
  # InterpolatedBIOT
15
 
16
  Channel-interpolating wrapper around :class:`BIOT`.
17
 
18
+ > **Architecture-only repository.** Documents the
19
  > `braindecode.models.InterpolatedBIOT` class. **No pretrained weights are
20
+ > distributed here.** Instantiate the model and train it on your own
21
+ > data.
 
22
 
23
  ## Quick start
24
 
 
37
  )
38
  ```
39
 
40
+ The signal-shape arguments above are illustrative defaults — adjust to
41
+ match your recording.
42
 
43
  ## Documentation
44
+ - Full API reference: <https://braindecode.org/stable/generated/braindecode.models.InterpolatedBIOT.html>
45
+ - Interactive browser (live instantiation, parameter counts):
 
 
46
  <https://huggingface.co/spaces/braindecode/model-explorer>
47
  - Source on GitHub: <https://github.com/braindecode/braindecode/blob/master/braindecode/models/interpolated.py#L1>
48
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
49
 
50
+ ## Architecture
 
51
 
52
+ ![InterpolatedBIOT architecture](https://braindecode.org/dev/_static/model/biot.jpg)
 
 
 
53
 
 
 
54
 
55
+ ## Parameters
56
 
57
+ | Parameter | Type | Description |
58
+ |---|---|---|
59
+ | `embed_dim` | int, optional | The size of the embedding layer, by default 256 |
60
+ | `num_heads` | int, optional | The number of attention heads, by default 8 |
61
+ | `num_layers` | int, optional | The number of transformer layers, by default 4 |
62
+ | `activation: nn.Module, default=nn.ELU` | — | Activation function class to apply. Should be a PyTorch activation module class like `nn.ReLU` or `nn.ELU`. Default is `nn.ELU`. |
63
+ | `return_feature: bool, optional` | — | Changing the output for the neural network. Default is single tensor when return_feature is True, return embedding space too. Default is False. |
64
+ | `hop_length: int, optional` | — | The hop length for the torch.stft transformation in the encoder. The default is 100. |
65
+ | `sfreq: int, optional` | — | The sfreq parameter for the encoder. The default is 200 |
66
 
 
 
 
67
 
68
+ ## References
69
 
70
+ 1. Yang, C., Westover, M.B. and Sun, J., 2023, November. BIOT: Biosignal Transformer for Cross-data Learning in the Wild. In Thirty-seventh Conference on Neural Information Processing Systems, NeurIPS.
71
+ 2. Yang, C., Westover, M.B. and Sun, J., 2023. BIOT Biosignal Transformer for Cross-data Learning in the Wild. GitHub https://github.com/ycq091044/BIOT (accessed 2024-02-13)
 
72
 
 
 
73
 
74
  ## Citation
75
 
76
+ Cite the original architecture paper (see *References* above) and braindecode:
 
77
 
78
  ```bibtex
79
  @article{aristimunha2025braindecode,