Skip to main content

NeuronLens Python Package - Interpretability analysis functions

Project description

NeuronLens Python Package

A Python package for accessing NeuronLens interpretability analysis functions.

Publishing to PyPI

  1. Update version in setup.py and __init__.py
  2. Build package: cd sae_app_v3/pip && python -m build
  3. Publish: export $(cat .env | xargs) && python -m twine upload dist/*

Note: PyPI API token in sae_app_v3/pip/.env (excluded from git).

Installation

pip install neuronlens

Development: cd sae_app_v3/pip && pip install -e .

Quick Start

API key required (via parameter or NEURONLENS_API_KEY env var):

import neuronlens
engine = neuronlens.Engine(api_key="nlive_your_api_key_here")

# Analyze agent query
result = engine.analyze_agent("Get Tesla stock price")
print(f"Alignment: {result['alignment_status']}")

# Analyze sentiment
result = engine.analyze_sentiment("Strong earnings", top_n=10)
print(f"Sentiment: {result['sentiment']['predicted_label']}")

Function Reference

High-Level: analyze_agent(), analyze_sentiment(), analyze_trading(), analyze_reasoning(), analyze_hallucination(), search_features(), steer_features()

Common Backend: extract_top_features(), model_cache_status(), unload_model(), unload_all_models()

Examples

# Sentiment
result = engine.analyze_sentiment("Strong quarterly earnings")
print(f"Label: {result['sentiment']['predicted_label']}")

# Search & Steer
features = engine.search_features("market volatility", k=10, layer=16)
steered = engine.steer_features(
    prompt="Market outlook?",
    features=[{"id": features[0]['feature_id'], "magnitude": 0.7}]
)

Architecture

  • Direct mode: When sae_app_v3 available, imports functions directly
  • HTTP mode: When sae_app_v3 not available, makes HTTP requests to frontend server (port 8001)

Server Requirements: Backend (port 8000) and Frontend (port 8001) must be running.

Configuration

API URL (priority): config.jsonNEURONLENS_API_URL env → .ngrok_url file → Ngrok API → constructor param

API Key: NEURONLENS_API_KEY or API_KEY env var, .env file, or Engine(api_key="...")

Requirements

Python 3.8+, requests>=2.25.0, numpy>=1.20.0

License

MIT License

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

neuronlens-0.2.1.tar.gz (13.6 kB view details)

Uploaded Source

Built Distribution

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

neuronlens-0.2.1-py3-none-any.whl (18.6 kB view details)

Uploaded Python 3

File details

Details for the file neuronlens-0.2.1.tar.gz.

File metadata

  • Download URL: neuronlens-0.2.1.tar.gz
  • Upload date:
  • Size: 13.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.8

File hashes

Hashes for neuronlens-0.2.1.tar.gz
Algorithm Hash digest
SHA256 0458c5183e8b828fc47efe11047c1423b6b8f4c6ab6ffc1bcc4910d600d3f6c2
MD5 9976b072965090552344930766ca214e
BLAKE2b-256 f737e4e9ae0c48755360d31ca09e0ce3b573361ffdc9046b595d919ae46fb8a4

See more details on using hashes here.

File details

Details for the file neuronlens-0.2.1-py3-none-any.whl.

File metadata

  • Download URL: neuronlens-0.2.1-py3-none-any.whl
  • Upload date:
  • Size: 18.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.8

File hashes

Hashes for neuronlens-0.2.1-py3-none-any.whl
Algorithm Hash digest
SHA256 f3ab7c870f15ac1ba5b78e2dccd291d825d44285a34dfc80d768bd45fdbb0a3c
MD5 5abf405dbc51c80d5634d4d8afb74be8
BLAKE2b-256 e8ef05502b72ea3786e1cd23c0a56c88882af7b4c9670a1240839ed54242dd31

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