Add MAPA mapa_vits384 converted from bentang18/MAPA@988efbf3 (Apache-2.0)
Browse files- NOTICE +64 -0
- README.md +72 -0
- config.json +19 -0
- convert_mapa_checkpoint.py +58 -0
- model.safetensors +3 -0
- pytorch_model.bin +3 -0
NOTICE
ADDED
|
@@ -0,0 +1,64 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
MAPA
|
| 2 |
+
Copyright 2026 Ben Tang, Zachary Spalding, and Gregory B. Cogan
|
| 3 |
+
|
| 4 |
+
================================================================================
|
| 5 |
+
What each license covers
|
| 6 |
+
================================================================================
|
| 7 |
+
|
| 8 |
+
Source code and released model checkpoints are licensed under the Apache License,
|
| 9 |
+
Version 2.0. See LICENSE. The release attachment named LICENSE-WEIGHTS contains
|
| 10 |
+
the same Apache 2.0 license for standalone checkpoint downloads. The checkpoint
|
| 11 |
+
license covers:
|
| 12 |
+
|
| 13 |
+
mapa_vits384.pt
|
| 14 |
+
mapa_vits384_no_region.pt
|
| 15 |
+
mapa_vits384_no_relpos.pt
|
| 16 |
+
mapa_vits384_no_priors.pt
|
| 17 |
+
|
| 18 |
+
================================================================================
|
| 19 |
+
Attribution
|
| 20 |
+
================================================================================
|
| 21 |
+
|
| 22 |
+
The checkpoints were pretrained on the Brain Treebank dataset, released under
|
| 23 |
+
CC BY 4.0 at https://braintreebank.dev/. The dataset retains its own license.
|
| 24 |
+
Attribution for the pretraining data:
|
| 25 |
+
|
| 26 |
+
Christopher Wang, Adam Yaari, Aaditya K Singh, Vighnesh Subramaniam,
|
| 27 |
+
Dana Rosenfarb, Jan DeWitt, Pranav Misra, Joseph R Madsen, Scellig Stone,
|
| 28 |
+
Gabriel Kreiman, Boris Katz, Ignacio Cases, and Andrei Barbu.
|
| 29 |
+
Brain Treebank: Large-scale intracranial recordings from naturalistic
|
| 30 |
+
language stimuli. Advances in Neural Information Processing Systems 37
|
| 31 |
+
(NeurIPS 2024), Datasets and Benchmarks Track.
|
| 32 |
+
|
| 33 |
+
The evaluation follows Neuroprobe, https://github.com/insight-neuro/neuroprobe,
|
| 34 |
+
released under the MIT License, Copyright (c) 2025 Andrii Zahorodnii,
|
| 35 |
+
collaborators and contributors.
|
| 36 |
+
|
| 37 |
+
================================================================================
|
| 38 |
+
Vendored Neuroprobe material
|
| 39 |
+
================================================================================
|
| 40 |
+
|
| 41 |
+
mapa/data/_neuroprobe_lite_tables.py includes tables copied from Neuroprobe
|
| 42 |
+
commit c7b955b0a31464f4a5eec3f3bd78ff29841d61ac. The upstream license follows:
|
| 43 |
+
|
| 44 |
+
MIT License
|
| 45 |
+
|
| 46 |
+
Copyright (c) 2025 Andrii Zahorodnii, collaborators and contributors
|
| 47 |
+
|
| 48 |
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
| 49 |
+
of this software and associated documentation files (the "Software"), to deal
|
| 50 |
+
in the Software without restriction, including without limitation the rights
|
| 51 |
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
| 52 |
+
copies of the Software, and to permit persons to whom the Software is
|
| 53 |
+
furnished to do so, subject to the following conditions:
|
| 54 |
+
|
| 55 |
+
The above copyright notice and this permission notice shall be included in all
|
| 56 |
+
copies or substantial portions of the Software.
|
| 57 |
+
|
| 58 |
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
| 59 |
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
| 60 |
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
| 61 |
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
| 62 |
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
| 63 |
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
| 64 |
+
SOFTWARE.
|
README.md
ADDED
|
@@ -0,0 +1,72 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
---
|
| 2 |
+
license: apache-2.0
|
| 3 |
+
library_name: braindecode
|
| 4 |
+
tags:
|
| 5 |
+
- braindecode
|
| 6 |
+
- pytorch
|
| 7 |
+
- safetensors
|
| 8 |
+
- ieeg
|
| 9 |
+
- seeg
|
| 10 |
+
- mapa
|
| 11 |
+
---
|
| 12 |
+
|
| 13 |
+
# mapa-pretrained
|
| 14 |
+
|
| 15 |
+
Weights of the MAPA encoder `mapa_vits384` (d_model 384, 12 blocks, 21,335,424
|
| 16 |
+
parameters), for
|
| 17 |
+
[`braindecode.models.MAPA`](https://braindecode.org/stable/generated/braindecode.models.MAPA.html),
|
| 18 |
+
converted from the authors' release. The classification head is not pretrained (seeded random init); fine-tune or linear-probe before use.
|
| 19 |
+
|
| 20 |
+
```python
|
| 21 |
+
from braindecode.models import MAPA
|
| 22 |
+
model = MAPA.from_pretrained("braindecode/mapa-pretrained", n_outputs=2, chs_info=raw.info["chs"], regions=regions)
|
| 23 |
+
```
|
| 24 |
+
|
| 25 |
+
Channel names are read as clinical contact labels (`"LA7"` is contact 7 of
|
| 26 |
+
array `LA`); `regions` are DKT names from `braindecode.models.mapa.MAPA_DKT_REGIONS`.
|
| 27 |
+
The montage in `config.json` (4 channels, no regions) is only a default. Input is
|
| 28 |
+
expected at 2048 Hz, or as the session-normalized spectrogram with
|
| 29 |
+
`normalization="session"`, `sfreq=32`.
|
| 30 |
+
|
| 31 |
+
## Source and conversion
|
| 32 |
+
|
| 33 |
+
- Source: [bentang18/MAPA](https://huggingface.co/bentang18/MAPA) at revision
|
| 34 |
+
`988efbf31a7d1f38533b848c993a719d6f900b1f`, file `mapa_vits384.pt`
|
| 35 |
+
(sha256 `2d236089a2f1a3cc2827e3f150c4a2ba14c51bbfaf0ce0888f84b92a6eb25a7a`),
|
| 36 |
+
Apache-2.0. The authors' `NOTICE` is copied in this repository.
|
| 37 |
+
- `convert_mapa_checkpoint.py` (in this repository) renames the feed-forward
|
| 38 |
+
`encoder.blocks.{i}.mlp.fc1`/`fc2` to `mlp.0`/`mlp.3` (braindecode's
|
| 39 |
+
`FeedForwardBlock`), keeps every other key, and writes `config.json`,
|
| 40 |
+
`model.safetensors` and `pytorch_model.bin` with `save_pretrained`.
|
| 41 |
+
- The converted model's outputs equal braindecode's loading of the original
|
| 42 |
+
file (max-abs difference 0.0).
|
| 43 |
+
- Requires a braindecode version newer than 1.8.1.
|
| 44 |
+
- The ablation checkpoints (`no_region`, `no_relpos`, `no_priors`) are not
|
| 45 |
+
re-hosted; they remain at the source repository.
|
| 46 |
+
|
| 47 |
+
## Citation
|
| 48 |
+
|
| 49 |
+
```bibtex
|
| 50 |
+
@misc{tang2026pretraining,
|
| 51 |
+
title = {Pretraining for Sample-Efficient Neural Interfaces},
|
| 52 |
+
author = {Ben Tang and Zachary Spalding and Gregory B. Cogan},
|
| 53 |
+
year = {2026},
|
| 54 |
+
eprint = {2609.13507},
|
| 55 |
+
archivePrefix = {arXiv},
|
| 56 |
+
primaryClass = {cs.LG},
|
| 57 |
+
url = {https://arxiv.org/abs/2609.13507},
|
| 58 |
+
}
|
| 59 |
+
|
| 60 |
+
@article{aristimunha2025braindecode,
|
| 61 |
+
title = {Braindecode: a deep learning library for raw electrophysiological data},
|
| 62 |
+
author = {Aristimunha, Bruno and others},
|
| 63 |
+
journal = {Zenodo},
|
| 64 |
+
year = {2025},
|
| 65 |
+
doi = {10.5281/zenodo.17699192},
|
| 66 |
+
}
|
| 67 |
+
```
|
| 68 |
+
|
| 69 |
+
## License
|
| 70 |
+
|
| 71 |
+
Apache-2.0, as the original MAPA release. The checkpoint was pretrained on the
|
| 72 |
+
Brain Treebank dataset (CC BY 4.0, https://braintreebank.dev/); see `NOTICE`.
|
config.json
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"n_outputs": 2,
|
| 3 |
+
"n_chans": 4,
|
| 4 |
+
"chs_info": null,
|
| 5 |
+
"n_times": 2048,
|
| 6 |
+
"input_window_seconds": null,
|
| 7 |
+
"sfreq": 2048,
|
| 8 |
+
"contact_labels": null,
|
| 9 |
+
"regions": null,
|
| 10 |
+
"d_model": 384,
|
| 11 |
+
"mlp_ratio": 4,
|
| 12 |
+
"region_embed": true,
|
| 13 |
+
"space_rope": true,
|
| 14 |
+
"deep_sup": true,
|
| 15 |
+
"pooling": "mean",
|
| 16 |
+
"normalization": "window",
|
| 17 |
+
"activation": "torch.nn.modules.activation.GELU",
|
| 18 |
+
"braindecode_version": "1.8.1"
|
| 19 |
+
}
|
convert_mapa_checkpoint.py
ADDED
|
@@ -0,0 +1,58 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""Convert the released MAPA checkpoint to a braindecode-native file.
|
| 2 |
+
|
| 3 |
+
Source: https://huggingface.co/bentang18/MAPA at revision
|
| 4 |
+
988efbf31a7d1f38533b848c993a719d6f900b1f (Apache-2.0), file ``mapa_vits384.pt``
|
| 5 |
+
(sha256 2d236089a2f1a3cc2827e3f150c4a2ba14c51bbfaf0ce0888f84b92a6eb25a7a).
|
| 6 |
+
|
| 7 |
+
Usage::
|
| 8 |
+
|
| 9 |
+
python convert_mapa_checkpoint.py OUT_DIR [SOURCE_FILE]
|
| 10 |
+
|
| 11 |
+
writes ``OUT_DIR/mapa-pretrained`` with ``config.json``, ``model.safetensors``
|
| 12 |
+
and ``pytorch_model.bin`` (``save_pretrained``). Without ``SOURCE_FILE`` the
|
| 13 |
+
file is downloaded.
|
| 14 |
+
|
| 15 |
+
Key changes: the feed-forward ``encoder.blocks.{i}.mlp.fc1``/``fc2`` become the
|
| 16 |
+
``FeedForwardBlock`` children ``mlp.0``/``mlp.3``; every other key is kept. The
|
| 17 |
+
classification head ``final_layer`` is not pretrained: it is a seeded random
|
| 18 |
+
``nn.Linear`` default init. The stored montage (4 channels, no labels or
|
| 19 |
+
regions) is only a default; pass ``chs_info`` or ``n_chans``, and
|
| 20 |
+
``contact_labels`` and ``regions``, to ``from_pretrained``.
|
| 21 |
+
"""
|
| 22 |
+
|
| 23 |
+
import hashlib
|
| 24 |
+
import sys
|
| 25 |
+
from pathlib import Path
|
| 26 |
+
|
| 27 |
+
import torch
|
| 28 |
+
|
| 29 |
+
from braindecode.models import MAPA
|
| 30 |
+
|
| 31 |
+
REPO, REVISION = "bentang18/MAPA", "988efbf31a7d1f38533b848c993a719d6f900b1f"
|
| 32 |
+
FILENAME = "mapa_vits384.pt"
|
| 33 |
+
SHA256 = "2d236089a2f1a3cc2827e3f150c4a2ba14c51bbfaf0ce0888f84b92a6eb25a7a"
|
| 34 |
+
|
| 35 |
+
|
| 36 |
+
def convert(source, out):
|
| 37 |
+
if source is None:
|
| 38 |
+
from huggingface_hub import hf_hub_download
|
| 39 |
+
|
| 40 |
+
source = hf_hub_download(REPO, FILENAME, revision=REVISION)
|
| 41 |
+
assert hashlib.sha256(Path(source).read_bytes()).hexdigest() == SHA256
|
| 42 |
+
released = torch.load(source, map_location="cpu", weights_only=True)["model"]
|
| 43 |
+
state = {
|
| 44 |
+
key.replace(".mlp.fc1.", ".mlp.0.").replace(".mlp.fc2.", ".mlp.3."): value
|
| 45 |
+
for key, value in released.items()
|
| 46 |
+
}
|
| 47 |
+
torch.manual_seed(0) # the head is a seeded random init
|
| 48 |
+
model = MAPA(n_outputs=2, n_chans=4, n_times=2048, sfreq=2048)
|
| 49 |
+
state.update(
|
| 50 |
+
{k: v for k, v in model.state_dict().items() if k.startswith("final_layer.")}
|
| 51 |
+
)
|
| 52 |
+
model.load_state_dict(state, strict=True)
|
| 53 |
+
model.save_pretrained(out)
|
| 54 |
+
return model
|
| 55 |
+
|
| 56 |
+
|
| 57 |
+
if __name__ == "__main__":
|
| 58 |
+
convert(sys.argv[2] if len(sys.argv) > 2 else None, Path(sys.argv[1]) / "mapa-pretrained")
|
model.safetensors
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:ed0626c405ef0b9f1759525ea67e18c45d8943d548e28bcfd0fb6679ae263611
|
| 3 |
+
size 85369608
|
pytorch_model.bin
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:f8dfe964f048b7fdc54be199403d01349a626a80df3b29bba6a2773a824bcc35
|
| 3 |
+
size 85411883
|