braindecode.models.Pratibha2#

class braindecode.models.Pratibha2(n_outputs=None, n_chans=None, chs_info=None, n_times=None, input_window_seconds=None, sfreq=None, *, patch_size=200, patch_stride=180, embed_dim=512, depth=22, num_heads=8, ffn_expansion=4, n_freqs=4, freq_range=(1.0, 10.0), head_hidden_dim=128, normalize_input=True, std_floor=1e-12, head_activation=<class 'torch.nn.modules.activation.ELU'>, drop_prob=0.3, att_drop_prob=0.0, norm_eps=1e-08, on_missing='error', channel_strategy='native', channel_strategy_kwargs=None)[source]#

PRATIBHA-2 (formerly MANAS-2) from Kulkarni et al. (2026) [manas2].

Foundation Model Attention/Transformer Channel

Added in version 2.1.

Architecture Overview

A transformer encoder pretrained with masked autoencoding on clinical and research EEG: waveform and spectral reconstruction (Raw-Band Hybrid) with a constraint on the local RMS energy of the reconstructed waveform (Constrained Reconstruction). Every electrode-patch pair is one token and every layer attends densely over all tokens of the window:

(batch, n_chans, n_times) -> per-channel z-score -> 1 s patches
(0.1 s overlap) -> patch embedding + 4D position encoding -> dense
transformer -> mean over tokens -> head -> (batch, n_outputs)

Macro Components

Pratibha2.patch_embed

Operations. Linear(patch_size, embed_dim) on each patch. Role. One token per electrode and patch; the same weights serve every electrode.

Pratibha2.pos_enc

Operations. Sines and cosines of n_freqs ** 4 frequency combinations of the token’s 4D position (electrode position in cm, patch index), projected to embed_dim, plus a learned gated branch; the sum is RMS-normalized and added to the patch embedding. Role. Tells the attention each token’s electrode and patch; this is how the montage enters the encoder.

Pratibha2.blocks

Operations. depth pre-norm blocks (RMSNorm) of multi-head self-attention and a gated feed-forward network fc2(fc1(x) * (swish(g) + gelu_tanh(g))), g = fc_gate(x). Role. The pretrained backbone; encode() returns its token grid.

Pratibha2.final_norm

Operations. RMSNorm of every token, the last step of encode(). Role. Normalizes the tokens that encode() returns and the head pools.

Pratibha2.final_layer

Operations. Linear -> head_activation -> Dropout -> Linear on the token mean. Not pretrained. Role. The classification head; train it for your task.

Temporal, Spatial, and Spectral Encoding

  • Temporal: 1 s patches with a learned linear embedding, ordered by the patch index of the position encoding.

  • Spatial: electrodes enter only through their 3D positions, so any montage the position table places can be read.

  • Spectral: learned by the band-power reconstruction target.

Additional Mechanisms

  • Channel positions. The pretraining electrode table, REVE’s bank (part of the 10-05 family, all of BioSemi-128 and of GSN-HydroCel-129) plus PRATIBHA-2’s own AFZ and IZ, looked up by name (exact spelling first, then ignoring case, EEG/-REF, T3-style aliases, or the midpoint of a bipolar A-B; see resolve_channel_positions()). Other 10-05 names take their position in MNE’s standard_1005 montage frame, the frame of the table’s 10-05 entries. Channel loc values are not used: they are in MNE’s head frame, a few centimetres from the pretraining frame.

  • Input scale. With normalize_input=True each channel is z-scored within each window, with a floor on the standard deviation (std_floor), so volts and microvolts give the same output; on microvolt data it matches the preprocessing of the release’s example, (x - mean) / (std + 1e-6).

Important

Resample to 200 Hz; windows need at least patch_size samples. The released 92.8M-parameter encoder (MannasAI/pratibha-2, Apache-2.0, release 863edc9), converted to these parameter names, is on the Hugging Face Hub at braindecode/pratibha2-pretrained; the head is not pretrained:

