Skip to content

modulabs/psyctl

 
 

Repository files navigation

PSYCTL Logo

PSYCTL - LLM Personality Steering Tool

⚠️ Project Under Development This project is currently under development and only supports limited functionality. Please check the release notes for stable features.

A project by Persona Lab at ModuLabs.

A tool that supports steering LLMs to exhibit specific personalities. The goal is to automatically generate datasets and work with just a model and personality specification.


📚 Documentation

Core Guides

Additional Resources


📖 User Guide

🚀 Quick Start

Installation

Basic Installation (CPU Version)

# Install uv (Windows)
Invoke-WebRequest -Uri "https://astral.sh/uv/install.ps1" -OutFile "install_uv.ps1"
& .\install_uv.ps1

# Project setup
uv venv
& .\.venv\Scripts\Activate.ps1
uv sync

Installation in Google Colab

# Install directly from GitHub
!pip install git+https://github.com/modulabs-personalab/psyctl.git

# Or install from specific branch
!pip install git+https://github.com/modulabs-personalab/psyctl.git@main

# Set environment variables
import os
os.environ['HF_TOKEN'] = 'your_huggingface_token_here'
os.environ['PSYCTL_LOG_LEVEL'] = 'INFO'

# Usage example
from psyctl import DatasetBuilder, P2, LLMLoader

GPU Acceleration Installation (CUDA Support)

# Install CUDA-enabled PyTorch after basic installation
uv pip install torch --index-url https://download.pytorch.org/whl/cu121

# Verify installation
python -c "import torch; print('CUDA available:', torch.cuda.is_available())"

Important: The transformers package has torch as a dependency, so running uv sync will automatically install the CPU version. For GPU usage, you need to run the CUDA installation command above again.

Basic Usage

# 1. Generate dataset
psyctl dataset.build.steer \
  --model "google/gemma-3-27b-it" \
  --personality "Extroversion, Machiavellism" \
  --output "./dataset/steering"

# 2. Upload dataset to HuggingFace Hub (optional)
psyctl dataset.upload \
  --dataset-file "./dataset/steering/steering_dataset_*.jsonl" \
  --repo-id "username/extroversion-steering"

# 3. Extract steering vector
psyctl extract.steering \
  --model "meta-llama/Llama-3.2-3B-Instruct" \
  --layer "model.layers[13].mlp.down_proj" \
  --dataset "./dataset/steering" \
  --output "./steering_vector/out.safetensors"

# 4. Steering experiment
psyctl steering \
  --model "meta-llama/Llama-3.2-3B-Instruct" \
  --steering-vector "./steering_vector/out.safetensors" \
  --input-text "Tell me about yourself"

# 5. Inventory test
psyctl benchmark \
  --model "meta-llama/Llama-3.2-3B-Instruct" \
  --steering-vector "./steering_vector/out.safetensors" \
  --inventory IPIP-NEO

📋 Commands Overview

PSYCTL provides 5 main commands. See documentation links above for detailed usage.

Command Description Documentation
dataset.build.steer Generate steering datasets Guide
dataset.upload Upload datasets to HuggingFace Guide
extract.steering Extract steering vectors Guide
steering Apply steering to generation Guide
benchmark Test with psychological inventories Coming soon

📊 Supported Inventories

Inventory Domain License Notes
IPIP-NEO-300/120 Big Five Public Domain Full & short forms
NPI-40 Narcissism Free research use Forced-choice
PNI-52 Pathological narcissism CC-BY-SA Likert 1–6
NARQ-18 Admiration & Rivalry CC-BY-NC Two sub-scales
MACH-IV Machiavellianism Public Domain Likert 1–5
LSRP-26 Psychopathy Public Domain Primary & secondary
PPI-56 Psychopathy Free research use Short form

⚙️ Configuration

PSYCTL uses environment variables for configuration. Required:

# Get your token from https://huggingface.co/settings/tokens
export HF_TOKEN="your_huggingface_token_here"  # Linux/macOS
$env:HF_TOKEN = "your_token_here"              # Windows

For detailed configuration options (directories, performance tuning, logging), see Configuration Guide.

📝 Complete Workflow Example

# 1. Generate dataset for extroversion personality
# Set batch size for optimal performance
export PSYCTL_INFERENCE_BATCH_SIZE="16"

psyctl dataset.build.steer \
  --model "meta-llama/Llama-3.2-3B-Instruct" \
  --personality "Extroversion" \
  --output "./dataset/extroversion" \
  --limit-samples 1000

# 2. Extract steering vector
psyctl extract.steering \
  --model "meta-llama/Llama-3.2-3B-Instruct" \
  --layer "model.layers[13].mlp.down_proj" \
  --dataset "./dataset/extroversion" \
  --output "./steering_vector/extroversion.safetensors"

# 3. Apply steering to generate text
psyctl steering \
  --model "meta-llama/Llama-3.2-3B-Instruct" \
  --steering-vector "./steering_vector/extroversion.safetensors" \
  --input-text "Tell me about yourself"

# 4. Measure personality changes
psyctl benchmark \
  --model "meta-llama/Llama-3.2-3B-Instruct" \
  --steering-vector "./steering_vector/extroversion.safetensors" \
  --inventory IPIP-NEO

More Examples:

  • See examples/ directory for Python library usage
  • Check documentation links above for detailed guides

🤝 Contributing

Contributions are welcome! See Contributing Guide for:

  • Development environment setup
  • Code style and standards
  • Testing guidelines
  • Pull request process

Key papers


Sponsors

This project is sponsored by Caveduck.io

Caveduck.io

About

페르소나 LAB의 프로젝트 결과물 아카이빙입니다.

Resources

Contributing

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Python 97.6%
  • PowerShell 2.3%
  • Jinja 0.1%