Skip to content

MostHumble/mech-interp-cookbook

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

9 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Mechanistic Interpretability Cookbook

A collection of simple, reproducible experiments to build intuition for mechanistic interpretability in transformer-based language models. This repo accompanies the blog post "Elements Of Mechanistic Interpretability: From Observation to Causation" on sifal.social, where we explore three key techniques: Logit Lens, Probing Classifiers, and Activation Patching.

These experiments use small, accessible models (like SmolLM2-360M-Instruct and GPT-2 Small) to demonstrate how to peek inside LLMs, locate concepts, and prove causal relationships in their internal computations.

Overview

Mechanistic interpretability aims to reverse-engineer the "circuits" inside neural networks to understand how they process information. This repo provides standalone Jupyter notebooks for three foundational experiments:

  • Logit Lens: Watch a model's "thought process" evolve layer by layer.
  • Probing Classifiers: Locate where specific concepts (e.g., part-of-speech tags) are represented.
  • Activation Patching: Perform "causal surgery" to identify which attention heads drive behavior.

Each notebook is self-contained, generates visualizations, and includes comments for easy understanding. The experiments are based on toy problems like factual recall and Indirect Object Identification (IOI) to keep things simple and focused.

For more details, read the blog post.

Usage

Each notebook can be opened and run in Jupyter Notebook, JupyterLab, or Google Colab, note that these experiments work on CPU but run faster on GPU (CUDA-enabled).

upload to Google Colab for cloud execution.

License

This project is licensed under the MIT License. See LICENSE for details.

Acknowledgements

About

The goal here is to get your hands dirty asap!

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors