Library for extracting and analyzing persona vectors
Project description
Persona Vectors
Extract persona vectors from language models, then probe, project, or steer with them.
Experimental.
Install
uv sync
cp .env.example .env
Requires Python >=3.12. Set NDIF_API_KEY in .env for remote extraction.
Dataset loading comes from sibling persona-data; the Streamlit UI lives in sibling persona-ui. For local dev, uncomment the persona-data path source in pyproject.toml.
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 — PCA, 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
MODEL=google/gemma-2-9b-it scripts/extraction_train_split.sh
# All-questions (explicit only): first 100 personas under artifacts/persona-vectors/
MODEL=google/gemma-2-9b-it scripts/extraction_all_questions.sh
Both refresh the Hub dataset card after pushing.
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 separate from train-split runs; pass --activations-dir artifacts/persona-vectors to subsequent commands. See 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
├── artifacts.py # PersonaVectorStore (local) + HFPersonaVectorStore (Hub)
├── analysis.py # aligned dataset loading, PCA, cosine similarity, clustering
├── plots/ # Plotly figures
├── probes.py # linear probes over saved persona vectors
├── steering.py # experimental steering vectors
└── parser.py # CLI parser
See the docs for API details.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file persona_vectors-0.8.3.tar.gz.
File metadata
- Download URL: persona_vectors-0.8.3.tar.gz
- Upload date:
- Size: 43.1 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: uv/0.11.14 {"installer":{"name":"uv","version":"0.11.14","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}
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
f0519846b3712865bd2562cd239df05ddd006ac3d1e73e5ec5a6c860aaed5b2e
|
|
| MD5 |
d9acb0eab9b99d9be62a0d8b14f03bb1
|
|
| BLAKE2b-256 |
c01d472284f43e2a276a035e9e3de08a92654945193699598def6d6a2aa74c96
|
File details
Details for the file persona_vectors-0.8.3-py3-none-any.whl.
File metadata
- Download URL: persona_vectors-0.8.3-py3-none-any.whl
- Upload date:
- Size: 53.1 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: uv/0.11.14 {"installer":{"name":"uv","version":"0.11.14","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}
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
2feeaf45b071ed417d88add48a1012455c8027e4f839e99658a9808c26786b8a
|
|
| MD5 |
cfbdb11bb5d153606e9d300bcc403129
|
|
| BLAKE2b-256 |
60d1a38dc354718310122cd5d3de63e3aa9060490c8db4c2eadb1d4985684796
|