# Useful starting code for interpretability

Want to try your hand at neural network interpretability? A very nice way to get started is to find an existing Python notebook using one or more interpretability techniques, hopefully one written with beginners in mind. In a click or two you can make a copy of it, which you can typically run without any modification, and then start tweaking it to look at what you're interested in. 

Fortunately, many such notebooks already exist, thanks to helpful members of the interp community! This post is just a list of those, mostly [Colab](https://colab.research.google.com/) notebooks. Many of them I have no personal experience with, but all of them have been recommended by people who know what they're doing. This list will probably be acceptably current through late 2024 or so; after that you should use a more up-to-date resource if one exists (although if one existed *now* I would have used it instead of writing one, so there may or may not be another one then).

Suggestions for other similarly useful starter notebooks for other areas are extremely welcomed!

*   Notebooks for understanding machine learning (as background): [Transformers From Scratch](https://colab.research.google.com/drive/1lDwKASSYGE4y_7DuGSqlo3DN41NHrXEw?usp=sharing), [some other ML technique](https://arena3-chapter0-fundamentals.streamlit.app/) notebooks, [reinforcement learning](https://arena3-chapter2-rl.streamlit.app/).

And the main list is in no particular order, so no need to go top to bottom.

*   [@Neel Nanda](https://www.lesswrong.com/users/neel-nanda-1?mention=user)'s [exploratory analysis demo](https://colab.research.google.com/github/neelnanda-io/TransformerLens/blob/main/demos/Exploratory_Analysis_Demo.ipynb) for TransformerLens walks you through many of the basic mech interp techniques, and is highly recommended, and he has others as well.
*   Another [intro to mech interp](https://colab.research.google.com/drive/1gZdHsBL8Ljq7nSWJtxxlsI4JWHmllxxP?usp=sharing) from [ARENA](https://www.arena.education/), along with [several other excellent notebooks](https://arena3-chapter1-transformer-interp.streamlit.app/~/+/) reproducing some important mech interp results:
    *   [ Indirect Object Identification](https://colab.research.google.com/drive/1ZzLGDngppg5Y7CAKubww45RZrcXpVsrL?usp=sharing)
    *   [Superposition & Sparse Autoencoders](https://colab.research.google.com/drive/1iCM3V0G3B7NSxKsZkvHtmv7k9rgBXYk4)
    *   [Function Vectors & Model Steering](https://colab.research.google.com/drive/1NYjR3tjOiDJ2v8nv3mhrph-_IM4p9goS?usp=sharing)
    *   [OthelloGPT](https://colab.research.google.com/drive/1-0HDNWowpG7gSiWJLrPWCHqEDEfXuLkq?usp=sharing)
    *   [Balanced Bracket Classifier](https://colab.research.google.com/drive/1q2NzRVjTAjz1XWb3N3DbICKd83AyqsrN?usp=sharing)
    *   [Grokking and Modular Arithmetic](https://colab.research.google.com/drive/1wg20amCB7n_myEgHYXMnltLiqH3f9aRN?usp=sharing)
*   [Two activation steering notebooks](https://github.com/UlisseMini/activation_additions_hf/tree/main/notebooks), based on "[Steering GPT-2-XL by adding an activation vector](https://www.lesswrong.com/posts/5spBue2z2tw4JuDCx/steering-gpt-2-xl-by-adding-an-activation-vector)" (bonus: [several different implementations](https://github.com/annahdo/implementing_activation_steering?tab=readme-ov-file) from [@Annah](https://www.lesswrong.com/users/annah?mention=user)) (extra bonus: [quick and dirty representation engineering](https://github.com/vgel/repeng/tree/main/notebooks) on Mistral)
*   [Developmental interpretability and singular learning theory notebooks](https://github.com/timaeus-research/devinterp/tree/main/examples), from [@Jesse Hoogland](https://www.lesswrong.com/users/jesse-hoogland?mention=user).
*   A smallish [notebook](https://colab.research.google.com/github/AlignmentResearch/tuned-lens/blob/main/notebooks/interactive.ipynb) on using the [tuned lens technique](https://tuned-lens.readthedocs.io/en/latest/index.html) (successor to the [logit lens](https://www.lesswrong.com/posts/AcKRB8wDpdaN6v6ru/interpreting-gpt-the-logit-lens)).
*   [Mech interp on Mamba](https://colab.research.google.com/drive/1he9B5anOjJSZgGsedso3PS7Xq11W-PTs) using nnsight.

Thanks to [@Jesse Hoogland](https://www.lesswrong.com/users/jesse-hoogland?mention=user) and [@CallumMcDougall](https://www.lesswrong.com/users/callummcdougall?mention=user) for extremely useful input!