payman21 commited on
Commit
e66b661
·
verified ·
1 Parent(s): b93caed

Upload folder using huggingface_hub

Browse files
Files changed (2) hide show
  1. README.md +105 -0
  2. sae.pt +3 -0
README.md ADDED
@@ -0,0 +1,105 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ---
2
+ license: mit
3
+ tags:
4
+ - fmri
5
+ - neuroscience
6
+ - sparse-autoencoder
7
+ - interpretability
8
+ - brainlm
9
+ ---
10
+
11
+ # BatchTopK sparse autoencoder over BrainLM token activations
12
+
13
+ The trained sparse dictionary used in *Interpretability nominates a testable
14
+ hypothesis from an fMRI foundation model: a proof of concept with sparse-feature
15
+ attribution* (Payman Roghani, Interpretability for Discovery workshop, NeurIPS
16
+ 2026).
17
+
18
+ It is fitted to final-layer token activations of the BrainLM `old_13M` encoder
19
+ (a masked autoencoder pretrained on resting-state fMRI), applied frozen to the
20
+ Human Connectome Project Young Adult cohort. The paper decomposes the model's
21
+ own prediction of fluid intelligence over this dictionary in closed form.
22
+
23
+ ## Specification
24
+
25
+ | | |
26
+ |---|---|
27
+ | Architecture | BatchTopK sparse autoencoder |
28
+ | Input dimension | 512 (BrainLM `old_13M` final-layer token activation) |
29
+ | Dictionary width | 4,096 |
30
+ | Sparsity `k` | 32 |
31
+ | Alive features | 3,781 of 4,096 |
32
+ | Training activations | 499,000 tokens |
33
+ | Epochs | 30 |
34
+ | Validation FVU | 0.081 |
35
+
36
+ **Fitted on the training split only** — 656 of 936 subjects. The 280-subject
37
+ holdout was drawn before any interpretability step and the dictionary never saw
38
+ it. This matters: an SAE fitted on the full cohort has seen the holdout, and any
39
+ attribution built on it inherits that contact.
40
+
41
+ ## Contents
42
+
43
+ `sae.pt` is a `torch.save` dictionary:
44
+
45
+ | Key | Type | Meaning |
46
+ |---|---|---|
47
+ | `state_dict` | `OrderedDict` | encoder/decoder weights and `b_pre` |
48
+ | `width` | `int` | 4096 |
49
+ | `k` | `int` | 32 |
50
+ | `mu` | `np.ndarray (1, 512)` | activation mean, subtracted before encoding |
51
+ | `scale` | `float` | activation scale, divided before encoding |
52
+ | `thresh` | `float` | BatchTopK threshold, frozen over the whole training matrix |
53
+
54
+ `thresh` is stored deliberately. BatchTopK's cut is otherwise a property of
55
+ whichever batch `encode()` was handed, so an SAE re-run on new data in different
56
+ batches will not reproduce its own training-time activations. Use the stored
57
+ value rather than recomputing per batch.
58
+
59
+ ## Loading
60
+
61
+ `mu` is a NumPy array, so on PyTorch 2.6 and later — where `torch.load` defaults
62
+ to `weights_only=True` — the default call raises `UnpicklingError`. Either:
63
+
64
+ ```python
65
+ import torch
66
+
67
+ ckpt = torch.load("sae.pt", map_location="cpu", weights_only=False)
68
+ print(ckpt["width"], ckpt["k"], ckpt["thresh"])
69
+
70
+ # Activations are normalised with the stored constants before encoding:
71
+ # x_norm = (x - ckpt["mu"]) / ckpt["scale"]
72
+ ```
73
+
74
+ or, to keep the safe loader, allowlist the NumPy reconstructors:
75
+
76
+ ```python
77
+ import numpy as np, torch
78
+
79
+ with torch.serialization.safe_globals(
80
+ [np._core.multiarray._reconstruct, np.ndarray, np.dtype, np.dtypes.Float32DType]
81
+ ):
82
+ ckpt = torch.load("sae.pt", map_location="cpu")
83
+ ```
84
+
85
+ On PyTorch below 2.6 the plain `torch.load("sae.pt", map_location="cpu")` works
86
+ as written.
87
+
88
+ The model class and the encode path are in `src/04_interpretability/train_sae_hcp.py`
89
+ in the code repository below.
90
+
91
+ ## Code
92
+
93
+ Analysis code and the aggregate result tables:
94
+ <https://github.com/payman21/brainlm-interpretability>
95
+
96
+ ## What is not here
97
+
98
+ Subject-level activation matrices are not redistributed. They are regenerable
99
+ from the released code given access to HCP-YA, which is available from the
100
+ open-access tier under the WU-Minn HCP Open Access Data Use Terms.
101
+
102
+ ## Contact
103
+
104
+ Payman Roghani, Center for Brain and Cognition, Computational Neuroscience Group,
105
+ Universitat Pompeu Fabra, Barcelona (proghani@gmail.com).
sae.pt ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:e37fbf523d4d57c04fd6ef0ff42808358712796e4a41c8c3ddf9c359618f693a
3
+ size 16801205