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.0.23.tar.gz (44.6 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.0.23-py3-none-any.whl (63.5 kB view details)

Uploaded Python 3

File details

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

File metadata

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

File hashes

Hashes for neuronpedia-1.0.23.tar.gz
Algorithm Hash digest
SHA256 e5b06c20199110733bfbc150a5e0163a98d52ec8625bcdc86303dcf4eee32de7
MD5 68002ce259a11f68a971e003ef552274
BLAKE2b-256 e577ec91e498cfa44f4eff784c793e8dca072e4edeeaf99a47f1a46de788d332

See more details on using hashes here.

File details

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

File metadata

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

File hashes

Hashes for neuronpedia-1.0.23-py3-none-any.whl
Algorithm Hash digest
SHA256 ccffc1808faed9c64b1a346a4108ea0650966562c034ef631d80c8ed12880461
MD5 8ae4721ffb195c5f632712fcca90ea4f
BLAKE2b-256 a94c967497ce648474bf92271dd51081bed14ab327742067ef8d3cf6e1a67890

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