Update README.md
Browse files2 unmodified lines3456678910111212131415161718141920212223242526271628293031323334353637383940414243442245464748495051525354555657585960616263646566676869707172737475767778798081828384858687882 unmodified linestags: - eeg - brain-computer-interface - pytorch - self-supervised-learning - mamba - pytorch---
# SAMBA-2s
SAMBA EEG encoder pretrained on 2-second windows at 128 Hz using Emotiv, HBN, Muse, and DICE. The encoder supports other input lengths and electrode layouts.[Project website](https://samba.dcode.ai/) 路 [Code](https://github.com/Jiazhen-Hong/SAMBA) 路 [Paper](https://arxiv.org/abs/2511.18571) 路 [SAMBA-100s](https://huggingface.co/Dcode-AI/SAMBA-100s)
SAMBA-2s was pretrained on 2-second EEG windows from Emotiv (Alpha, Attention, Crowdsource, DriverDistraction, and STEW), HBN resting state, Muse sleep onset, and DICE eyes closed. Pretraining used 256 samples per window at 128 Hz and 4, 14, 19, and 129 EEG channels. The encoder supports other window lengths and electrode layouts.
## Download
[Project](https://samba.dcode.ai/) 路 [Code](https://github.com/Jiazhen-Hong/SAMBA) 路 [Paper](https://arxiv.org/abs/2511.18571) 路 [Shared usage guide](https://huggingface.co/Dcode-AI/SAMBA) 路 [SAMBA-100s](https://huggingface.co/Dcode-AI/SAMBA-100s)[Download config](https://huggingface.co/Dcode-AI/SAMBA-2s/resolve/main/config.json?download=true) 路 [Download weights](https://huggingface.co/Dcode-AI/SAMBA-2s/resolve/main/model.safetensors?download=true)
Keep both files in the same directory. To download them together from a terminal:
```bashpip install -U huggingface_hubhf download Dcode-AI/SAMBA-2s config.json model.safetensors --local-dir ./SAMBA-2s```
Install SAMBA from the code repository with `pip install -e '.[mamba,hub]'`. Inference requires CUDA.## Usage
Install SAMBA in a CUDA environment:
```bashgit clone https://github.com/Jiazhen-Hong/SAMBA.gitcd SAMBApip install -e '.[mamba,hub]'```
Load the downloaded directory. If you skipped the download step, the following example fetches both files automatically:
```pythonimport torchfrom huggingface_hub import snapshot_downloadfrom samba_eeg import SambaModel
folder = snapshot_download("Dcode-AI/SAMBA-2s", allow_patterns=["config.json", "model.safetensors"])folder = snapshot_download( "Dcode-AI/SAMBA-2s", 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`. The decoder reconstructs EEG at the input electrode coordinates.
```pythonsignals = 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="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"> |
## 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}}```README.md+69-5