braindecode.models.SignalJEPA_Contextual#
- class braindecode.models.SignalJEPA_Contextual(n_outputs=None, n_chans=None, chs_info=None, n_times=None, input_window_seconds=None, sfreq=None, *, n_spat_filters: int = 4, feature_encoder__conv_layers_spec: ~typing.Sequence[tuple[int, int, int]] = ((8, 32, 8), (16, 2, 2), (32, 2, 2), (64, 2, 2), (64, 2, 2)), drop_prob: float = 0.0, feature_encoder__mode: str = 'default', feature_encoder__conv_bias: bool = False, activation: type[~torch.nn.modules.module.Module] = <class 'torch.nn.modules.activation.GELU'>, pos_encoder__spat_dim: int = 30, pos_encoder__time_dim: int = 34, pos_encoder__sfreq_features: float = 1.0, pos_encoder__spat_kwargs: dict | None = None, transformer__d_model: int = 64, transformer__num_encoder_layers: int = 8, transformer__num_decoder_layers: int = 4, transformer__nhead: int = 8, _init_feature_encoder: bool = True, _init_transformer: bool = True)[source]#
Contextual downstream architecture introduced in signal-JEPA Guetschel, P et al (2024) [1].
This architecture is one of the variants of
SignalJEPA
that can be used for classification purposes.Added in version 0.9.
- Parameters:
n_outputs (int) – Number of outputs of the model. This is the number of classes in the case of classification.
n_chans (int) – Number of EEG channels.
chs_info (list of dict) – Information about each individual EEG channel. This should be filled with
info["chs"]
. Refer tomne.Info
for more details.n_times (int) – Number of time samples of the input window.
input_window_seconds (float) – Length of the input window in seconds.
sfreq (float) – Sampling frequency of the EEG recordings.
n_spat_filters (int) – Number of spatial filters.
feature_encoder__conv_layers_spec (list of tuple) –
Tuples have shape
(dim, k, stride)
where:dim
: number of output channels of the layer (unrelated to EEG channels);k
: temporal length of the layer’s kernel;stride
: temporal stride of the layer’s kernel.
drop_prob (float)
feature_encoder__mode (str) – Normalisation mode. Either
default
orlayer_norm
.feature_encoder__conv_bias (bool)
activation (nn.Module) – Activation layer for the feature encoder.
pos_encoder__spat_dim (int) – Number of dimensions to use to encode the spatial position of the patch, i.e. the EEG channel.
pos_encoder__time_dim (int) – Number of dimensions to use to encode the temporal position of the patch.
pos_encoder__sfreq_features (float) – The “downsampled” sampling frequency returned by the feature encoder.
pos_encoder__spat_kwargs (dict) – Additional keyword arguments to pass to the
nn.Embedding
layer used to embed the channel names.transformer__d_model (int) – The number of expected features in the encoder/decoder inputs.
transformer__num_encoder_layers (int) – The number of encoder layers in the transformer.
transformer__num_decoder_layers (int) – The number of decoder layers in the transformer.
transformer__nhead (int) – The number of heads in the multiheadattention models.
_init_feature_encoder (bool) – Do not change the default value (used for internal purposes).
_init_transformer (bool) – Do not change the default value (used for internal purposes).
- Raises:
ValueError – If some input signal-related parameters are not specified: and can not be inferred.
FutureWarning – If add_log_softmax is True, since LogSoftmax final layer: will be removed in the future.
Notes
If some input signal-related parameters are not specified, there will be an attempt to infer them from the other parameters.
References
[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
Methods
- forward(X)[source]#
Define the computation performed at every call.
Should be overridden by all subclasses.
Note
Although the recipe for forward pass needs to be defined within this function, one should call the
Module
instance afterwards instead of this since the former takes care of running the registered hooks while the latter silently ignores them.- Parameters:
X – The description is missing.
- classmethod from_pretrained(model: SignalJEPA, n_outputs: int, n_spat_filters: int = 4, chs_info: list[dict[str, Any]] | None = None)[source]#
Instantiate a new model from a pre-trained
SignalJEPA
model.- Parameters:
model (SignalJEPA) – Pre-trained model.
n_outputs (int) – Number of classes for the new model.
n_spat_filters (int) – Number of spatial filters.
chs_info (list of dict | None) – Information about each individual EEG channel. This should be filled with
info["chs"]
. Refer tomne.Info
for more details.