EEGMamba: Bidirectional State Space Model with Mixture of Experts for EEG Multi-task Classification

Yiyu Gui, MingZhi Chen, Yuqi Su, Guibo Luo, Yuchao YangarXiv 2024

TL;DR

EEGMamba is the first universal multi-task deep learning framework for EEG classification that can process diverse datasets with varying channel counts and signal lengths in a single training session. By combining bidirectional Mamba blocks with a task-aware Mixture of Experts (MoE), it achieves state-of-the-art performance across multiple clinical and cognitive tasks while maintaining linear computational complexity.

What Problem Does This Paper Address?

Electroencephalogram (EEG) data is notoriously messy and heterogeneous. Depending on the clinical or cognitive task—whether you are detecting epileptic seizures, tracking sleep stages, recognizing emotions, or decoding motor imagery—the data will feature different channel counts, sampling rates, and sequence lengths.

Because of this variability, existing deep learning models are strictly single-task; they require separate architectures, separate training sessions, and manual tuning for each specific dataset. Furthermore, while Transformer-based models excel at capturing long-range dependencies in brainwaves, their quadratic computational complexity ($O(N^2)$) makes processing long-duration EEG recordings computationally prohibitive.

The authors introduce EEGMamba to solve both problems at once: creating a single unified network capable of multi-task learning across completely different EEG datasets without exploding computational costs.

Figure 1: Our proposed EEGMamba can simultaneously process EEG signals from multiple tasks including epilepsy detection, sleep stage classification, emotion recognition, and motor imagery. It achieves state-of-the-art (SOTA) performance on the majority of datasets.

Methods

EEGMamba achieves its universality by seamlessly integrating three novel architectural components:

  1. Spatio-Temporal-Adaptive (ST-Adaptive) Module: To handle varying channel counts, this module uses a series of 1D convolutional sub-modules (spatial-adaptive convolution) that standardize any input channel size into a uniform feature dimension. To handle varying signal lengths, it introduces a tokenization layer paired with a special class token to achieve temporal adaptability.
  2. Bidirectional Mamba (BiMamba) Block: Standard State Space Models (SSMs) like Mamba are inherently causal and unidirectional, making them ideal for autoregressive tasks like language generation. However, EEG classification requires looking both forward and backward in time. The authors designed a bidirectional Mamba block that runs parallel forward and backward sequence modeling, capturing global context while preserving Mamba’s highly efficient linear complexity ($O(N)$).
  3. Task-Aware MoE with a Universal Expert: To prevent negative task interference (where learning one task degrades performance on another), a sparse gating network routes tokens to specialized experts based on an encoded task token. Crucially, the authors add a mandatory Universal Expert that processes all tokens regardless of the task, allowing the network to capture shared underlying physiological features across all human brain activity.
Figure 2: Overall structure of EEGMamba. The model consists of ST-Adaptive module, Bidirectional Mamba (BiMamba) blocks and Task-aware MoE modules.

Datasets

The model was rigorously evaluated on eight publicly available datasets spanning four distinct task domains:

  • Epilepsy Detection: Siena Scalp EEG, CHB-MIT
  • Sleep Stage Classification: SleepEDF-20, SHHS
  • Emotion Recognition: DEAP, SEED
  • Motor Imagery: Shu, BCI-IV-2a

Key Insights and Ideas

  • Breaking the Single-Task Paradigm: EEGMamba proves that a single model can be trained on entirely different datasets simultaneously. Instead of managing eight separate models, practitioners can deploy one model that dynamically adapts its routing based on the task at hand.
  • Linear Scaling for Long Sequences: As EEG sequence lengths grow to 40,000 data points, traditional Transformer baselines suffer from Out-Of-Memory (OOM) errors. EEGMamba scales linearly, proving that bidirectional state-space models are a viable, lightweight alternative to attention mechanisms for bio-signals.
  • Shared vs. Specific Knowledge: The visualization of the MoE gating network revealed that the model naturally develops preferences (e.g., routing epilepsy data to specific experts), while the Universal Expert successfully extracts commonalities, validating the hybrid design.

Key Results

  • State-of-the-Art Performance: Despite being a single multi-task model competing against specialized single-task networks, EEGMamba ranked in the top three across seven datasets and achieved the absolute best performance on four of them (including SleepEDF-20, SHHS, DEAP, and Shu).
  • Efficiency Benchmarks: In stress tests with multi-channel data at a sequence length of 40,000, Transformer models like AttnSleep and EEG Conformer failed due to memory limits. EEGMamba maintained a stable memory footprint (~46 GB) and maintained a steady inference speed of 5.05 iterations/second.

Limitations and Future Work

While EEGMamba represents a massive leap forward for universal bio-signal modeling, the authors note two primary limitations:

  1. Task Scope: The evaluation only covers four types of EEG tasks, which is only a fraction of what EEG data can be used for in clinical and Brain-Computer Interface (BCI) settings.
  2. Modality Constraints: The architecture is currently optimized purely for EEG. The authors suggest that future iterations should extend the model to other 1D physiological time-series signals, such as electrocardiograms (ECG) or electromyograms (EMG), to truly demonstrate multi-signal universality.

Summary updated

BibTeX
@misc{gui2024eegmamba,
  author = {Yiyu Gui and MingZhi Chen and Yuqi Su and Guibo Luo and Yuchao Yang},
  title = {{EEGMamba: Bidirectional State Space Model with Mixture of Experts for EEG Multi-task Classification}},
  year = {2024},
  eprint = {2407.20254},
  archivePrefix = {arXiv},
  url = {https://arxiv.org/abs/2407.20254},
}
Figure