neuraltrain.models.base.BaseBrainDecodeModel

pydantic model neuraltrain.models.base.BaseBrainDecodeModel[source][source]

Base class for braindecode model configurations.

Subclasses set _MODEL_CLASS_PATH (e.g. "braindecode.models.Labram") to resolve the underlying class lazily, avoiding an unconditional braindecode import at module load time. Subclasses that need custom resolution (e.g. optional-dependency handling) can instead override _ensure_model_class directly.

The dynamic registration in _register_braindecode_models() sets _MODEL_CLASS directly at import time for the common braindecode models, which short-circuits the lazy path.

kwargs[source]

Free-form keyword arguments forwarded to the braindecode model constructor. Validated against the model’s __init__ signature at config creation time.

Type:

dict

from_pretrained_name[source]

Optional HuggingFace Hub repository ID (e.g. "braindecode/labram-pretrained"). When set, build() calls _MODEL_CLASS.from_pretrained() instead of the regular constructor.

Type:

str or None

Fields:
required_fields: ClassVar[list[Literal['ch_names', 'n_times', 'sfreq']]] = [][source]

Which data-derived build inputs this braindecode model requires forwarded from the context. Members:

  • "ch_names" – forward chs_info from the dataset’s channel names (e.g. LaBraM, REVE);

  • "n_times" – forward n_times even on the pretrained path (non-pretrained builds always receive it);

  • "sfreq" – forward the sampling rate (frequency -> braindecode sfreq, e.g. models with a fixed spectral front end).

Empty by default: most models take sfreq via config kwargs and need neither channel names nor a pretrained-path n_times.

field kwargs: dict[str, Any] = {}[source]
field from_pretrained_name: str | None = None[source]
build(n_spatial_locations: int, n_temporal_samples: int, n_outputs: int | None = None, chs_info: list[dict[str, Any]] | None = None, frequency: float | None = None) Module[source][source]

Build the braindecode model from context-named shape parameters.

Parameters are named/typed like BrainModelBuildContext fields/properties, so the base build_from_context injects them (chs_info / frequency from the matching context properties/fields). Covers every auto-registered braindecode model (EEGNet, Deep4Net, ShallowFBCSPNet, BIOT, …); custom configs (LaBraM, REVE, LUNA, BENDR) override this and reuse _bd_shape_kwargs() for the name mapping.