Skip to main content

Neuronpedia

Project description

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)

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

neuronpedia-1.2.0.tar.gz (41.9 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

neuronpedia-1.2.0-py3-none-any.whl (61.5 kB view details)

Uploaded Python 3

File details

Details for the file neuronpedia-1.2.0.tar.gz.

File metadata

  • Download URL: neuronpedia-1.2.0.tar.gz
  • Upload date:
  • Size: 41.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/2.1.3 CPython/3.12.8 Darwin/25.1.0

File hashes

Hashes for neuronpedia-1.2.0.tar.gz
Algorithm Hash digest
SHA256 9ecd02b7f5f5374b5a6595d4b8f6b5641d56428293693051e9927fc7a809ca21
MD5 4ab20047b89e9a24023adffb15a76f25
BLAKE2b-256 d083a2e8afeeca18f57d4e91922549222416cceb1a3047b417e0378a663eea1c

See more details on using hashes here.

File details

Details for the file neuronpedia-1.2.0-py3-none-any.whl.

File metadata

  • Download URL: neuronpedia-1.2.0-py3-none-any.whl
  • Upload date:
  • Size: 61.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/2.1.3 CPython/3.12.8 Darwin/25.1.0

File hashes

Hashes for neuronpedia-1.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 9a9e865fa5af4128de200211fea7d9395f8214a8548b50f799f3a004f2126cf9
MD5 384286ee608e1f4a2b4d9a0ab2a9b983
BLAKE2b-256 bcd83546abf55cc4e10b4c2f42859877d27c218c9aeff967b0dd56ab4e5b9949

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page