BrainCodes A Lightweight EEG Foundation Model over Discrete Neural Codes

  • Kleanthis Avramidis1
  • Ivan Tashev2
  • Dimitra Emmanouilidou2

1University of Southern California  ·  2Microsoft Research

At a Glance

BrainCodes is a lightweight EEG foundation model with 1.9M trainable parameters, pretrained through self-supervised learning on more than 800 hours of EEG recordings from over 1,000 participants.

Most EEG foundation models are pretrained to reconstruct masked signal patches. Under a squared-error loss, high-power broadband activity dominates the objective, and a masked channel can largely be recovered by interpolating its neighbors, so a model can fit the signal well without retaining its rhythms or spatial structure. BrainCodes instead predicts the discrete codes of a frozen vector-quantized tokenizer, encodes relative electrode positions directly in channel attention, and adds an auxiliary objective that localizes synthetic oscillatory bursts. It matches or surpasses the state of the art across 14 benchmarks and transfers to consumer wearable devices.

Discrete by design

Each channel is tokenized by a VQ-based tokenizer, so the model predicts code indices instead of waveform power.

Montage-agnostic

Electrodes are modeled through rotary encodings of their 3D relative positions, so they are agnostic to the utilized layout.

Scaled down to 1.9M

A tuned lightweight backbone matches or surpasses the state of the art across 14 different performance benchmarks.

From electrodes to tokens to embeddings

BrainCodes pretraining. Input EEG is either tokenized by BioCodec and block-masked, or injected with a narrowband burst over a region of electrodes and then tokenized. Both token grids pass through a shared U-Net of factorized transformer blocks that attend over time and over channels, compressing time to T/2 and T/4. The masked branch predicts the missing codes; the perturbed branch reads the bottleneck to predict the burst's frequency, duration and location.
Figure 1. A) Contiguous blocks of codes are masked and the model predicts the missing indices, evaluated through mean cross-entropy over the masked positions (Ltok). B) Narrowband bursts are injected into regions of electrodes and the bottleneck is read by 3 different linear heads (Losc).

Raw EEG

(B, C, T) at 250 Hz, from any number of channels with provided 3D coordinates.

Tokenizer

Frozen BioCodec: 6 RVQ codes per channel, resulting in a 128D input embedding.

Backbone

A 3-layer, factorized time-channel U-Net with 3D rotary channel encoding.

Embeddings

Per-channel bottleneck features for probing downstream evaluation.

Downstream evaluation

Table 1. Balanced accuracy (BAC) on the main benchmark under full fine-tuning, mean over 3 seeds. Mean nBAC is the chance-normalized mean over the seven datasets.
Model Params TUAB TUEV ISRUC Siena Phy-MI BCI IV-2a EEGMAT Mean nBAC
BIOT3.2M0.7960.5280.7530.7350.6150.4750.6880.478
LaBraM-Base5.8M0.8140.6410.7630.7080.6170.4870.6910.501
CBraMod4.0M0.8290.6670.7870.7320.6420.5140.7260.540
REVE-Base69M0.8320.6760.7820.7400.6480.6400.7660.581
BrainCodes1.9M0.8110.6900.7960.8270.6640.6390.7720.609

Three lines to an embedding

The released package ships pretrained weights and a minimal API. Full documentation lives in the associated GitHub repository.

install
git clone https://github.com/microsoft/BrainCodes.git
cd BrainCodes && pip install -e .
# the frozen BioCodec tokenizer is a separate download
git clone https://github.com/klean2050/BioCodec-release.git
quickstart.py
import torch
from braincodes import BrainCodesModel

ch_names = ["TP9", "AF7", "AF8", "TP10"]
model = BrainCodesModel.from_pretrained(ch_names, device="cuda")

eeg = torch.randn(8, 4, 1000)        # (B, C, T) @ 250 Hz
emb = model.embed(eeg, pool="channel")  # (B, C*D)

clf = model.build_classifier(num_classes=4, mode="linear_probe")
logits = clf(model.tokenize(eeg))

Cite this study

BibTeX
@article{braincodes2026,
  title   = {BrainCodes: A Lightweight EEG Foundation Model over Discrete Neural Codes},
  author  = {Avramidis, Kleanthis and Emmanouilidou, Dimitra and Tashev, Ivan},
  year    = {2026}
}

Intended use disclosure

BrainCodes is hereby released for neuroscientific research. It is not intended to support clinical, diagnostic, or other high-impact decisions about individuals. The present release includes model parameters only, and no guidance or implementation for a specific downstream task.