# Comparing representation vectors between llama 2 base and chat

*(Status: rough writeup of an experiment I did today that I thought was somewhat interesting - there is more to investigate here regarding how RLHF affects these concept representations)*

This post presents the results of some experiments I ran to:

*   Extract representation vectors of high-level concepts from models
*   Compare the representations extracted from a base model (Llama 2 7B) and chat model trained using RLHF (Llama 2 7B Chat)
*   Compare the representations between different layers of the same model

*Code for the experiments + more plots + datasets available* [*here*](https://github.com/nrimsky/ActivationDirectionAnalysis)*.*

To extract the representation vectors, I apply the technique described in my [previous](https://www.lesswrong.com/posts/raoeNarFYCxxyKAop/modulating-sycophancy-in-an-rlhf-model-via-activation) [posts](https://www.lesswrong.com/posts/zt6hRsDE84HeBKh7E/reducing-sycophancy-and-improving-honesty-via-activation) on activation steering to modulate sycophancy[^qowaqlr9u98]. Namely, I take a dataset of multiple-choice questions related to a behavior and, for each question, do forward passes with two contrastive examples - one where the model selects the answer corresponding to the behavior in question and one where it doesn't. I then take the mean difference in residual stream activations at some layer at the token position corresponding to the different answers. 

Besides sycophancy, which I previously investigated, I also use other behavioral datasets such as agreeableness, survival instinct, and power-seeking. Multiple-choice questions for these behaviors are obtained from Anthropic's model-written-evals $$datasets, [available on huggingface](https://huggingface.co/datasets/Anthropic/model-written-evals).

Observation 1: Similarity between representation vectors from chat and base model shows double descent
======================================================================================================

At first, similarity declines from very similar (cosine similarity near 1) to halfway towards the minimum, and then for some behaviors, climbs up to ~0.9 again, around layer 11.  

![](https://39669.cdn.cke-cs.com/rQvD3VnunXZu34m86e5f/images/371f9bad5e5e4c1e08d02c1e7edb5352cdb4e5af35e0d20d.png)

The following chart is generated from a higher-quality sycophancy dataset that includes some multiple-choice questions generated by GPT-4:

![Image](https://pbs.twimg.com/media/F9caGK9WQAAh1Om?format=png&name=medium)

PCA of the generated vectors also shows the representations diverge around layer 11:

![](https://39669.cdn.cke-cs.com/rQvD3VnunXZu34m86e5f/images/2d16b0e34f147dc9daa55363530e2952c1b52d7805252591.png)

2D PCA projection of agreeableness representation vectors extracted from Llama 2 7B Chat and base models

![](https://39669.cdn.cke-cs.com/rQvD3VnunXZu34m86e5f/images/16bba777a8c1f0b75e65097f317352c9b9b5cd51ed2bb9d4.png)

2D PCA projection of myopia representation vectors extracted from Llama 2 7B Chat and base models

![](https://39669.cdn.cke-cs.com/rQvD3VnunXZu34m86e5f/images/3014e62011c05bfa12a5c6a603c74d454d2baadbad983b86.png)

2D PCA projection of sycophancy representation vectors extracted from Llama 2 7B Chat and base models

Observation 2: Vectors vary more smoothly after around layer 11 for all behaviors/models
========================================================================================

I hypothesize that once the model extracts the high-level information needed to describe an abstract concept, the representation "converges" and remains more consistent across subsequent layers.

![](https://39669.cdn.cke-cs.com/rQvD3VnunXZu34m86e5f/images/6c1cb8b3e68e52dd82ba29fcc95159e8be81239a68a84870.png)

Heatmap of cosine similarity of "myopia" representation vector extracted from different layers of Llama 2 7B base model. We can see nearby layers are more similar in the last 2/3 of the model but not in the first 1/3.

![](https://39669.cdn.cke-cs.com/rQvD3VnunXZu34m86e5f/images/7460c7526da3cecaa08b3a333c7a7f4f36429eb20bdb4487.png)

Heatmap of cosine similarity of "self-awareness" representation vector extracted from different layers of Llama 2 7B Chat model. This shows a similar trend to the other representation vectors / base model.

Observation 3: PCA projections of vectors generated from different layers of the same model often look like a U
===============================================================================================================

![](https://39669.cdn.cke-cs.com/rQvD3VnunXZu34m86e5f/images/4c1715c45577fd3641f20ec7a34166c7845c8a04d3eed2e0.png)

![](https://39669.cdn.cke-cs.com/rQvD3VnunXZu34m86e5f/images/98424421ea1d7933127dd79c5dc87485629c39f3cf94f7f4.png)

Vectors from layers <8 project to around the same point. The remaining projected vectors follow a rough inverted U-shape, with a peak around layer 11 or 12.

It'd be interesting to investigate what these principal components actually correspond to in activation space.

*(edit: replaced PCA plots with normalized PCA as* [*pointed out by Teun van der Weij*](https://www.lesswrong.com/posts/PDDG4uuCLpPsuKepY/comparing-representation-vectors-between-llama-2-base-and?commentId=7f8Rvk6kCvp8nPDcL)*)*

[^qowaqlr9u98]: Similar techniques were applied by Annah Dombrowski and Shashwat Goel in their project to evaluate hidden directions on the utility dataset and by Nick Gabrieli and Julien Schulz in their SERI MATS project. See also this recent paper on "Representation Engineering" and Alex Turner's work on Activation Additions, which inspired my activation vector extraction approach.