braindecode.models.BIOT#

class braindecode.models.BIOT(emb_size=256, att_num_heads=8, n_layers=4, sfreq=200, hop_length=100, return_feature=False, n_outputs=None, n_chans=None, chs_info=None, n_times=None, input_window_seconds=None, activation: ~torch.nn.modules.module.Module = <class 'torch.nn.modules.activation.ELU'>, drop_prob: float = 0.5)[source]#

BIOT from Yang et al. (2023) [Yang2023]

BioT

BIOT: Cross-data Biosignal Learning in the Wild.

BIOT is a large language model for biosignal classification. It is a wrapper around the BIOTEncoder and ClassificationHead modules.

It is designed for N-dimensional biosignal data such as EEG, ECG, etc. The method was proposed by Yang et al. [Yang2023] and the code is available at [Code2023]

The model is trained with a contrastive loss on large EEG datasets TUH Abnormal EEG Corpus with 400K samples and Sleep Heart Health Study 5M. Here, we only provide the model architecture, not the pre-trained weights or contrastive loss training.

The architecture is based on the LinearAttentionTransformer and PatchFrequencyEmbedding modules. The BIOTEncoder is a transformer that takes the input data and outputs a fixed-size representation of the input data. More details are present in the BIOTEncoder class.

The ClassificationHead is an ELU activation layer, followed by a simple linear layer that takes the output of the BIOTEncoder and outputs the classification probabilities.

Added in version 0.9.

Parameters:
  • emb_size (int, optional) – The size of the embedding layer, by default 256

  • att_num_heads (int, optional) – The number of attention heads, by default 8

  • n_layers (int, optional) – The number of transformer layers, by default 4

  • sfreq (int, optional) – The sfreq parameter for the encoder. The default is 200

  • hop_length (int, optional) – The hop length for the torch.stft transformation in the encoder. The default is 100.

  • 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.

  • 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 to mne.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.

  • 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.

  • drop_prob – The description is missing.

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

[Yang2023] (1,2)

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.

[Code2023]

Yang, C., Westover, M.B. and Sun, J., 2023. BIOT Biosignal Transformer for Cross-data Learning in the Wild. GitHub ycq091044/BIOT (accessed 2024-02-13)

Methods

forward(x)[source]#

Pass the input through the BIOT encoder, and then through the classification head.

Parameters:

x (Tensor) – (batch_size, n_channels, n_times)

Returns:

  • out (Tensor) – (batch_size, n_outputs)

  • (out, emb) (tuple Tensor) – (batch_size, n_outputs), (batch_size, emb_size)