Persona Vectors
Extract persona vectors from language models, then probe, project, or steer with them.
A persona vector is the mean hidden-state activation a model produces while answering as a given persona. Extraction saves one (num_layers, hidden_size) tensor per persona, prompt variant, model, and mask strategy; everything downstream reads those tensors back.
personas + QA pairs -> prompts -> token masks -> hidden states -> saved vectors -> analysis
Install
uv sync
cp .env.example .env
Requires Python >=3.12. Set NDIF_API_KEY in .env for remote extraction.
Dataset loading comes from persona-data; the
Quickstart
# Extract — one (num_layers, hidden_size) vector per persona/variant/mask
uv run python main.py extract --model google/gemma-2-9b-it --backend remote
# Analyze — normalized PCA/UMAP, similarity, clustering, scree plots
uv run python main.py analyze --model google/gemma-2-9b-it --variant biography
# Probe — linear probes per persona attribute
uv run python main.py probe --model google/gemma-2-9b-it --variant templated
# Steer — biography minus templated direction
uv run python main.py steer --model google/gemma-2-9b-it --persona-id <UUID> --layer 20
# Push extracted vectors to the Hub
uv run python main.py push --model google/gemma-2-9b-it --repo implicit-personalization/synth-persona-vectors
Notebooks under notebooks/ cover the same flows interactively.
Extraction scripts
# Steering: train split, push to Hub, refresh the dataset card
MODEL=google/gemma-2-9b-it scripts/extraction_train_split.sh
# All-questions (explicit only): first 100 personas under artifacts/persona-vectors/,
# then push and refresh the dataset card
MODEL=google/gemma-2-9b-it scripts/extraction_all_questions.sh
What gets saved
artifacts/activations/<model_dir>/<mask_strategy>/<prompt_variant>/
├── manifest.json
└── <persona_id>.safetensors
<model_dir> is the HF id with / → __. Each safetensors file holds one activations tensor — the persona vector for that variant, averaged across QA pairs and selected tokens.
scripts/extraction_all_questions.sh writes under artifacts/persona-vectors/ to keep all-questions runs separate from train-split runs; pass --activations-dir artifacts/persona-vectors to read it back.
See the artifacts docs for the full layout.
Layout
src/persona_vectors/
├── activations.py # low-level hidden-state extraction
├── extraction.py # prompt formatting, masks, persona extraction flow
├── preview.py # token-mask preview for --verbose
├── artifacts.py # PersonaVectorStore (local) + HFPersonaVectorStore (Hub)
├── hub.py # push to / discover Hub vector datasets
├── analysis.py # aligned dataset loading, PCA, cosine similarity, clustering
├── plots/ # Plotly figures
├── attributes.py # attribute schema + color helpers for plots
├── probes.py # linear probes over saved persona vectors
├── steering.py # experimental steering vectors
└── parser.py # CLI parser
See the docs for API details.
Metadata
Release files for persona-vectors 0.8.10
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| persona_vectors-0.8.10.tar.gz | 49.1 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| persona_vectors-0.8.10-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 108.8 kB
Release files / persona_vectors-0.8.10.tar.gz
| Download URL | persona_vectors-0.8.10.tar.gz |
|---|---|
| Size | 49.1 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
d32ad922953995726d872e98e760b62022a6d7de6a791f2c6838fc5e7ab1ea6d
|
|
BLAKE2b-256 checksum How to use checksums |
99b9c7c95c6dcd6d61c37c87b765d23c3bd307a5f12d1567a2f6f7bc2b0c9c63
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
uv/0.11.19 {"installer":{"name":"uv","version":"0.11.19","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}
|
Release files / persona_vectors-0.8.10-py3-none-any.whl
| Download URL | persona_vectors-0.8.10-py3-none-any.whl |
|---|---|
| Size | 59.7 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
2a083ee1d42a3feab472cb687f7f0b81528530eac8156c1352941e0f589cc54e
|
|
BLAKE2b-256 checksum How to use checksums |
c1b95c99252375510c802a3c50fde9dc20a2d488e45b7584cc9d91aca9a1a2ee
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
uv/0.11.19 {"installer":{"name":"uv","version":"0.11.19","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}
|