File size: 3,752 Bytes
12c7e40 da66cd2 12c7e40 da66cd2 12c7e40 da66cd2 12c7e40 da66cd2 12c7e40 da66cd2 12c7e40 da66cd2 12c7e40 da66cd2 12c7e40 da66cd2 0530159 da66cd2 3a235a1 da66cd2 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 | ---
pipeline_tag: feature-extraction
tags:
- eeg
- brain-computer-interface
- self-supervised-learning
- mamba
- pytorch
---
# SAMBA-100s
[Project website](https://samba.dcode.ai/) · [Code](https://github.com/Jiazhen-Hong/SAMBA) · [Paper](https://arxiv.org/abs/2511.18571) · [SAMBA-2s](https://huggingface.co/Dcode-AI/SAMBA-2s)
SAMBA-100s was pretrained on 100-second windows from the Temple University Hospital Abnormal EEG Corpus (TUAB), using 12,800 samples at 128 Hz and 16 bipolar channels. Retraining followed the original method with a rebuilt TUAB pipeline and validation split. The encoder supports other window lengths and electrode layouts.
## Download
[Download config](https://huggingface.co/Dcode-AI/SAMBA-100s/resolve/main/config.json?download=true) · [Download weights](https://huggingface.co/Dcode-AI/SAMBA-100s/resolve/main/model.safetensors?download=true)
Keep both files in the same directory. To download them together from a terminal:
```bash
pip install -U huggingface_hub
hf download Dcode-AI/SAMBA-100s config.json model.safetensors --local-dir ./SAMBA-100s
```
## Usage
Install SAMBA in a CUDA environment:
```bash
git clone https://github.com/Jiazhen-Hong/SAMBA.git
cd SAMBA
pip install -e '.[mamba,hub]'
```
Load the downloaded directory. If you skipped the download step, the following example fetches both files automatically:
```python
import torch
from huggingface_hub import snapshot_download
from samba_eeg import SambaModel
folder = snapshot_download(
"Dcode-AI/SAMBA-100s",
allow_patterns=["config.json", "model.safetensors"],
)
model = SambaModel.from_pretrained(folder).cuda().eval()
```
For files you already downloaded, pass their local directory to `SambaModel.from_pretrained` in place of `folder`.
Prepare EEG at 128 Hz. Use `signals` shaped `[batch, channels, samples]` and electrode `positions` shaped `[channels, 3]` or `[batch, channels, 3]`. Match the signal channel order and use the same coordinate frame and units as the target positions in `config.json`. TUAB pretraining used a 0.5–45 Hz bandpass. The decoder reconstructs EEG on a fixed 16-channel bipolar montage.
```python
signals = signals.to(device="cuda", dtype=torch.float32)
positions = positions.to(device="cuda", dtype=torch.float32)
# Skip these two lines if the signals are already normalized this way.
scale = torch.quantile(signals.abs(), 0.95, dim=-1, keepdim=True)
signals = signals / scale.clamp_min(1e-8)
with torch.inference_mode():
features = model.encode(signals, positions)
pooled_features = features.mean(dim=1)
```
`features` has shape `[batch, floor(samples / 8), 128]`. Use `pooled_features` for linear probing.
## Learned EEG spatial weights
SAMBA uses electrode coordinates to learn how to combine EEG channels. These maps show how the spatial weights change during training.
| Eyes open vs. closed | Driver distraction | Motor imagery |
|:---:|:---:|:---:|
| <img src="https://raw.githubusercontent.com/Jiazhen-Hong/SAMBA/main/Figures/Topo_gif/EyesState_GIF.gif" width="250" alt="Eyes open vs. closed"> | <img src="https://raw.githubusercontent.com/Jiazhen-Hong/SAMBA/main/Figures/Topo_gif/DriverDistraction_GIF.gif" width="238" alt="Driver distraction"> | <img src="https://raw.githubusercontent.com/Jiazhen-Hong/SAMBA/main/Figures/Topo_gif/MI_GIF.gif" width="245" alt="Motor imagery"> |
## Citation
```bibtex
@inproceedings{hong2026samba,
title = {{SAMBA}: Toward an {EEG} Foundation Model via Differential Mamba and Coordinate-Driven Spatial Embedding},
author = {Hong, Jiazhen and Mackellar, Geoffrey and Ghane, Soheila},
booktitle = {NeurReps 2026: Symmetry and Geometry in Neural Representations (Proceedings Track)},
year = {2026}
}
```
|