Skip to main content

Someone wanted to learn this too, so Grasp built them a personal learning path.

You can keep exploring this one or create your own

Understanding Model Internals: An Introduction to Mechanistic Interpretability

Hello! Welcome to your fifth lesson in the AI Alignment and Safety module.

In our previous lesson, we explored Constitutional AI (CAI), Anthropic's method for aligning models with a set of explicit principles. We saw how this shapes a model's external behavior to be more harmless and helpful, moving the human role from labeling data to designing the system's rules.

Today, we're going to peel back the layers and look inside the model. While CAI treats the model as a system to be guided, this lesson asks: what are the internal mechanisms that produce the model's behavior in the first place? This brings us to a field that is core to Anthropic's research philosophy: Mechanistic Interpretability.

Your learning outcome is to explain the goals of mechanistic interpretability and how techniques like circuit analysis help us understand models.

1. What is Mechanistic Interpretability?

Neural networks, especially large language models, are often described as "black boxes." We design their architecture and training process, but the complex algorithms they learn emerge on their own. As you know from building complex distributed systems, not understanding the internal state and logic of a component can make debugging, ensuring reliability, and preventing exploits incredibly difficult.

Mechanistic Interpretability (MI) is the field dedicated to reverse-engineering these emergent algorithms from the model's weights and activations.

To get a foundational understanding of this idea, let's hear from Chris Olah, a pioneering researcher in this field (and a lead at Anthropic's interpretability team).

Mechanistic Interpretability explained | Chris Olah and Lex Fridman

In this clip from a conversation with Lex Fridman, Chris Olah explains the core motivation behind mechanistic interpretability.

Watch the first 3 minutes of the video. Pay attention to the analogy of neural networks being 'grown' rather than 'programmed' and how MI seeks to discover the algorithms that form within them. Note the distinction he makes between MI and older methods like saliency maps.

The Engineer's Goal: From Understanding to Control

While the academic goal of MI might be pure understanding, for an engineer—especially at a safety-conscious company like Anthropic—the goals are more pragmatic. It's less about "What does the model know?" and more about "What can break, and how can I fix it?"

Mechanistic Interpretability for Engineers | by Zaina Haider - Medium

The article 'Mechanistic Interpretability for Engineers' reframes the field from an engineering perspective, which should resonate with your background.

Read the section '1. The Engineering Goal Is Not Understanding'. It clearly lists the practical engineering goals that MI serves, such as debugging failures, improving reliability, and controlling behavior.

As the article highlights, MI is valuable when it helps us:

  • Debug failures and reduce hallucinations.
  • Improve the reliability and predictability of model outputs.
  • Control model behavior to align it with safety requirements.
  • Diagnose regressions or silent drift in model updates, much like you'd use integration tests or performance monitoring in a system like Rudi.

MI moves us from treating the model as an opaque box that we can only influence via its inputs (prompting) and outputs (fine-tuning) to a system whose internal logic we can begin to analyze and, eventually, control.

2. The Building Blocks: Features and Circuits

To reverse-engineer a program, you first need to understand its basic components and structures. In MI, the key concepts are features and circuits.

  • Features: Think of these as the idealized "variables" or "concepts" the model uses. A feature isn't necessarily a single neuron. Often, a concept (like "the Golden Gate Bridge" or "a line of code in Python") is represented by a specific direction in the high-dimensional activation space. A major challenge, known as polysemanticity, is that a single neuron can be involved in representing many unrelated features.
  • Circuits: These are the "algorithms" built from features. A circuit is a subgraph of the neural network—a specific set of connections between features across layers—that implements a certain computation.

The video below gives a fantastic explanation of these concepts, including a simple circuit example (a car detector) and the fundamental idea that makes this analysis possible: the Linear Representation Hypothesis.

Mechanistic Interpretability explained | Chris Olah and Lex Fridman

Continuing with Chris Olah, this segment defines the core vocabulary of MI.

Watch from 09:06 to 18:37. Focus on: The definition of features and circuits, particularly the example of a car-detector circuit being built from wheel and window detectors. The 'Linear Representation Hypothesis' and the famous word2vec analogy: King - Man + Woman = Queen. This is a crucial concept that suggests vector arithmetic inside models is meaningful.

The idea that you can meaningfully add and subtract concepts within a model's internal state is powerful. It's the foundation that allows us to trace how information flows and transforms, which is the essence of circuit analysis.

3. Circuit Analysis: How We Find Algorithms in the Machine

Circuit analysis is the process of identifying a specific circuit responsible for a specific, observable behavior. Think of it like using a debugger and profiler to trace a single request through a distributed system to see exactly which services and functions were called.

A Concrete Example: Indirect Object Identification (IOI)

A classic example is the Indirect Object Identification (IOI) task. Consider the sentence:

"When Mary and John went to the store, John gave a drink to ___"

The model should predict "Mary". How does it do this? Researchers have identified a circuit for this behavior.

