Editing
Mechanistic Interp
(section)
Jump to navigation
Jump to search
Warning:
You are not logged in. Your IP address will be publicly visible if you make any edits. If you
log in
or
create an account
, your edits will be attributed to your username, along with other benefits.
Anti-spam check. Do
not
fill this in!
== <span style="color: #FFFFFF;">Applying</span> == '''Using TransformerLens for mechanistic analysis:''' <syntaxhighlight lang="python"> import transformer_lens from transformer_lens import HookedTransformer import torch # Load a model with interpretability hooks model = HookedTransformer.from_pretrained("gpt2-small") model.eval() # Logit lens: see how model prediction evolves through layers prompt = "The Eiffel Tower is located in" tokens = model.to_tokens(prompt) logits, cache = model.run_with_cache(tokens) # Project each layer's residual stream to vocabulary def logit_lens(cache, model, layer_idx): resid = cache["resid_post", layer_idx] # (1, seq_len, d_model) logits = model.unembed(model.ln_final(resid)) # (1, seq_len, vocab) top_tokens = logits[0, -1].topk(5) return [(model.to_string([t]), p.item()) for t, p in zip(top_tokens.indices, top_tokens.values.softmax(0))] for layer in range(12): print(f"Layer {layer}: {logit_lens(cache, model, layer)}") # Activation patching: find which components are responsible for a fact def patch_head(hook, stored_act): return stored_act # Replace with stored activation from different run # Run model on "clean" prompt, save activations # Run model on "corrupted" prompt (patched entity) # Systematically patch each head's output; find which patching "restores" correct answer </syntaxhighlight> ; Mechanistic interpretability tools : '''TransformerLens''' β Python library for GPT-style model analysis (Neel Nanda) : '''BauKit''' β David Bau's toolkit for network dissection and causal tracing : '''ROME/MEMIT''' β Locate and edit factual associations in transformer MLP layers : '''Sparse Autoencoders''' β Anthropic, EleutherAI β decompose polysemantic activations : '''Probing classifiers''' β Linear probes on activations to identify encoded concepts </div> <div style="background-color: #8B4500; color: #FFFFFF; padding: 20px; border-radius: 8px; margin-bottom: 15px;">
Summary:
Please note that all contributions to BloomWiki may be edited, altered, or removed by other contributors. If you do not want your writing to be edited mercilessly, then do not submit it here.
You are also promising us that you wrote this yourself, or copied it from a public domain or similar free resource (see
BloomWiki:Copyrights
for details).
Do not submit copyrighted work without permission!
Cancel
Editing help
(opens in new window)
Navigation menu
Personal tools
Not logged in
Talk
Contributions
Create account
Log in
Namespaces
Page
Discussion
English
Views
Read
Edit
View history
More
Search
Navigation
Main page
Recent changes
Random page
Help about MediaWiki
Tools
What links here
Related changes
Special pages
Page information