This post has some ablation results around the thesis of the ICML 2024 Mech. Interp. workshop 1st prize winning paper: The Geometry of Categorical and Hierarchical Concepts in Large Language ModelsThe main takeaway is that the orthogonality they observe in categorical and hierarchical concepts occurs practically everywhere, even at places where it really should not.
They split the computation of a large language model (LLM) as:
P(y∣x)=exp(λ(x)⊤γ(y))∑y′∈Vocabexp(λ(x)⊤γ(y′))
where: - λ(x) is the context embedding for input x (last token’s residual after last layer), - γ(y) is the unembedding vector for output y.
Next, to align the embedding and unembedding spaces and make the Euclidean inner product a causal one (see the paper for details), a transformation using the covariance matrix of the unembedding vectors is applied:
g(y)=Cov(γ)−1/2(γ(y)−E[γ])
where γ is the unembedding vector, E[γ] is the expected unembedding vector, and Cov is the covariance matrix of γ.
Now, for any concept W, its vector representation ℓW is defined to be one that follows these two constraints:
Given such a vector representation lw for binary concepts (where ℓw1−ℓw0 is the linear representation of w0⇒w1), the following orthogonality relations hold:
ℓw⊥(ℓz−ℓw)for z≺w
I’m skipping some notation here, but this says that for hierarchical concepts mammal ≺ animal, we have ℓanimal⊥(ℓmammal−ℓanimal).
ℓw⊥(ℓz1−ℓz0)for {z0,z1}≺w
Similarly, this means ℓanimal⊥(ℓmammal−ℓreptile).
(ℓw1−ℓw0)⊥(ℓz1−ℓz0)for {z0,z1}≺{w0,w1}
(ℓw1−ℓw0)⊥(ℓw2−ℓw1)for w2≺w1≺w0
Also, they show that categorical concepts form simplices in the transformed representation space. For each of these theorems, they give concrete proofs and provide experimental evidence on GPT-4 generated data and Gemma representations for animal categories and plants. They start with a dataset that looks like:
To study concepts that do not form such semantic categories and hierarchies, we add the following two datasets and play around with their codebase:
First, an “emotions” dictionary for various kinds of emotions split in various top-level emotions. Note that these categories are not expected to be orthogonal (for instance, joy and sadness should be anti-correlated). We create this via a simple call to ChatGPT.
Next, we add a “nonsense” dataset that has five completely random categories where each category is defined by a lot (order of 100) of totally random words completely unrelated to the top-level categories. This will help us get directions for random nonsensical concepts (again, via a ChatGPT call):
Hierarchical features are orthogonal—but so are semantic opposites!?
Now, let’s look at their main experimental results (for animals):
And this is what we get for emotions:
While this seems okay, look at the following plot where we just look at joy and sadness in the span of sadness and all emotions:
Sadness and joy are semantic opposites, so one should expect the vectors to be anti-correlated rather than orthogonal. Also, here’s the same plot but for completely random, non-sensical concepts:
It seems like their orthogonality results, while true for hierarchical concepts, are also true for semantically opposite concepts and totally random concepts. 🤔
Categorical features form simplices—but so do totally random ones!?
Here is the simplex they find animal categories to form:
And this is what we get for completely random concepts:
Thus, while categorical concepts form simplices, so do completely random, non-sensical concepts.
Orthogonality being ubiquitous in high dimensions
Because a model’s representation space is quite high-dimensional (2048 in the case of Gemma), and k independent random vectors are expected to be almost orthogonal in high-dimensional spaces. Multiple concrete proofs of the same are given here, but here’s a quick intuitive sketch:
Let v1,v2,…,vk be k random vectors in Rn with their components distributed independently and uniformly on the unit sphere. The inner product between two vectors vi and vj is given by:
⟨vi,vj⟩=n∑l=1vi,lvj,l
and has the following variance:
Var[⟨vi,vj⟩]=1n
Thus, as n (the number of dimensions) increases, the variance tends to zero:
limn→∞Var[⟨vi,vj⟩]=0
This implies that, in high dimensions, random vectors are almost orthogonal with high probability:
⟨vi,vj⟩≈0 for i≠j
Discussion and Future Work
A transformation where opposite concepts seem orthogonal doesn’t seem good for studying models. It breaks our semantic model of associating directions with concepts and makes steering both ways impossible.
As for categorical features forming simplices in the representation space, this claim isn’t surprising because every single thing seems to form simplices, even totally random concepts.
There are lots of ways of assigning a direction or a vector to a given concept or datapoint, and it is unclear if the vectors thus obtained are correct or uniquely identifiable.
Here are some of the questions this leaves us with and ones that we’d be very excited to work on in the near future (contact us to collaborate!):
A framework on how to think about representations that unifies how they’re obtained (contrastive activations, PCA, SAE, etc.), how they’re used (by the model), and how they can be used to control (eg. via steering vectors).
How to figure out how well a given object (a direction, a vector, or even a black-box function over model parameters) represents a given human-interpretable concept or feature.
If orthogonality and simplices are too universal and not specific enough to study the geometry of categorical and hierarchical concepts, then what is a good lens or theory to do so?
The Geometry of Feelings and Nonsense in Large Language Models
This post has some ablation results around the thesis of the ICML 2024 Mech. Interp. workshop 1st prize winning paper: The Geometry of Categorical and Hierarchical Concepts in Large Language Models The main takeaway is that the orthogonality they observe in categorical and hierarchical concepts occurs practically everywhere, even at places where it really should not.
Overview of the original paper
A lot of the intuition and math around why they do what they do is shared in their previous work called The Linear Representation Hypothesis and the Geometry of Large Language Models, but let’s quickly go over what the paper’s core idea is:
They split the computation of a large language model (LLM) as:
P(y∣x)=exp(λ(x)⊤γ(y))∑y′∈Vocabexp(λ(x)⊤γ(y′))
where:
- λ(x) is the context embedding for input x (last token’s residual after last layer),
- γ(y) is the unembedding vector for output y.
Next, to align the embedding and unembedding spaces and make the Euclidean inner product a causal one (see the paper for details), a transformation using the covariance matrix of the unembedding vectors is applied:
g(y)=Cov(γ)−1/2(γ(y)−E[γ])
where γ is the unembedding vector, E[γ] is the expected unembedding vector, and Cov is the covariance matrix of γ.
Now, for any concept W, its vector representation ℓW is defined to be one that follows these two constraints:
P(W=1∣ℓ+αℓW)>P(W=1∣ℓ)∀α>0 P(Z∣ℓ+αℓW)=P(Z∣ℓ)for off-target conceptZ
Given such a vector representation lw for binary concepts (where ℓw1−ℓw0 is the linear representation of w0⇒w1), the following orthogonality relations hold:
ℓw⊥(ℓz−ℓw)for z≺w
I’m skipping some notation here, but this says that for hierarchical concepts mammal ≺ animal, we have ℓanimal⊥(ℓmammal−ℓanimal).
ℓw⊥(ℓz1−ℓz0)for {z0,z1}≺w
Similarly, this means ℓanimal⊥(ℓmammal−ℓreptile).
(ℓw1−ℓw0)⊥(ℓz1−ℓz0)for {z0,z1}≺{w0,w1}
(ℓw1−ℓw0)⊥(ℓw2−ℓw1)for w2≺w1≺w0
Also, they show that categorical concepts form simplices in the transformed representation space. For each of these theorems, they give concrete proofs and provide experimental evidence on GPT-4 generated data and Gemma representations for animal categories and plants. They start with a dataset that looks like:
Ablations
To study concepts that do not form such semantic categories and hierarchies, we add the following two datasets and play around with their codebase:
First, an “emotions” dictionary for various kinds of emotions split in various top-level emotions. Note that these categories are not expected to be orthogonal (for instance, joy and sadness should be anti-correlated). We create this via a simple call to ChatGPT.
Next, we add a “nonsense” dataset that has five completely random categories where each category is defined by a lot (order of 100) of totally random words completely unrelated to the top-level categories. This will help us get directions for random nonsensical concepts (again, via a ChatGPT call):
Hierarchical features are orthogonal—but so are semantic opposites!?
Now, let’s look at their main experimental results (for animals):
And this is what we get for emotions:
While this seems okay, look at the following plot where we just look at joy and sadness in the span of sadness and all emotions:
Sadness and joy are semantic opposites, so one should expect the vectors to be anti-correlated rather than orthogonal. Also, here’s the same plot but for completely random, non-sensical concepts:
It seems like their orthogonality results, while true for hierarchical concepts, are also true for semantically opposite concepts and totally random concepts. 🤔
Categorical features form simplices—but so do totally random ones!?
Here is the simplex they find animal categories to form:
And this is what we get for completely random concepts:
Thus, while categorical concepts form simplices, so do completely random, non-sensical concepts.
Orthogonality being ubiquitous in high dimensions
Because a model’s representation space is quite high-dimensional (2048 in the case of Gemma), and k independent random vectors are expected to be almost orthogonal in high-dimensional spaces. Multiple concrete proofs of the same are given here, but here’s a quick intuitive sketch:
Let v1,v2,…,vk be k random vectors in Rn with their components distributed independently and uniformly on the unit sphere. The inner product between two vectors vi and vj is given by:
⟨vi,vj⟩=n∑l=1vi,lvj,l
and has the following variance:
Var[⟨vi,vj⟩]=1n
Thus, as n (the number of dimensions) increases, the variance tends to zero:
limn→∞Var[⟨vi,vj⟩]=0
This implies that, in high dimensions, random vectors are almost orthogonal with high probability:
⟨vi,vj⟩≈0 for i≠j
Discussion and Future Work
A transformation where opposite concepts seem orthogonal doesn’t seem good for studying models. It breaks our semantic model of associating directions with concepts and makes steering both ways impossible.
As for categorical features forming simplices in the representation space, this claim isn’t surprising because every single thing seems to form simplices, even totally random concepts.
There are lots of ways of assigning a direction or a vector to a given concept or datapoint, and it is unclear if the vectors thus obtained are correct or uniquely identifiable.
Here are some of the questions this leaves us with and ones that we’d be very excited to work on in the near future (contact us to collaborate!):
A framework on how to think about representations that unifies how they’re obtained (contrastive activations, PCA, SAE, etc.), how they’re used (by the model), and how they can be used to control (eg. via steering vectors).
How to figure out how well a given object (a direction, a vector, or even a black-box function over model parameters) represents a given human-interpretable concept or feature.
If orthogonality and simplices are too universal and not specific enough to study the geometry of categorical and hierarchical concepts, then what is a good lens or theory to do so?