File size: 3,434 Bytes
2d5ba6a
 
 
 
 
 
 
 
 
 
 
 
 
1b262b3
2d5ba6a
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1b262b3
 
4588488
1b262b3
 
 
4588488
1b262b3
2d5ba6a
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
90
91
92
---
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}
}
```