File size: 9,826 Bytes
bab5617
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
---
license: apache-2.0
pretty_name: CSP-Atlas
size_categories:
  - 100K<n<1M
tags:
  - mechanistic-interpretability
  - code
  - python
  - sparse-transformer
  - circuits
  - concept-extraction
language:
  - code
---

# CSP-Atlas: Concept-Specific Neural Circuits in a Sparse Python Transformer

Frozen experimental artifacts for the paper *CSP-Atlas: Concept-Specific Neural Circuits in a Sparse Python Transformer* (Wilam, 2026). This repository holds the prompts, masks, and decomposition tables that the paper's figures and numbers are computed from; the model itself is `openai/circuit-sparsity` on the Hub.

- **Paper code:** <https://github.com/piotrwilam/AtlasCSP>
- **Model used:** [`openai/circuit-sparsity`](https://huggingface.co/openai/circuit-sparsity) — 8-layer sparse Python transformer, 2,048-dim MLP output per layer.
- **Concept space:** 106 Python concepts = 43 AST node types + 63 builtin objects.
- **Prompts:** 63,800 object prompts (1,276 pairs × 50 variations) + 2,848 checker + 2,861 token-checker.
- **Parameter sweep:** ε ∈ {0.001, 0.1, 0.5} × C ∈ {20%, 50%, 80%} = 9 settings.

All claims in the paper regenerate from these files via the released code (`pytest tests/test_paper_numbers.py`).

## Layout

```
CSP-Atlas/
├── 11A_object_prompts.parquet          # 63,800 object prompts (the (AST × builtin) × 50 grid)
├── 11B_checker_prompts.parquet         # 2,848 checker prompts (keyword present, concept absent)
├── token_checker_prompts.parquet       # 2,861 token-checker prompts (broader set, all keyword contexts)

├── 12_object_activations.h5            # Raw MLP-output activations, object prompts (optional — derivable)
├── 12_checker_activations.h5           # Raw MLP-output activations, checker prompts (optional)

├── 13_object_masks_eps{ε}_cons{C}.h5   # 9 files — binarised + marginalised universal masks per (ε, C)
├── 13_checker_masks_eps{ε}_cons{C}.h5  # 9 files — binarised checker masks per (ε, C)
├── token_checker_masks.h5              # Token-checker masks (single setting: ε=0.5, C=0.8)

├── 14_summary.csv                              # 9 rows — global concept/token fractions per (ε, C)
├── 14_target_checker_eps{ε}_cons{C}.csv        # 9 files — per-object × per-layer "co / sh / to" decomposition

├── relaxed_modularity_scores.csv       # §6.1 — significant-layer count per concept × trim level p ∈ {0, 0.05, 0.1, 0.25}
├── relaxed_modularity_detail.csv       # §6.1 — full per-layer Jaccard trim-mean values

├── token_independence_summary.csv      # Per-object: concept_fraction, token_fraction, A_size, A∩B, A\B, B\A
├── token_independence_detail.csv       # Per-object × per-layer breakdown
└── token_independence_no_keyword.csv   # The 48 tokenless concepts (no checker confound applies)
```

## File schemas

### HDF5 mask files (`13_*.h5`, `token_checker_masks.h5`, `universal_106x50.h5`)

Layer-major group layout. Datasets are boolean vectors of length 2,048 (one bit per MLP-output dimension):

```
/metadata
    .attrs: {epsilon, consistency_thresh, n_layers=8, n_pairs=1276}
    /ast_nodes        — array of 43 AST node names
    /builtin_objs     — array of 63 builtin object names
/universal_masks
    /layer_0/{concept_name}      — (2048,) bool
    /layer_1/{concept_name}      — (2048,) bool

    /layer_7/{concept_name}      — (2048,) bool
/pair_masks
    /layer_0/{ast}__{builtin}    — (2048,) bool    (e.g. AnnAssign__abs)

/metrics
    aggregate statistics per layer (sizes, intersection counts)
```

Concept names use the convention `ast__<NodeType>` or `builtin__<object>` (double underscore).

### Prompt parquets

`11A_object_prompts.parquet` (63,800 rows):

| column | type | meaning |
|---|---|---|
| `ast_node` | str | AST node type (e.g. `For`) |
| `builtin_obj` | str | Builtin name (e.g. `bytearray`) |
| `variation_id` | int | 0..49 (50 variations per pair) |
| `prompt_text` | str | The Python snippet |
| `sequence_loss` | float | Model's per-token loss on the snippet (used for filtering) |
| `token_length` | int | Tokenizer output length |
| `ast_verified` | bool | True if `ast.parse()` round-trips with the target node present |

`11B_checker_prompts.parquet` (2,848 rows) and `token_checker_prompts.parquet` (2,861 rows):

| column | type | meaning |
|---|---|---|
| `object` | str | Target concept (e.g. `ast__Break`) |
| `keyword` | str | The bare token under test (e.g. `break`) |
| `variation_id` | int | 0..49 |
| `prompt_text` | str | Python that contains the keyword but excludes the concept (string literal, comment, var name, …) |

### Decomposition CSVs (`14_target_checker_*.csv`)

One row per testable concept (58 of them), 8 layer columns (`L0`–`L7`). Each cell encodes the three-way decomposition as a string:

```
co / sh / to
```

— concept-only `|A \ B|`, shared `|A ∩ B|`, token-only `|B \ A|`. From these the concept fraction `co / (co + sh)` is recovered.

### Global summary (`14_summary.csv`)

One row per (ε, C) setting. Columns: `epsilon, consistency, n_testable, n_ast, n_builtin, mean_concept_fraction, mean_token_fraction, ast_concept_fraction, ast_token_fraction, blt_concept_fraction, blt_token_fraction, mean_A_size, mean_B_size`.

### Modularity (`relaxed_modularity_scores.csv`)

| column | meaning |
|---|---|
| (index) | concept name |
| `type` | `ast` or `builtin` |
| `p=0.0`, `p=0.05`, `p=0.1`, `p=0.25` | Number of layers (0–8) at which the concept's mean Jaccard to its k-nearest-neighbour shell, trimmed at trim level p, exceeds the permutation null at significance 0.05. The paper's §6.1 Break-at-top result is `p=0.0 == 3`. |

`relaxed_modularity_detail.csv` is the un-aggregated per-layer per-trim-level Jaccard means feeding the score table.

### Token-independence (`token_independence_*.csv`)

`summary.csv` is one row per testable object: `object, type, keyword, concept_fraction, token_fraction, A_size, A_and_B, A_only, B_only` (averaged across layers).

`detail.csv` breaks the same statistics out by `(object, layer)`.

`no_keyword.csv` is the 48 concepts (19 tokenless AST + 29 tokenless builtins) for which no checker confound applies — included so downstream users can see the full 106-concept universe.

## Quickstart

The dataset is normally accessed through the [AtlasCSP code repository](https://github.com/piotrwilam/AtlasCSP), which contains loaders that auto-download missing files from this Hub mirror:

```python
from csp_atlas.io import (
    load_universal_masks,        # 13_object_masks_*.h5
    load_pair_masks,             # 13_object_masks_*.h5
    load_concept_inventory,      # the 43 + 63 names
    load_summary,                # 14_summary.csv
    load_target_checker,         # 14_target_checker_*.csv
    load_modularity_scores,      # relaxed_modularity_scores.csv
    load_prompts,                # 11A / 11B / token_checker
)

# Universal mask set at the paper's reference setting:
masks = load_universal_masks(eps=0.5, cons=0.8)        # dict[concept] -> dict[layer] -> set[int]
ast, builtin = load_concept_inventory(eps=0.5, cons=0.8)  # 43, 63
prompts = load_prompts(kind="object")                  # the 63,800-row DataFrame
```

Direct download with `huggingface_hub`:

```python
from huggingface_hub import hf_hub_download
path = hf_hub_download(
    repo_id="piotrwilam/CSP-Atlas",
    filename="13_object_masks_eps0.5_cons0.8.h5",
    repo_type="dataset",
)
```

Or with `datasets` (parquets only):

```python
from datasets import load_dataset
ds = load_dataset("piotrwilam/CSP-Atlas", data_files="11A_object_prompts.parquet")
```

## Reproducing the paper

The paper's claims are locked in `tests/test_paper_numbers.py` in the code repo. With the dataset in place at `$CSP_ATLAS_DATA_ROOT` (or the default local mirror) and a uv venv:

```bash
git clone https://github.com/piotrwilam/AtlasCSP
cd AtlasCSP
uv sync
export CSP_ATLAS_DATA_ROOT=/path/to/CSP-Atlas
pytest tests/test_paper_numbers.py -v
python experiments/fig1_atomicity_dendrogram.py
```

The single dendrogram figure (Figure 1) is produced by `experiments/fig1_atomicity_dendrogram.py`, driven by `configs/paper/figure1_atomicity_dendrogram.yaml`.

## Generation pipeline

The four-stage extraction (`11_``12_``13_``14_`) is documented in [`circuits/README.md`](https://github.com/piotrwilam/AtlasCSP/blob/main/circuits/README.md) in the code repo:

| Stage | Step | Output |
|---|---|---|
| 11 | Prompt generation (`circuits/prompts/`) | `11A`, `11B`, `token_checker` parquets |
| 12 | Forward-pass extraction (`circuits/extraction/`) | `12_*_activations.h5` (last-token MLP outputs, 8 layers) |
| 13 | Binarisation + marginalisation | `13_object_masks_*.h5`, `13_checker_masks_*.h5` per (ε, C) |
| 14 | Decomposition vs checker masks | `14_summary.csv`, `14_target_checker_*.csv` |

The `relaxed_modularity_*.csv` and `token_independence_*.csv` are downstream analyses computed on stage 13/14 outputs.

## What is *not* in this repo

- **Model weights**`openai/circuit-sparsity` is loaded from its own Hub repo at runtime; not duplicated here.
- **Pre-paper development snapshots** — checkpoints/, earlier 115-concept experiments, exploratory runs.
- **Figure PDFs** — the figure files for the paper live in the AtlasCSP code repo under `results/`.

## Citation

```bibtex
@article{Wilam2026CSPAtlas,
  title   = {CSP-Atlas: Concept-Specific Neural Circuits in a Sparse Python Transformer},
  author  = {Wilam, Piotr},
  year    = {2026},
  url     = {https://github.com/piotrwilam/AtlasCSP}
}
```

## License

Apache-2.0 — see `LICENSE`. The model `openai/circuit-sparsity` is distributed under its own licence on its own Hub repo and is not redistributed here.