Steering Llama 2 via Contrastive Activation Addition

Nina Panickssery, Nick Gabrieli, Julian Schulz, Meg Tong, Evan Hubinger +1 more
12/9/2023
1,429 citations
cs.CLcs.AIcs.LG

Official code: nrimsky/CAA (263 stars, Jupyter Notebook, MIT, PyTorch, last commit 2024-05-23).

Abstract

We introduce Contrastive Activation Addition (CAA), an innovative method for steering language models by modifying their activations during forward passes. CAA computes "steering vectors" by averaging the difference in residual stream activations between pairs of positive and negative examples of a particular behavior, such as factual versus hallucinatory responses.

Show full abstract

During inference, these steering vectors are added at all token positions after the user's prompt with either a positive or negative coefficient, allowing precise control over the degree of the targeted behavior. We evaluate CAA's effectiveness on Llama 2 Chat using multiple-choice behavioral question datasets and open-ended generation tasks. We demonstrate that CAA significantly alters model behavior, is effective over and on top of traditional methods like finetuning and system prompt design, and minimally reduces capabilities. Moreover, we gain deeper insights into CAA's mechanisms by employing various activation space interpretation methods. CAA accurately steers model outputs and sheds light on how high-level concepts are represented in Large Language Models (LLMs).

View on arXivView PDF

Code Implementations(1)

nrimsky/CAAOfficial100%
PyTorchMIT

Steering Llama 2 with Contrastive Activation Addition

26371Jupyter Notebook, PythonSep 25, 20232 years agoMIT
llama2pytorch

Similar Papers

Cite this paper

@article{panickssery2023steering,
  title  = {Steering Llama 2 via Contrastive Activation Addition},
  author = {Nina Panickssery and Nick Gabrieli and Julian Schulz and Meg Tong and Evan Hubinger and Alexander Matt Turner},
  year   = {2023},
  eprint = {2312.06681},
  archivePrefix = {arXiv},
  url    = {http://arxiv.org/abs/2312.06681v4}
}

Add a badge to your README

Shows whether official code is linked for this paper.

Code of Paper badge
[![Code of Paper](https://codeofpaper.com/badge/2312.06681.svg)](https://codeofpaper.com/paper/2312.06681)

Discussion