Skip to main content

Python Library

The Neuronpedia Python library makes it easy to use the API from Python.

pip install neuronpedia

Source code: webapp-python-client on GitHub

Set Your API Key​

Some calls need an API key, for example calls that upload data or change your account.

  1. Sign in at neuronpedia.org.
  2. Copy your API key from neuronpedia.org/account.
  3. Set the environment variable NEURONPEDIA_API_KEY, for example in a .env file.
from dotenv import load_dotenv

load_dotenv() # loads NEURONPEDIA_API_KEY from .env

Example - Get a Feature​

from neuronpedia.np_sae_feature import SAEFeature

sae_feature = SAEFeature.get("gemma-2-2b", "20-gemmascope-res-16k", "10956")
print(sae_feature)

Example - Upload a Vector, Then Steer With It​

from neuronpedia.np_vector import NPVector
from neuronpedia.sample_data import GEMMA2_2B_IT_DINOSAURS_VECTOR

np_vector = NPVector.new(
label="dinosaurs",
model_id="gemma-2-2b-it",
layer_num=20,
hook_type="hook_resid_pre",
vector=GEMMA2_2B_IT_DINOSAURS_VECTOR,
default_steer_strength=44,
)

response = np_vector.steer_chat(
steered_chat_messages=[{"role": "user", "content": "Write a one sentence story."}]
)
print("UI Steering at: " + response["shareUrl"])

Example Notebooks​

NotebookWhat it does
get_sae_featureGet a feature and its data.
steer_completionSteer a completion with a vector.
upload_vector_and_activationsUpload a vector, test it, and upload its activations.
upload_featuresUpload your own features. See Upload Your SAEs.
new-modelAdd a new model.
generate_graphMake an attribution graph.
upload_graphUpload an attribution graph. See Upload Graphs.
llama_3.3_70b_instructGet activations and top features for your text, with Goodfire's Llama 3.3 70B SAE.

Other Libraries​

These libraries work with Neuronpedia:

  • SAELens - Train and load SAEs. Many SAEs on Neuronpedia can be loaded with SAELens.
  • circuit-tracer - Make attribution graphs on your own GPU, then upload them to Neuronpedia.
  • interp-engine - The library that Neuronpedia uses to run models. See interp-engine.