Foundation models have revolutionized how we process text and images, but the "language of the brain"—Electroencephalography (EEG)—has proven much harder to crack. EEG signals are noisy, vary wildly between individuals, and contain a complex mix of temporal waveforms and frequency rhythms.
A new paper from researchers at the National University of Singapore and the Chinese Academy of Sciences introduces CodeBrain, a two-stage foundation model designed to bridge the gap between raw neural data and clinical interpretability.
TL;DR
CodeBrain is a novel EEG foundation model that uses a "decoupled" tokenizer to separate temporal and frequency information, making its internal representations clinically interpretable. By combining Structured State Space Models (SSMs) with sliding window attention, it mimics the brain's "small-world" connectivity to achieve state-of-the-art performance across 10 diverse datasets.
What Problem Does This Paper Address?
Most current EEG foundation models (EFMs) treat brain signals like images or text, using a single "mixed" tokenizer to turn signal patches into discrete codes. The authors argue this is a mistake. EEG is heterogeneous: a signal patch might look identical to another in the time domain but represent a completely different brain state in the frequency domain.
Furthermore, standard Transformer architectures used in EFMs are "over-connected." They use global self-attention, which has quadratic complexity and fails to reflect the small-world topology of the human brain—where neurons have dense local clusters and sparse long-range "shortcuts." Existing models often miss local neural events (like sleep spindles) while struggling to efficiently model long-range dependencies.
Methods
CodeBrain tackles these issues through a two-stage design:
- TFDual-Tokenizer: Instead of one codebook, CodeBrain uses two. It decouples the signal into Temporal and Frequency tokens. This "dual-stream" approach quadratically expands the representation space ($N \times N$ possible combinations) and allows the model to learn specific codes for waveforms (e.g., K-complexes) and rhythms (e.g., Alpha waves) independently.
- EEGSSM Architecture: To model these tokens, the authors built a multi-scale backbone:
- Global Scale: It uses Structured Global Convolutions (SGConv), a variant of State Space Models (SSMs), to capture long-range dependencies with $O(N \log N)$ efficiency.
- Local Scale: It employs Sliding Window Attention (SWA) to focus on fine-grained, intra-patch neural events that global models often overlook.
- Pretraining: The model is pretrained using a Masked Autoencoder (MAE) objective on a massive corpus, learning to predict missing temporal and frequency tokens.
Datasets
- Pretraining: The model was trained on the TUH EEG Corpus (TUEG), the largest public EEG dataset, involving over 9,246 hours of recordings.
- Evaluation: The researchers tested CodeBrain on 10 public datasets covering 8 downstream tasks, including:
- Emotion Recognition (FACED, SEED-V)
- Sleep Staging (ISRUC S1 & S3)
- Seizure Detection (CHB-MIT)
- Motor Imagery (SHU-MI)
- Imagined Speech (BCIC 2020-T3)
Key Insights and Ideas
- Decoupling is the "Aha!" Moment: By separating time and frequency, the model doesn't just get more accurate—it becomes more "human-readable." The authors visualized the learned tokens and found they naturally align with known neurophysiological markers like sleep spindles and delta waves.
- Efficiency via Small-World Logic: By replacing standard Transformers with an SSM-based architecture, CodeBrain achieves better results with fewer parameters (15M) than much larger models. It effectively mimics the brain's own structural efficiency.
- Quadratic Representation Power: Using two codebooks ($N$ temporal and $N$ frequency) allows for $N^2$ unique combinations. This provides a much richer "vocabulary" for the model to describe complex brain states without needing an impossibly large single codebook.
Key Results
CodeBrain consistently outperformed both task-specific models and existing foundation models (like BIOT, LaBraM, and EEGPT):
- Generalization: It achieved a +9.11% gain in Cohen’s Kappa on imagined speech classification over the strongest baseline.
- Robustness: In stress tests involving missing channels (dropping up to 50% of electrodes) and non-stationary shifts (simulating sensor drift), CodeBrain maintained significantly higher performance than its competitors.
- Scaling Laws: The authors demonstrated that CodeBrain follows clear scaling laws—performance continues to improve as they increase both the pretraining data volume (up to 9k hours) and model size.
Limitations and Future Work
- Scalp EEG Focus: The current study focuses entirely on scalp EEG. The authors note that extending this to intracranial EEG (iEEG) or ECoG, which have much higher frequency content, is a necessary next step.
- Fine-tuning Interpretability: While the pretraining tokens are interpretable, the authors suggest future work should explore "decision-level" interpretability—essentially explaining why the model made a specific prediction during a task like seizure detection.
- Cross-Modality: The current model is unimodal. Future iterations could integrate EEG with other physiological signals (like EKG or eye-tracking) for a more holistic view of brain-body states.
Check out the code and weights: GitHub - jingyingma01/CodeBrain
Summary updated