SAMBA / README.md
Jay1208's picture
Update README.md
4588488 verified
|
Raw History Blame
3.43 kB
---
library_name: samba-eeg
pipeline_tag: feature-extraction
tags:
- eeg
- brain-computer-interface
- self-supervised-learning
- mamba
- pytorch
---
# SAMBA
EEG representation models. [Project website](https://samba.dcode.ai/) · [Code](https://github.com/Jiazhen-Hong/SAMBA) · [Paper](https://arxiv.org/abs/2511.18571)
SAMBA was developed during my 2025 internship at Emotiv. The original checkpoints are no longer available, so we retrained both models. SAMBA-100s follows the original training method with a rebuilt TUAB pipeline and validation split. SAMBA-2s adds HBN, Muse, and DICE to the Emotiv data for greater electrode-layout diversity.
## Checkpoints
Both models use 128 Hz EEG. The names indicate the pretraining window; the encoders support other input lengths and channel layouts.
| | [SAMBA-2s](SAMBA-2s) | [SAMBA-100s](SAMBA-100s) |
|---|---|---|
| Window | 2 s, 256 samples | 100 s, 12,800 samples |
| Data | Emotiv¹, HBN, Muse, DICE | TUAB |
| Pretraining channels | 4, 14, 19, 129 | 16 bipolar |
| Parameters | 1.06M | 1.06M |
¹ Alpha, Attention, Crowdsource, DriverDistraction, and STEW.
## 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="250" alt="Driver distraction"> | <img src="https://raw.githubusercontent.com/Jiazhen-Hong/SAMBA/main/Figures/Topo_gif/MI_GIF.gif" width="250" alt="Motor imagery"> |
## Usage
Requires a compatible CUDA system.
```bash
git clone https://github.com/Jiazhen-Hong/SAMBA.git
cd SAMBA
pip install -e '.[mamba,hub]'
```
```python
from pathlib import Path
import torch
from huggingface_hub import snapshot_download
from samba_eeg import SambaModel
variant = "SAMBA-2s" # or "SAMBA-100s"
folder = snapshot_download(
"Jay1208/SAMBA",
allow_patterns=[f"{variant}/*"],
)
model = SambaModel.from_pretrained(Path(folder) / variant).cuda().eval()
```
Prepare EEG at 128 Hz:
- `signals`: `[batch, channels, samples]`.
- `positions`: `[channels, 3]` or `[batch, channels, 3]`, matching the channel order and the coordinate units and frame in `config.json`.
- Normalize each channel in each window by its absolute 95th percentile. TUAB pretraining uses a 0.5–45 Hz bandpass.
```python
signals = signals.to(device="cuda", dtype=torch.float32)
positions = positions.to(device="cuda", dtype=torch.float32)
# Skip if already normalized.
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 the pooled features for linear probing, or fine-tune the encoder.
## Citation
```bibtex
@article{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},
journal={arXiv preprint arXiv:2511.18571},
year={2026}
}
```