AI Interpretability

In this unit you look inside a neural network and ask what it learned. A neuron often holds many ideas at once. This is superposition. A sparse autoencoder (SAE) is a second small network that pulls the ideas apart again.

The lecture is a notebook in your Codespace. Then you run two marimo notebooks in molab. They build a toy network and train an SAE on it. Last, you do a short exercise in your Codespace. You do not turn it in.

You need your fork of the class repo and the pixi environment from the Encoders unit.

1. Sync your fork

The lecture and the exercise are in the class repo, not in your fork yet. Open your Codespace from github.com/codespaces. In the terminal, run opencode and paste this prompt:

Sync my Codespace with the class repo and push my work. Do not lose any of my work.

1. Run git status. If there are any changed or new files, stage them all and commit
   with the message "save my work before sync".
2. Run gh repo sync. If it succeeds, go to step 6.
3. If it fails because of diverging changes, do NOT run it again with --force. Instead,
   run git fetch upstream, then merge upstream/main into my current branch. If there
   is no remote named upstream, stop and tell me.
4. If a notebook (.ipynb) in notebooks/ or exercises/ has a conflict, do not edit inside the file. Keep my version
   under the original name. Save the class version next to it with "-new" added
   before .ipynb. Then mark the conflict resolved.
5. Commit the merge.
6. Push to origin.
7. Show me a short list: files that came in from the class repo, and any "-new" files
   you made. Stop after that. Do not delete anything. Do not force push.

When it is done, check that the files arrived:

ls notebooks exercises

You should see 19-ai-interpretability.ipynb and 19-sae-exercise.ipynb.

2. Start JupyterLab

Open a second terminal with the + button in the terminal panel. Then run:

pixi shell
jupyter lab --ip=0.0.0.0 --port=8888 --no-browser --IdentityProvider.token='' --ServerApp.password='' --config=jupyter_config.py

If you added the jlab task in the Model Basics unit, you can run this one command instead:

pixi run jlab

Open JupyterLab the same way as before. Click the Ports tab, find the 8888 row, and click the globe icon. Do not use the Open in Browser popup.

The Ports tab in VS Code. The row for port 8888 is highlighted and the globe icon shows a tooltip that says Open in Browser.

Hover over the 8888 row and click the globe.

3. Follow along with the lecture

In JupyterLab, double-click the notebooks folder, then 19-ai-interpretability.ipynb. Follow along in class. You do not need to change it or turn it in.

4. Run the marimo notebooks

We run these two notebooks together in class. Click each badge to open it in molab:

  1. Toy superposition. Train a tiny network that squeezes 5 ideas into 2 neurons. Then look at how the ideas overlap. At the end, download hidden_activations.csv. Open the toy superposition notebook in molab
  2. Sparse autoencoder. Upload hidden_activations.csv. Train an SAE on it. At the end, download sae_output.csv. Open the sparse autoencoder notebook in molab

If molab asks you to sign in, use your GitHub account. Training takes a minute or two.

Keep sae_output.csv. You need it for the exercise. The notebooks are also in the marimo repo.

5. Complete the exercise

In JupyterLab, open the exercises folder. Use the Upload button (the up-arrow icon) to put sae_output.csv in this folder. Then double-click 19-sae-exercise.ipynb.

The exercise asks one question: did the SAE find the true features? The SAE never saw the 5 true features. Now you peek at the answer key. Do the steps in order. Use opencode when you need help.

Save your work. You do not turn this exercise in.

Things to know

  • Stop your Codespace when you are done to save your free hours.
  • If the sync makes a -new file, the class version of that notebook changed. Open it next to your own copy to see what changed.
  • molab runs in your browser. Nothing you do there goes into your fork.
  • The numbers change a little each time you train. Your table may have the latents in a different order than your neighbor’s. That is fine.