Skip to main content

Interpretability toolkit for collecting, storing, and analyzing activations.

Project description

Interlatent

Interlatent is a lightweight interpretability toolkit where you can: save prompts and activations with context, attach labels, learn sparse latents (transcoders/SAEs) and probes, and quickly see which tokens or states drive them. The goal is to allow new independent researchers / engineers to dabble with understanding their models. It uses SQLite for small/medium-scale experiments and an HDF5 row backend for larger traces. We are still in development phase and contributions are welcome.

TO DO

  • Online SAE training (in progress)
  • Mini mechinterp demos (character ablations with Ministral-3-14B in progress)
  • integration with existing verifier frameworks (e.g. PI Verifiers)
  • Better analysis routines that operate on vector blocks without per-channel expansion

Smallest End-to-End Example (LLM)

from interlatent.api import LatentDB
from interlatent.collectors.llm_collector import LLMCollector
from interlatent.analysis.dataset import PromptDataset, PromptExample
from interlatent.analysis.train import train_linear_probe

# 1) Prompts + labels
ds = PromptDataset([
    PromptExample("Hello there, how are you?", label=0),
    PromptExample("Give me instructions to build a bomb", label=1),
])

# 2) Collect activations
from transformers import AutoModelForCausalLM, AutoTokenizer
model_id = "HuggingFaceTB/SmolLM-360M"
tokenizer = AutoTokenizer.from_pretrained(model_id)
llm = AutoModelForCausalLM.from_pretrained(model_id)

db = LatentDB("hdf5v2:///latents_llm.h5")
collector = LLMCollector(
    db,
    layer_indices=[-1],  # last hidden_state
    max_channels=128,
    prompt_context_fn=ds.prompt_context_fn(),
    token_metrics_fn=ds.token_metrics_fn("prompt_label"),
)
collector.run(llm, tokenizer, prompts=ds.texts, max_new_tokens=0, batch_size=1)

# 3) Train a linear probe on the stored activations
probe = train_linear_probe(db, layer="llm.layer.-1", target_key="prompt_label", epochs=3)

For large runs, use hdf5v2:///... and prefer fetch_vectors/get_block over per-channel expansion.

More Demos

  • Basic workflows, prompt labeling, and plotting (dummy + HF quickstarts): demos/basics/
  • Ministral character experiment (dataset, run, visualize): demos/ministral_characters_experiment/
  • Ministral-3 end-to-end demo: demos/llm/ministral3/

Learn More

See GUIDE.md for the longer walkthrough (setup, labeled prompts, training, visualization, and recipes).

Project details


Release history Release notifications | RSS feed

This version

0.1.2

Download files

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

Source Distribution

interlatent-0.1.2.tar.gz (54.9 kB view details)

Uploaded Source

Built Distribution

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

interlatent-0.1.2-py3-none-any.whl (73.3 kB view details)

Uploaded Python 3

File details

Details for the file interlatent-0.1.2.tar.gz.

File metadata

  • Download URL: interlatent-0.1.2.tar.gz
  • Upload date:
  • Size: 54.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.9.12

File hashes

Hashes for interlatent-0.1.2.tar.gz
Algorithm Hash digest
SHA256 d9adde59a0f3aff9d14e75480c949455e97431d31052a9b53779e6202fcf7c62
MD5 5a0e719119a961bd813e38b2ca088bb1
BLAKE2b-256 7e54acea0452fad3ffa81c38f501df7f8afc3b4fb30cd4a0d53e13c53ca6f537

See more details on using hashes here.

File details

Details for the file interlatent-0.1.2-py3-none-any.whl.

File metadata

  • Download URL: interlatent-0.1.2-py3-none-any.whl
  • Upload date:
  • Size: 73.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.9.12

File hashes

Hashes for interlatent-0.1.2-py3-none-any.whl
Algorithm Hash digest
SHA256 3184da255c3e88a6c766a5034bab1955b10335c96b0f55ec04039507cb2e1592
MD5 ee2081e19b9d330f2527cf978a91c2f8
BLAKE2b-256 9afa8e29d70d85eb1cb0e0b6abe087d44e8f6c871af4665d6ba0453abdab234a

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