from braindecode.models import Pratibha2
model = Pratibha2.from_pretrained(
    "braindecode/pratibha2-pretrained",
    chs_info=raw.info["chs"], n_outputs=4, n_times=1000,
)
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 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.

  • sfreq (float) – Sampling frequency of the EEG recordings.

  • patch_size (int) – Number of samples per patch (token length). 200 samples = 1 s at 200 Hz.

  • patch_stride (int) – Step between consecutive patches, in samples.

  • embed_dim (int) – Token embedding dimension.

  • depth (int) – Number of transformer blocks.

  • num_heads (int) – Number of attention heads.

  • ffn_expansion (int) – Width multiplier of the gated feed-forward network.

  • n_freqs (int) – Frequencies per axis of the Fourier position encoding.

  • freq_range (tuple[float, float]) – Lowest and highest of those frequencies, evenly spaced ([1, 10] in release 863edc9).

  • head_hidden_dim (int) – Hidden size of the classification head.

  • normalize_input (bool) – If True, z-score each channel within each window before patching.

  • std_floor (float) – Floor of a channel’s standard deviation in that z-score, 1e-12 by default. The release’s example adds 1e-6 to it instead, so volts and microvolts would give different tokens.

  • head_activation (type[Module]) – Activation of the classification head.

  • drop_prob (float) – Dropout probability in the classification head.

  • att_drop_prob (float) – Attention dropout probability (0 in the pretrained model).

  • norm_eps (float) – Epsilon of every RMSNorm (1e-8 in model.py of release 863edc9).

  • on_missing (str) – Channels the position table cannot place: "error" raises, "drop" leaves them out of the input, "nearest" takes the table entry closest to the channel’s loc (approximate: loc is in a different frame).

  • channel_strategy (str) – How another montage reaches the encoder; see EEGModuleMixin. PRATIBHA-2 reads any montage natively, so the default "native" is usually what you want.

  • channel_strategy_kwargs (Optional[dict]) – Options of channel_strategy.

Raises:

ValueError – If some input signal-related parameters are not specified: and can not be inferred.

Notes

If some input signal-related parameters are not specified, there will be an attempt to infer them from the other parameters.

References

[manas2]

Kulkarni, A., Mishra, A. R., Jain, M., Runwal, P., Saini, L., Panwar, S., & Singh, S. (2026). MANAS-2: Constrained Reconstruction for EEG Foundation Models. arXiv:2609.13717. https://arxiv.org/abs/2609.13717

Hugging Face Hub integration

When the optional huggingface_hub package is installed, all models automatically gain the ability to be pushed to and loaded from the Hugging Face Hub. Install with:

pip install braindecode[hub]

Pushing a model to the Hub:

from braindecode.models import Pratibha2

# Train your model
model = Pratibha2(n_chans=22, n_outputs=4, n_times=1000)
# ... training code ...

# Push to the Hub; ``datasets`` and ``base_model`` go to the card
model.push_to_hub(
    repo_id="username/my-pratibha2-model",
    commit_message="Initial model upload",
    model_card_kwargs={"datasets": ["BNCI2014_001"]},
)

Loading a model from the Hub:

from braindecode.models import Pratibha2

# Load pretrained model
model = Pratibha2.from_pretrained("username/my-pratibha2-model")
# Data the weights were trained on, from the Hub model card
print(model.card_data.datasets if model.card_data else None)

# Load with a different number of outputs (head is rebuilt automatically)
model = Pratibha2.from_pretrained("username/my-pratibha2-model", n_outputs=4)

Extracting features and replacing the head:

import torch

x = torch.randn(1, model.n_chans, model.n_times)
# Extract encoder features (consistent dict across all models)
out = model(x, return_features=True)
features = out["features"]

# Replace the classification head
model.reset_head(n_outputs=10)

Saving and restoring full configuration:

import json

config = model.get_config()            # all __init__ params
with open("config.json", "w") as f:
    json.dump(config, f)

model2 = Pratibha2.from_config(config)    # reconstruct (no weights)

All model parameters (both EEG-specific and model-specific such as dropout rates, activation functions, number of filters) are automatically saved to the Hub and restored when loading.

See Loading and Adapting Pretrained Foundation Models for a complete tutorial.

Methods

encode(x)[source]#

Encode EEG into the grid of token embeddings.

This is the encoder output before pooling and the classification head.

Parameters:

x (Tensor) – EEG of shape (batch, n_chans, n_times), sampled at 200 Hz.

Returns:

Tokens of shape (batch, n_kept_chans, n_patches, embed_dim), where n_kept_chans excludes channels dropped by on_missing="drop".

Return type:

Tensor

forward(x, return_features=False)[source]#

Classify a batch of EEG windows.

Tokens are averaged over electrodes and patches, then passed to the classification head final_layer.

Parameters:
  • x (Tensor) – EEG of shape (batch, n_chans, n_times), sampled at 200 Hz.

  • return_features (bool) – If True, return a dict with the pooled embedding ("features", shape (batch, embed_dim)) and the token grid ("tokens", shape (batch, n_kept_chans, n_patches, embed_dim), see encode()) instead of logits.

Returns:

Logits of shape (batch, n_outputs), or the feature dict when return_features is True.

Return type:

Union[Tensor, dict[str, Optional[Tensor]]]

reset_head(n_outputs)[source]#

Replace the classification head for a new number of outputs.

The encoder is left unchanged; the new head is randomly initialised.

Parameters:

n_outputs (int) – Number of outputs of the new head.

Return type:

None

Examples

>>> from braindecode.models import BENDR
>>> model = BENDR(n_chans=22, n_times=1000, n_outputs=4)
>>> model.reset_head(10)
>>> model.n_outputs
10

Added in version 1.4.