--- license: mit library_name: transformer-lens tags: [mechanistic-interpretability, induction-heads, toy-model, transformer-circuits, visualization] --- # transformer-visualized: tiny 2-layer transformers (trained, hand-crafted, controls) Weights for **[transformer-visualized](https://github.com/BurnyCoder/transformer-visualized)**, an interactive, animated visualization of a two-layer transformer (live site: https://burnycoder.github.io/transformer-visualized/; paper: https://github.com/BurnyCoder/transformer-visualized/blob/main/reports/paper.pdf). Every run of the study is here under `runs//`: the preregistered runs, the preregistration-addendum-1 control runs (`ind_spans*`, `gram_*`), the sensitivity runs (`sens_*`) and the pilot runs (`pilot_*`). - `final.safetensors`: final weights (TransformerLens 3.9.0 `HookedTransformer` names; biases are zero and omitted) - `checkpoints/step_*.safetensors`: 38 log-spaced training checkpoints (40 requested; steps that coincide after rounding are kept once) - `config.json`: architecture and training spec - `metrics.jsonl`: validation metrics logged during training - `eval_val.json` / `eval_test.json`: full evaluation on the grammar (losses with bootstrap CIs, G, head scores, circuits, ablations); `eval_meta.json` records the device of evaluations re-run on the CPU - `eval_induction.json`: textbook-circuit measurements on held-out repeated random spans (addendum 1) **Architecture.** 2 layers, 2 heads × 8 dims, ReLU MLP of width 64, d_model = 32, n_ctx = 24, vocabulary of 26 tokens (24 words, the full stop and ``); no LayerNorm, zero biases (the analytical simplifications of *A Mathematical Framework for Transformer Circuits*, built into the model). Other runs differ as recorded in their `config.json`. **Data.** A toy word grammar (exact bigram chain) in which each later sentence repeats an earlier one with probability 0.5. The splits are in the companion dataset repo. **Key results (test set).** Gain fraction G (share of the achievable in-context gain; 0 = bigram oracle, 1 = Bayes-optimal): main 2-layer model 0.981 [0.971, 0.990] over 5 seeds; 1-word induction oracle 0.869; hand-crafted 0.853 [0.851, 0.855]. The hand-crafted model implements the textbook previous-token → induction circuit; the trained models mostly do not on the grammar (H1 falsified, H4 falsified), but the same architecture forms it on repeated random spans in 4/5 seeds (addendum A1 supported). Two independent audits (CPU only) recomputed every decision from these weights: `reports/reviews/review-3.md` and `reports/reviews/review-4.md` of the code repository. **Load.** ```python from transformer_lens import HookedTransformer, HookedTransformerConfig from safetensors.torch import load_file cfg = HookedTransformerConfig(n_layers=2, d_model=32, n_ctx=24, d_head=8, n_heads=2, d_mlp=64, d_vocab=26, act_fn="relu", normalization_type=None) model = HookedTransformer(cfg) model.load_state_dict(load_file("runs/main_s0/final.safetensors"), strict=False) # biases stay zero ``` Token ids: see `src/tfviz/grammar.py` in the code repository (0 = ``, 1 = `.`). Author: Libor "Burny" Burian. License: MIT.