Skip to main content

Neuronpedia Python Library

Authentication

Some APIs on Neuronpedia require an API key. For example, if you want to bookmark something in your account, or upload a new vector, you'll need to identify yourself with a Neuronpedia API key.

Setting the API Key

  1. Sign up for free at neuronpedia.org.
  2. Get your Neuronpedia API key from neuronpedia.org/account.
  3. Set the environment variable NEURONPEDIA_API_KEY to your API key. You can do this through a .env file or other similar methods.

Example: Upload a Vector, then Steer With It

from neuronpedia.sample_data import GEMMA2_2B_IT_DINOSAURS_VECTOR
from neuronpedia.np_vector import NPVector
import os, json

# from neuronpedia.org/account
os.environ["NEURONPEDIA_API_KEY"] = "YOUR_NP_API_KEY"

# upload the custom 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,
)

# steer with it
responseJson = np_vector.steer_chat(
    steered_chat_messages=[{"role": "user", "content": "Write a one sentence story."}]
)

print(json.dumps(responseJson, indent=2))
print("UI Steering at: " + responseJson["shareUrl"])

The output of the above will be similar to:

{
  "STEERED": {
    "chat_template": [
      {
        "content": "Write a one sentence story.",
        "role": "user"
      },
      {
        "content": "The last dinosaur roared, its breath a smoke-filled mirror of the dying sun.",
        "role": "model"
      }
    ],
    "raw": "<bos><start_of_turn>user\nWrite a one sentence story.<end_of_turn>\n<start_of_turn>model\nThe last dinosaur roared, its breath a smoke-filled mirror of the dying sun. \n<end_of_turn><eos>"
  },
  [...]
}

See the examples folder for detailed notebooks and usage.

Important: Uniquely Identifying a Vector/Feature

On Neuronpedia, a vector or feature has a unique identifier comprised of three parts:

  • Model ID: The ID of the model that this vector belongs to. For example, gpt2-small.
  • Source: A "group name" that starts with the layer number, and usually contains some other identifying information depending on what it is, like number of features in the group. Some examples of source:
    • 6-res-jb: 6 = Layer 6, res = residual stream, jb = Joseph Bloom
    • 3-gemmascope-att-16k: 3 = Layer 3, gemmascope = Gemma Scope, att = Attention, 16k = 16k-width SAE
  • Index: The index in the model + source. This is a string, and currently the string is always an integer. However, this may change in the future.

Example:

  • gemma-2-2b/3-gemmascope-att-16k/4232
    • Model: gemma-2-2b
    • Source: 3-gemmascope-att-16k
    • Index: 4232

To make API calls that involve an existing vector or feature on Neuronpedia, you pass the model, source, and index as required.

Example API Call: Get SAE Feature (including activations, explanations, etc)

from neuronpedia.np_sae_feature import SAEFeature

sae_feature = SAEFeature.get("gemma-2-2b", "3-gemmascope-att-16k", "4232")
print(sae_feature)

Metadata

Release files for neuronpedia 1.2.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for neuronpedia 1.2.1
File Size Uploaded Provenance
neuronpedia-1.2.1.tar.gz 45.7 kB Without provenance Details

Built distribution (wheel)

Table of built distributions (wheels) for neuronpedia 1.2.1
File Interpreter ABI Platform
neuronpedia-1.2.1-py3-none-any.whl Python 3 none any Details

Total release size: 111.3 kB

Release files / neuronpedia-1.2.1.tar.gz

Download URL neuronpedia-1.2.1.tar.gz
Size 45.7 kB
Tags Source
SHA-256 checksum
How to use checksums
33941faea683d0d0b1a4b910c33248200aed4a711da7e4c074b8567899e2cb29
BLAKE2b-256 checksum
How to use checksums
40b1907e117d0b04eabf24f0a405e179a923dcf63e4525aaa2bfd867c42abd7a
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.11.7 {"installer":{"name":"uv","version":"0.11.7","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"26.04","id":"resolute","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

Release files / neuronpedia-1.2.1-py3-none-any.whl

Download URL neuronpedia-1.2.1-py3-none-any.whl
Size 65.7 kB
Tags Python 3
SHA-256 checksum
How to use checksums
c439a0a08c22b61a7b8fe3638191ebae9113c39b7cdbf7a37fccc4589c106af6
BLAKE2b-256 checksum
How to use checksums
fd235a4f0cbe3d718db9b2d41cd0eca5a6849b5f72346396c0695abb87ec2169
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.11.7 {"installer":{"name":"uv","version":"0.11.7","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"26.04","id":"resolute","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

Security for neuronpedia 1.2.1

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page