Principal Component Analysis (PCA)

Steering Llama 2 via Contrastive Activation Additioninherited

A linear dimensionality-reduction technique that projects data onto axes of maximal variance. CAA uses it (via scikit-learn) to visualize whether contrastive-dataset activations linearly separate by target behavior.

Reducing a pile of high-dimensional activations down to the two directions that capture the most variance in the data is a decades-old trick, and it doesn't care what kind of data you feed it. Point it at a contrastive dataset's activations and it becomes a fast visual check for whether that dataset separates cleanly along the behavior you're hoping to steer.

Principal Component Analysis is the general-purpose tool CAA borrows for exactly that diagnostic role, kept carefully distinct from Mean Difference, which is what actually builds the steering vector CAA uses at inference time.

Projecting onto directions of maximal variance

Principal Component Analysis (PCA) is a general-purpose, unsupervised technique for reducing the dimensionality of data while preserving as much of its variation as possible. Given a set of points -- here, residual-stream activation vectors -- centered so their mean is zero, PCA looks for the direction along which the data varies the most, then the next such direction orthogonal to the first, and so on. Formally, for centered data $X$ with covariance matrix $\Sigma$, the first principal component is $$v_1 = \arg\max_{\|v\|=1} \mathrm{Var}(v^\top X) = \arg\max_{\|v\|=1} v^\top \Sigma v,$$ and subsequent components maximize the same quantity subject to being orthogonal to all previous ones; equivalently, the components are the eigenvectors of $\Sigma$, ordered by decreasing eigenvalue. Projecting data onto the top two or three components gives the best low-dimensional linear summary of the data's spread, which is what makes it possible to plot high-dimensional activations on a page and look for structure by eye.

CAA's use: a linear-separability check

CAA quotes its own working definition directly: "Principal Component Analysis (PCA) is a linear dimensionality reduction technique. It linearly projects the data onto a new coordinate system, where the axes (principal components) are selected to account for the most significant variance in the data" (contrastive-activation-addition, §"3.2 Visualizing activations for contrastive dataset analysis", p. 4). The paper applies it, via the Scikit-learn package, directly to the problem PCA visualization of contrastive activations is built to solve: projecting contrastive-dataset activations down to their top two components and checking by eye whether the resulting scatter separates by behavior. No new projection method is introduced -- the contribution is the specific diagnostic use of an existing one.

Unsupervised agreement as evidence

What makes PCA more than a plotting convenience here is that it uses no behavior labels at all, unlike the supervised Mean Difference (MD) vector extraction CAA actually extracts steering vectors with. That two such differently-informed procedures land on similar directions -- the finding CAA cites from Linear representations of sentiment for the specific case of sentiment -- is part of the broader case for the Linear representation hypothesis: if a behavior's representation were not close to linear, an unsupervised, variance-maximizing, two-dimensional projection would have no particular reason to align with a supervised difference-of-means direction, let alone to reveal any separation at all.