How does Mechanistic Interpretability work?
- Authors
- Name
- Amit Shekhar
- Published on
Mechanistic Interpretability is the study of opening up a trained neural network and finding out, step by step, how it turns its input into its output. It tries to understand the actual parts and connections inside the model.
In this blog, we will learn about how Mechanistic Interpretability works. We will also see why a neural network is called a black box, what features and circuits mean, why one neuron often does many jobs, how sparse autoencoders pull ideas apart, how researchers test their guesses by changing the insides of a model, and where this field works well and where it still fails.
We will cover the following:
- What is a neural network?
- The black box problem
- What is Mechanistic Interpretability?
- Features: the ideas inside the model
- Circuits: how features connect
- The problem: one neuron, many jobs
- Superposition: why it happens
- Sparse Autoencoders: pulling ideas apart
- Testing our guesses with interventions
- A real example: induction heads
- The full workflow
- Where it works well and where it fails
I am Amit Shekhar, Founder @ Outcome School, I have taught and mentored many developers, and their efforts landed them high-paying tech jobs, helped many tech companies in solving their unique problems, and created many open-source libraries being used by top companies. I am passionate about sharing knowledge through open-source, blogs, and videos.
I teach AI and Machine Learning at Outcome School.
Let's get started.
What is a neural network?
Before jumping into Mechanistic Interpretability, we must know what a neural network is, because that is the thing we are trying to understand.
A neural network is a model that learns from examples instead of being written rule by rule.
It is made of many small units called neurons. A neuron is a tiny calculator. It takes some numbers in, multiplies them by some other numbers, adds them up, and passes a number out.
The numbers that a neuron multiplies with are called weights. During training, the network keeps updating these weights until it starts giving good answers.
The number that a neuron passes out at any moment is called its activation. Means, the activation tells us how strongly that neuron "fired" for the current input.
Neurons are arranged in layers. The input goes into the first layer, the result goes to the next layer, and so on, till the last layer gives the final answer.
+--------------------------------------+
| Input |
+--------------------------------------+
↓
+--------------------------------------+
| Layer 1: neurons produce activations |
+--------------------------------------+
↓
+--------------------------------------+
| Layer 2: neurons produce activations |
+--------------------------------------+
↓
+--------------------------------------+
| Layer 3: neurons produce activations |
+--------------------------------------+
↓
+--------------------------------------+
| Output |
+--------------------------------------+
Here, we can see that the input flows through the layers one after another. At each layer, every neuron produces an activation, and those activations become the input for the next layer.
An LLM (Large Language Model) is a very big neural network that reads text and predicts the next token. It has billions of weights.
If we want to go deep into Neural Networks and Feed Forward Neural Networks (FFNNs), and even build a Large Language Model (LLM) from scratch, check out our AI and Machine Learning Program at Outcome School.
Now, let's understand the problem.
The black box problem
Let's say we ask an LLM, "The capital of France is", and it answers "Paris".
We know the input. We know the output. But what happened in between?
Inside, billions of multiplications took place. If we print the activations, we see huge lists of numbers like 0.42, -1.3, 0.07, 2.1, .... These numbers do not come with labels. Nobody wrote "this number means France".
This is why a neural network is called a black box. We can see what goes in and what comes out, but we cannot see the reasoning inside.
This creates real problems:
- We cannot be sure why the model gave an answer.
- We cannot easily find out if the model learned a wrong shortcut.
- We cannot check if the model is hiding something harmful inside.
- We cannot fix a specific bad behavior without guessing.
So, here comes Mechanistic Interpretability to the rescue.
What is Mechanistic Interpretability?
Mechanistic Interpretability is the work of reverse engineering a trained neural network into parts that humans can understand.
Here, mechanistic means "about the mechanism", which means the actual moving parts and how they work together. So, it explains a model by understanding its inner mechanism, not just by looking at its inputs and outputs.
The best way to learn this is by taking an example.
Suppose someone gives us a compiled app, but not its source code. We can run it and see what it does. But if we want to know exactly how it works, we decompile it and read the logic line by line.
Mechanistic Interpretability does the same for a neural network. The weights are like the compiled app. The researcher tries to recover the "source code" in human terms, like "this part detects French words" and "this part copies a name from earlier in the sentence".
Many other methods only tell us which input words were important for the answer. Mechanistic Interpretability wants the whole path inside, from input to result. We have a detailed blog on Explainable AI (XAI) that covers those other methods.
Now, let's understand the two main building blocks it looks for: features and circuits.
Features: the ideas inside the model
A feature is an idea or pattern that the model has learned to recognize and represent inside its activations.
For example, a model can have features like:
- "this text is in French"
- "this is a number"
- "this is inside Python code"
- "this is about the Golden Gate Bridge"
- "the sentence is sad"
When the input contains that idea, the feature becomes active. When it does not, the feature stays quiet.
Mathematically, a feature is usually treated as a direction in the space of activations. Let's say a layer has only 3 neurons. Its activation is a list of 3 numbers like [0.9, 0.1, 0.4]. A feature is a fixed recipe like "a lot of neuron 1, a little of neuron 3". The more the current activation matches that recipe, the stronger the feature is.
Layer activation: [0.9, 0.1, 0.4]
"French" recipe: [1.0, 0.0, 0.5]
Match score = 0.9*1.0 + 0.1*0.0 + 0.4*0.5 = 1.1 --> "French" is strongly active
Here, we multiply each number with the matching number in the recipe and add them up. A high score means the feature is present. This matching is called a dot product, and it is how researchers read how strong a feature is.
Planning your move into AI?
No matter which tech domain you work in today, with your effort, you can transition to these roles:
- AI Engineer
- Forward Deployed Engineer
- AI Agent Engineer
- Harness Engineer
- Voice AI Engineer
- AI Architect
- LLM Engineer
- LLM Inference Engineer
- Gen AI Engineer
- MLOps Engineer
- ML Engineer
- Deep Learning Engineer
Our AI and Machine Learning Program at Outcome School takes you there.
Circuits: how features connect
Now, let's move to circuits. Features alone do not explain behavior. We also need to know how features in one layer use features from an earlier layer.
A circuit is a small group of features and the connections between them that together perform one specific job.
Let's take a simple example from image models. Researchers found:
- Early layers have features that detect simple edges and curves.
- Middle layers combine curves into features like "circle" or "fur texture".
- Later layers combine those into features like "dog's head".
curve detectors ----+
+--> "circle" ----+
edge detectors -----+ +--> "dog's head"
|
fur texture --------------------------+
Here, each arrow is a set of weights that connects one feature to the next. When we can name the features and explain why the weights connect them, we have understood a circuit.
This is like reading a small function in the decompiled code. One function detects circles. Another uses circles and fur to detect a dog's head.
Now, the question is, if features are inside the neurons, why can we not just look at each neuron and give it a name?
The problem: one neuron, many jobs
The early hope was simple: one neuron equals one idea. Then we can just label every neuron.
When researchers looked at what makes a single neuron fire, they often found a mix of unrelated things. For example, in an image model, one neuron fired for cat faces, for the front of cars, and for cat legs. These neurons are called polysemantic neurons, which means "having many meanings".
A neuron that fires for just one clean idea is called monosemantic, which means "one meaning".
Most neurons in big language models are polysemantic. So, looking at neurons one by one gives us a confusing picture. We need to understand why this happens.
Superposition: why it happens
The reason is called superposition.
Superposition means the model stores more features than it has neurons, by spreading each feature across many neurons and letting them overlap.
Let's say a layer has only 1,000 neurons, but the model wants to remember 50,000 different ideas. There is not enough room to give each idea its own neuron.
So, the model gives each idea its own direction, which means its own mix of neurons, and these directions overlap a little.
This works because most ideas are rare. In any one sentence, only a few ideas are present at the same time. Text about the Golden Gate Bridge is almost never also text about Python code and French cooking. Since they rarely appear together, sharing neurons causes very little confusion.
Think of a small office with 10 desks and 40 part-time workers. Each worker comes in only on a few days. As long as not too many come on the same day, they share desks without problems. But if we look at a single desk, we see many different people using it. That desk is "polysemantic".
The researchers at Anthropic showed this clearly in a 2022 paper called "Toy Models of Superposition", where tiny networks trained on rare features learned to pack more features than neurons.
Hence, the ideas are real, but they are hidden in directions that do not line up with single neurons. We need a tool to pull them apart.
Sparse Autoencoders: pulling ideas apart
So, here comes the Sparse Autoencoder into the picture.
A Sparse Autoencoder (SAE) is a small helper network that we train to rewrite the model's activations as a combination of a few clean features.
Let's break the name:
- Autoencoder is a network that takes an input, converts it into another form, and then tries to rebuild the original input from that form.
- Sparse means "mostly zeros". For each input, only a few features are allowed to be active.
The idea is as below:
+-----------------------------+
| Model activation |
| (1,000 numbers) |
+-----------------------------+
↓
Encoder
↓
+-----------------------------+
| Sparse features |
| (50,000 numbers, |
| only about 20 non-zero) |
+-----------------------------+
↓
Decoder
↓
+-----------------------------+
| Rebuilt activation |
| (1,000 numbers) |
+-----------------------------+
Here, the encoder takes the activation from one layer of the model and spreads it into a much bigger list of features. The decoder tries to rebuild the original activation from those features.
We train the SAE with two goals at once:
- The rebuilt activation must be close to the original one.
- Very few features must be active at a time.
So, the SAE is forced to explain each activation using only a handful of features. So, it learns to give each feature a single, clean meaning. Means, the overlapping ideas get separated.
Let's see a minimal version of an SAE in PyTorch as below:
import torch
import torch.nn as nn
class SparseAutoencoder(nn.Module):
def __init__(self, d_model, d_features):
super().__init__()
self.encoder = nn.Linear(d_model, d_features)
self.decoder = nn.Linear(d_features, d_model)
def forward(self, x):
features = torch.relu(self.encoder(x)) # only positive values survive
rebuilt = self.decoder(features)
return rebuilt, features
def sae_loss(x, rebuilt, features, sparsity_weight=1e-3):
rebuild_error = ((x - rebuilt) ** 2).mean() # how far from the original
sparsity = features.abs().sum(dim=-1).mean() # pushes most features to zero
return rebuild_error + sparsity_weight * sparsity
Here, we have:
d_modelis the size of the model's activation, for example 1,000.d_featuresis the number of features we want to find, for example 50,000. It is much bigger thand_model.encoderturns the activation into feature strengths, andrelusets negative values to zero.decoderrebuilds the activation from the features. Each column of the decoder is the direction of one feature.rebuild_errorchecks how close the rebuilt activation is to the original.sparsityadds up the feature strengths. Keeping it small forces most features to be exactly zero.
After training, we take each feature and look at the text where it fires the strongest. If a feature fires on "Golden Gate Bridge", "the bridge in San Francisco", and pictures of that bridge, we can label it as the Golden Gate Bridge feature.
This is exactly what Anthropic did in its 2024 work "Scaling Monosemanticity" on the Claude 3 Sonnet model. They found millions of features, including ones for cities, code bugs, famous people, and even abstract ideas like secrecy or flattery.
This is how sparse autoencoders turn a long list of unlabeled numbers into readable features.
A quick note for you
No matter which tech domain you work in, get familiar with these topics:
- LLM
- RAG
- MCP
- Agent
- Fine-tuning
- Quantization
We put it all together in one video:
AI Engineering Explained: LLM, RAG, MCP, Agent, Fine-Tuning, and Quantization
No need to stop reading - bookmark it and watch later when you get time. Future you will thank you.
Now, let's get back to the topic.
Testing our guesses with interventions
Finding a feature with a label is only half of the work. A label is only a guess. We must prove that the model really uses that feature in the way we think.
So, how can we prove it? The answer is that we change the inside of the model and watch what happens to the output. This is called an intervention.
There are two common ways.
Way 1 (Steering): We take a feature and manually make it stronger or weaker while the model runs.
When Anthropic turned the Golden Gate Bridge feature up very high, the model started bringing up the bridge in almost every answer. When asked about itself, it even said that it was the Golden Gate Bridge. This was released for a short time as "Golden Gate Claude". It showed that this feature was not just a label. It really controlled the model's behavior.
Way 2 (Activation patching): Activation patching means taking the activation from one input and pasting it into the model while it processes a different input.
Let's say we have two prompts:
- Clean prompt: "The Eiffel Tower is in the city of" and the model says "Paris".
- Corrupted prompt: "The Colosseum is in the city of" and the model says "Rome".
Now, we run the corrupted prompt, but at one chosen location inside the model, we paste the activation from the clean prompt. If the answer flips from "Rome" to "Paris", we found a location that carries the information about the landmark's city.
Let's see the idea in code as below:
# Step 1: save activations from the clean run
clean_cache = run_and_save_activations(model, "The Eiffel Tower is in the city of")
# Step 2: run the corrupted prompt, but patch one chosen location (target_layer, target_position)
def patch(layer, position, activation):
if (layer, position) == (target_layer, target_position):
return clean_cache[(layer, position)] # paste clean value here
return activation # keep everything else
output = run_with_hook(model, "The Colosseum is in the city of", hook=patch)
print(prob_of(output, "Paris"))
Here, run_and_save_activations and run_with_hook are simple helper names just for the sake of understanding. Real libraries like TransformerLens provide such helpers. We save every activation from the clean run first. Then, we run the corrupted prompt and replace only one activation with the clean one. If the chance of "Paris" goes up a lot, that location matters for this fact.
We repeat this for every layer and position, and we get a map of where the important information lives.
Stay updated: Subscribe to our newsletter to get our latest AI and Machine Learning blogs straight to your inbox.
A real example: induction heads
Now, let's take a real, well-understood circuit inside language models.
Before that, we need one term. Inside an LLM, there are parts called attention heads. An attention head lets the current word look back at earlier words in the text and pull information from them.
Now, look at this text:
"Mr. Dursley ... (many words) ... Mr. ___"
Most of us can guess that the next word is "Dursley". Why? Because earlier, "Mr." was followed by "Dursley", so we expect the same pattern again.
Researchers at Anthropic found, in a 2022 paper on in-context learning, that models do the same using a two-step circuit called an induction head:
- Step 1: An earlier attention head, called a "previous token head", marks every token with the token that came before it. So, "Dursley" gets a note saying "Mr. came before me".
- Step 2: The induction head, sitting at the second "Mr.", searches for an earlier word whose note says "Mr. came before me". It finds "Dursley" and copies it as the prediction.
+---------------------------------------------+
| Text: ... Mr. Dursley ... Mr. ___ |
+---------------------------------------------+
↓
+---------------------------------------------+
| Step 1: Previous token head |
| "Dursley" gets a note: "Mr. came before me" |
+---------------------------------------------+
↓
+---------------------------------------------+
| Step 2: Induction head at the second "Mr." |
| Searches for the note "Mr. came before me" |
+---------------------------------------------+
↓
+---------------------------------------------+
| Finds "Dursley" and copies it as the |
| prediction |
+---------------------------------------------+
Here, we can see that the second "Mr." looks for a word that was preceded by "Mr." and copies it forward.
This circuit is well understood: we know which heads are involved, what they look at, and how the weights produce this behavior.
To master the Attention Mechanism, Self-Attention and Multi-Head Attention, and the Transformer Architecture in depth, we have our AI and Machine Learning Program at Outcome School.
The full workflow
Now, it's time to put features, circuits, sparse autoencoders, and interventions together.
A typical Mechanistic Interpretability study goes like this:
Step 1: Pick a behavior. For example, "the model knows that the Eiffel Tower is in Paris".
Step 2: Collect activations. Run many inputs through the model and save the activations from the layers we care about.
Step 3: Find features. Train sparse autoencoders on those activations and label features by looking at where they fire.
Step 4: Trace the circuit. Find which features in earlier layers feed into which features in later layers for this behavior. Newer methods, like the attribution graphs that Anthropic published in 2025, build this map automatically for a single prompt.
Step 5: Form a hypothesis. Write the mechanism in plain words, like "the model first finds the landmark, then looks up its city, then outputs the city".
Step 6: Test with interventions. Steer features or patch activations. If the behavior changes the way our hypothesis predicts, the hypothesis gains support.
+-------------------------------+
| Behavior |
+-------------------------------+
↓
+-------------------------------+
| Activations |
+-------------------------------+
↓
+-------------------------------+
| Features (SAE) |
+-------------------------------+
↓
+-------------------------------+
| Circuit |
+-------------------------------+
↓
+-------------------------------+
| Hypothesis | <---------+
+-------------------------------+ |
↓ |
+-------------------------------+ |
| Intervention | |
+-------------------------------+ |
↓ |
+-------------------------------+ |
| Prediction does not match? | |
| Revise the hypothesis | ----------+
+-------------------------------+
Here, we can see that it is a loop. If the intervention does not match our prediction, we revise the hypothesis and test again.
Where it works well and where it fails
Let me tabulate the strengths and the limits for your better understanding.
| Works well | Still fails or is hard |
|---|---|
| Finding clean, readable features with sparse autoencoders | SAEs do not rebuild the activations perfectly, so some of the model's work is missed |
| Explaining small, specific behaviors like induction heads | Explaining a whole large model end to end is far from done |
| Proving cause and effect using steering and patching | Labels for features are given by humans or other models and can be wrong |
| Finding hidden concepts like deception or bias features | It takes a lot of compute and human time for each behavior |
| Giving a path to check model safety from the inside | Different SAE settings find somewhat different features, so the "true" set is unclear |
Now we must have understood how Mechanistic Interpretability works.
Frequently Asked Questions
How is Mechanistic Interpretability different from other explainability methods?
Mechanistic Interpretability looks at the whole path inside the model, from input to result. Many other methods only tell us which input words were important for the answer. Mechanistic Interpretability explains a model by understanding its inner mechanism, its actual parts and connections, not just by looking at its inputs and outputs.
What is the difference between a polysemantic and a monosemantic neuron?
A polysemantic neuron fires for many unrelated things, while a monosemantic neuron fires for just one clean idea. For example, one neuron in an image model fired for cat faces, for the front of cars, and for cat legs. Most neurons in big language models are polysemantic, so looking at neurons one by one gives a confusing picture.
What was Golden Gate Claude?
Golden Gate Claude was a version of the model in which Anthropic turned the Golden Gate Bridge feature up very high. The model started bringing up the bridge in almost every answer, and even said that it was the Golden Gate Bridge. It was released for a short time, and it showed that the feature really controlled the model's behavior.
Do Sparse Autoencoders capture everything a model does?
No. Sparse Autoencoders do not rebuild the activations perfectly, so some of the model's work is missed. Also, different SAE settings find somewhat different features, so the "true" set of features is unclear. The labels given to features also come from humans or other models, and they can be wrong.
That's it for now.
Thanks
Amit Shekhar
Founder @ Outcome School
You can connect with me on:
Follow Outcome School on:
