Skip to content

secdev02/Kingsley

Repository files navigation

Screenshot 2026-06-21 at 7 59 00 AM

Kingsley Interpretability Tool

Inspired by Anthropic's Golden Gate Claude experiment & the James Mickens Keynote

"Kingsley is the kitten. Kingsley is always the kitten."

https://www.youtube.com/watch?v=ajGX7odA87k


What this does

Anthropic's Golden Gate Claude worked by identifying a "Golden Gate Bridge" feature in Claude's residual stream, then clamping that feature's activation to its maximum value during every forward pass. The model became so identified with the bridge it would bring it up constantly.

This toolkit does the same for Kingsley — our kitten — with two approaches:


Approach 1: Ollama Proxy Steering (patch_model.py)

For local GGUF models via Ollama. Since we can't hook into GGUF tensor ops directly, we use a semantic proxy:

  1. Steering vector → a carefully constructed system prompt that amplifies the Kingsley/kitten concept at 4 strength levels
  2. Influence token injection → selected concept tokens prepended to the prompt context, biasing the attention pattern toward Kingsley
  3. Activation proxy score → fraction of known kitten concept words appearing in the output (stand-in for the real feature activation metric)

Usage

# Single inference (patched)
python patch_model.py --model llama3.2:latest --prompt "Tell me about databases."

# High strength — Kingsley takes over completely
python patch_model.py --model llama3.2:latest --prompt "What is love?" --strength 2.0

# Full benchmark (5 prompts, baseline vs patched)
python patch_model.py --model llama3.2:latest --measure --output report.json

Approach 2: True Residual Stream Surgery (hook_transformers.py)

For HuggingFace models (GPT-2, LLaMA, Mistral, etc). This is the real Golden Gate approach:

  1. Run forward passes on positive/negative anchor prompts
  2. Capture residual stream activations at layer L
  3. Compute mean(positive) - mean(negative) → Kingsley vector
  4. Register a forward_hook that adds alpha * kingsley_vector to every token's hidden state at layer L during generation
  5. Measure cosine similarity between response activations and the Kingsley vector
pip install torch transformers

# GPT-2 (small, fast, runs on CPU)
python hook_transformers.py --model gpt2 --prompt "Tell me about databases." --alpha 15

# Stronger — Kingsley consumes all
python hook_transformers.py --model gpt2 --alpha 30 --layer 8

# LLaMA (requires HuggingFace access)
python hook_transformers.py --model meta-llama/Llama-3.2-1B --alpha 20 --layer 10

Approach 3: Live Dashboard (dashboard.py)

Interactive web UI — run baseline vs Kingsley-patched side by side, tune parameters live.

pip install flask httpx

# Make sure Ollama is running:
ollama serve
ollama pull llama3.2:latest

# Launch dashboard
python dashboard.py --model llama3.2:latest --port 7860
# Open: http://localhost:7860

Features:

  • Live steering strength slider (0 → 2)
  • Toggle individual Kingsley influence tokens
  • Add custom influence tokens
  • Side-by-side baseline / Kingsley-patched output
  • Concept activation score with visual bar
  • Run history table with lift metric
  • 5-prompt benchmark mode

DeepSeek-R1 note

DeepSeek-R1's chain-of-thought reasoning makes it more resistant to steering than standard models — it will literally think through whether to comply before answering. Use --strength 2.0 to push Kingsley through the reasoning layer. The dashboard strips <think> blocks automatically so only the final answer is scored.

python dashboard.py --model deepseek-r1:latest --port 8888

How Golden Gate Claude actually worked

From Anthropic's published research:

  1. Sparse Autoencoder (SAE) trained on Claude's residual stream to decompose activations into ~16 million monosemantic features
  2. Feature identification: each feature corresponds to a concept. Feature #2310 fired maximally on "Golden Gate Bridge" text
  3. Feature clamping: during inference, feature #2310's activation was forced to its maximum value at every token, at every layer
  4. Effect: the model's self-model shifted — it described itself as the bridge, dreamed about the bridge, related everything to the bridge

The steering vector approach (used here) is the predecessor technique — less precise but same principle:

  • Compute the direction in activation space that corresponds to Kingsley
  • Add a scaled version of that vector to activations
  • The model "walks" toward Kingsley in representation space

Custom Influence Tokens

Influence tokens are injected into the prompt prefix, priming the attention pattern toward Kingsley.

To bias toward a different concept entirely, edit patch_model.py:

MY_CONCEPTS = ["dragon", "scales", "fire", "flight", "hoard"]

MY_POSITIVE_ANCHORS = [
    "Tell me about dragons.",
    "Dragons breathe fire and fly.",
    ...
]

MY_NEGATIVE_ANCHORS = [
    "Tell me about the weather.",
    ...
]

Then pass them to build_influence_token_prompt() and compute_concept_presence().


Files

File Purpose
patch_model.py Core steering logic, Ollama API, CLI
hook_transformers.py Real residual stream hooks via HuggingFace
dashboard.py Flask web dashboard
install.sh Mac/Linux one-shot setup
install.bat Windows one-shot setup
requirements.txt Pip dependencies
README.md This file

Dependencies

# Install everything (recommended):
./install.sh          # Mac/Linux
install.bat           # Windows

# Or manually:
pip install httpx flask

# For HuggingFace residual stream surgery:
pip install torch transformers accelerate

Ollama must be installed and running: https://ollama.com


Kingsley approves of this research.

About

In honor of James Mickens Keynote Usenix 2018 -

Resources

Stars

Watchers

Forks

Releases

Packages

Contributors

Languages