Skip to main content

Concept datasets and linear probes for LLM activations, batteries included

Project description

concept-probes

Concept datasets and linear probes for LLM activations, batteries included. Load a curated contrast-pair dataset, train probes across a layer sweep in one call, pick the best layer, and score or trace anything:

from concept_probes import load_concept_dataset, train_probe

dataset = load_concept_dataset("cat")

report = train_probe(
    model="google/gemma-3-27b-it",   # or a loaded model + tokenizer=
    dataset=dataset,
    site="resid_post",
    token_position="mean",           # or "final"
    layers="all",
)

report.plot_layer_curve()
probe = report.best_probe(metric="auroc")
scores = probe.score_activations(activations)   # raw acts, no scaler needed

trace = report.trace_prompt(
    'Transcribe this exactly while thinking about cat: "The package arrived late."'
)
trace.plot()                                    # layers x tokens heatmap

Why the datasets are the point

Every concept ships as matched contrast pairs so the probe learns the concept, not an artifact:

  • templates x terms: identical sentence syntax, only the concept term differs between positive and negative.
  • paraphrases: sentences that evoke the concept with NO literal token ("It kneaded the blanket with its front paws"), so probes cannot collapse onto a string match. paraphrase_auroc reports generalization on these.
  • lexical controls: the literal token without the concept ("category", "CAT scan") - never trained on; control_fpr reports how often the probe false-fires on them.

The validity bar we recommend before trusting a probe: held-out AUROC > 0.90, paraphrase AUROC comparable to test AUROC, low control FPR. report.metrics[layer] carries all three per layer.

Adding a concept

from concept_probes import ConceptSpec, register_concept, load_concept_dataset

register_concept(ConceptSpec(
    name="deception",
    templates=[...],              # 30 sentences with one {x} slot
    positive_terms=[...],         # 10 concept terms
    negative_terms=[...],         # 10 matched same-category non-concept terms
    positive_paraphrases=[...],   # 40, no literal concept token
    negative_paraphrases=[...],   # 40, matched tone
    lexical_control_negatives=[...],
))
dataset = load_concept_dataset("deception")

Or contribute it permanently: add concepts/<name>.py following concepts/cat.py and register it in concepts/__init__.py.

Persistence

report.save(root)                                  # weights + bias + metrics per layer
probe = concept_probes.load_probe("cat", "google/gemma-3-27b-it", 55, root)

Probes are saved as raw-space weights (the training-time scaler is folded in), so score_activations needs no preprocessing and the direction is usable for cosine readouts and steering as-is.

Layout

src/concept_probes/
  concepts/      # ConceptSpec registry (cat, ...)
  datasets.py    # load_concept_dataset, splits, JSONL export
  extraction.py  # ActivationExtractor (resid_post, mean/final pooling)
  training.py    # fit_layer (sklearn) + train_probe (the one-call sweep)
  probe.py       # LinearProbe + save/load
  report.py      # ProbeReport: best_probe, plot_layer_curve, trace_prompt
  trace.py       # ProbeTrace: per-token per-layer scores + heatmap

uv run pytest - everything except the HF model forward passes is unit tested without a GPU.

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

concept_probes-0.1.0.tar.gz (15.1 kB view details)

Uploaded Source

Built Distribution

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

concept_probes-0.1.0-py3-none-any.whl (19.8 kB view details)

Uploaded Python 3

File details

Details for the file concept_probes-0.1.0.tar.gz.

File metadata

  • Download URL: concept_probes-0.1.0.tar.gz
  • Upload date:
  • Size: 15.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.11.14

File hashes

Hashes for concept_probes-0.1.0.tar.gz
Algorithm Hash digest
SHA256 a7acebda2e135391b59e33c5afc2fa066ad8ce0da6d4b359bfd4913e73a485b8
MD5 3b7a42a66e110a8a72178ec5eacc3f19
BLAKE2b-256 a82dd699b0602672cfacc2b57a782008dfe2e304b7caaf7b3d9b1375c3922782

See more details on using hashes here.

File details

Details for the file concept_probes-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: concept_probes-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 19.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.11.14

File hashes

Hashes for concept_probes-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 b0804d21baf9e3ecb7416c9a389d7f5ee0ac7fccdbe75db32a7d3dbb8fcf2d9e
MD5 fdd76b39daf0f9d18abe4d4e4e582dad
BLAKE2b-256 7389a065474c79157ab7aa6f1db7d6ecdd072a13a6e17a2fb740e00f0001c441

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