braindecode.modules.SpatialTemporalBlock#

class braindecode.modules.SpatialTemporalBlock(n_dim, n_head, dropout, rope_positions=240)[source]#

Temporal attention (RoPE) on one feature half, spatial on the other.

The block of BrainOmni and MEG-XL. Steps: RMS-normalize the tokens; the first half of the features attends over time (with RoPE) and the second half over the channels; the two outputs are concatenated, spatial first (the halves swap, as released), and added to the input; then a RMS-normalized feed-forward layer with its residual. (batch, n_chans, n_times, n_dim) in and out.

Parameters:
  • n_dim (int) – Token width. Each attention works on n_dim // 2 features.

  • n_head (int) – Attention heads; each attention has n_head // 2.

  • dropout (float) – Dropout of the attention and of the feed-forward output.

  • rope_positions (int, default=240) – Positions cached by the rotary embedding of the temporal attention; a longer sequence rebuilds it.

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.

Return type:

Tensor