Circuit Diagram for Name Tracking in a Language Model
This diagram from Redwood Research shows a simplified circuit for the IOI task in GPT-2. It illustrates how different attention heads specialize in sub-tasks: some find names ('Duplicate Token Heads'), others inhibit the name that is the subject ('S-Inhibition Heads'), and others copy the remaining name to the final position ('Name Mover Heads').

This is what a mechanistic explanation looks like: a specific, testable hypothesis about how components of the model collaborate to produce an output. But how do we find these circuits?

The Key Tool: Activation Patching

The primary technique for establishing a causal link between a component and a behavior is activation patching. It's a clever experimental technique that works like this:

  1. Define Two Inputs: Create a "clean" input (The Louvre is in Paris) and a "corrupted" input (The Coliseum is in Rome) that should produce different behaviors.
  2. Run Both Inputs: Run the model on both inputs and save all the internal activations at each layer.
  3. Patch and Observe: Run the model again on the corrupted input, but at a specific point (e.g., layer 10, attention head 5), swap in (or "patch") the activation from the clean run.
  4. Measure the Effect: Does this patch "trick" the model? If patching the clean activation causes the corrupted run to output "Paris" instead of "Rome", you've found a component that is causally responsible for that decision.

This process is like a targeted A/B test on the model's internal computation.

Activation Patching and Boolean Logic Analogies for Mechanistic Interpretability
This image illustrates the concept of activation patching. It shows swapping activations from a 'clean' run (Input A) into a 'corrupted' run (Input B) to isolate which internal components are responsible for a specific behavior.

By systematically patching different components (layers, attention heads, neurons), researchers can generate a "heat map" of which parts of the model are critical to the circuit.

This next reading provides a fantastic, detailed walkthrough of circuit analysis techniques, focusing on the ones most relevant to an engineer.

"Mechanistic interpretability" for LLMs, explained - The Counterfactual

The article '"Mechanistic interpretability" for LLMs, explained' provides an excellent technical deep dive into the MI toolbox.

Read two key sections: 'What is a “mechanistic answer” anyway?': This section introduces the IOI task we just discussed and frames what a mechanistic answer looks like. 'Tool #2: Activation patching': This section provides a detailed, step-by-step explanation of how activation patching works using a minimal pair example. It's the most important causal analysis technique in the MI toolbox.

Other Important Techniques

While activation patching is central, other techniques are also crucial:

  • Ablation: The simpler cousin of patching. You simply "zero out" or disable a component (e.g., an attention head) and see if the model's performance on a task breaks. This is like turning off a microservice to see what downstream systems fail.
  • Sparse Auto-Encoders (SAEs): A more advanced technique used to tackle the problem of polysemanticity. SAEs are small neural networks trained to find the "true" underlying features within a model's activation space, making them more interpretable and easier to analyze. Anthropic has done groundbreaking work using SAEs to find millions of interpretable features in Claude Sonnet.

This next short video gives a great overview of these techniques from a practical, "how-to-hack-an-LLM" perspective.

Hacking LLMs: An Introduction to Mechanistic Interpretability — Jenny Vega

The talk 'Hacking LLMs: An Introduction to Mechanistic Interpretability' provides a quick tour of the main techniques used by researchers.

Watch from 15:13 to 22:47. The speaker, Jenny Vega, quickly explains activation patching, ablation, and other tools. Crucially, she connects these techniques to practical safety applications, such as identifying how a model might leak private data or respond to jailbreaking prompts.

Conclusion

In this lesson, we've journeyed inside the black box to understand the goals and methods of mechanistic interpretability. This field is not just an academic curiosity; for a company like Anthropic, it is a fundamental part of the strategy for building safe and reliable AI.

Key Takeaways:

  • Goal of MI: To reverse-engineer the algorithms that emerge in neural networks, moving from a behavioral understanding to a mechanistic one. For engineers, this translates to crucial capabilities in debugging, reliability, and safety control.
  • Features and Circuits: The core concepts of MI are features (meaningful concepts or variables) and circuits (algorithms formed by connected features).
  • Circuit Analysis: This is the process of identifying which model components are responsible for a specific behavior.
  • Activation Patching: This is the primary causal analysis tool used in circuit analysis. By swapping activations between different inputs, researchers can pinpoint which components are critical for a given computation.
  • Practical Applications: MI research is directly applied to safety challenges, such as understanding and mitigating hallucinations, data leakage, and vulnerability to prompt injections.

Your experience designing, deploying, and monitoring complex, high-stakes systems at AWS gives you a unique perspective on the importance of this work. Just as you wouldn't run a critical service without detailed metrics, logging, and tracing, the ultimate goal of MI is to provide similar observability for the most complex software we've ever built.

Next Lesson Preview

Understanding a model's internal mechanisms is a prerequisite for ensuring it will behave safely as its capabilities increase. In our next lesson, we will explore how this idea connects to long-term safety strategy by examining Anthropic's Responsible Scaling Policy (RSP) and AI Safety Levels (ASL). We'll see how interpretability is a key component required to "level up" a model's safety validation as it becomes more powerful.

Can't find a good explanation? Sign up and we'll make it for you

Sign up