transformer-visualized: tiny 2-layer transformers (trained, hand-crafted, controls)
Weights for transformer-visualized, an interactive, animated visualization of a two-layer
transformer (live site: https://burnycoder.github.io/transformer-visualized/). Every run of the preregistered study is here under runs/<run_id>/:
final.safetensors: final weights (TransformerLens 3.9.0HookedTransformernames; biases are zero and omitted)checkpoints/step_*.safetensors: ~40 log-spaced training checkpointsconfig.json: architecture and training specmetrics.jsonl: validation metrics logged during trainingeval_val.json/eval_test.json: full evaluation (losses with bootstrap CIs, G, head scores, circuits, ablations)
Architecture. 2 layers, 2 heads ร 8 dims, ReLU MLP of width 64, d_model = 32, n_ctx = 24, vocabulary of 26 words; no LayerNorm, zero biases (the simplifications of A Mathematical Framework for Transformer Circuits).
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; hand-crafted 0.853 [0.851, 0.855].
Load.
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 = <bos>, 1 = .).
Author: Libor "Burny" Burian. License: MIT.