# 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**](https://arxiv.org/abs/2406.01506) *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](https://arxiv.org/abs/2311.03658), 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 \\mid x) = \\frac{\\exp(\\lambda(x)^\\top \\gamma(y))}{\\sum_{y' \\in \\text{Vocab}} \\exp(\\lambda(x)^\\top \\gamma(y'))}$$

where:  
- $\lambda(x)$ is the context embedding for input $x$ (last token's residual after last layer),  
- $\gamma(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) = \\text{Cov}(\\gamma)^{-1/2} (\\gamma(y) - \\mathbb{E}\[\\gamma\])$$

where $\gamma$ is the unembedding vector, $\mathbb{E}[\gamma]$ is the expected unembedding vector, and $\text{Cov}$ is the covariance matrix of $\gamma$.

Now, for any concept $W$, its vector representation $\ell_W$ is defined to be:

$$\\bar{\\ell}\_w = (\\tilde{g}\_w^\\top\\mathbb{E}(g\_w)) \\tilde{g}\_w, \\text{where} \\,\\,\\,\\, \\tilde{g}\_w = \\frac{\\text{Cov}(g\_w)^\\dagger\\mathbb{E}(g\_w)}{\\|\\text{Cov}(g\_w)^\\dagger\\mathbb{E}(g\_w)\\|\_2}$$

Given such a vector representation $l_w$ for binary concepts (where $\ell_{w_1} - \ell_{w_0}$ is the linear representation of $w_0 \Rightarrow w_1$), the following orthogonality relations hold:

*   $\ell_w \perp (\ell_z - \ell_w) \quad \text{for } z \prec w$
    
    I'm skipping some notation here, but this says that for hierarchical concepts mammal $\prec$ animal, we have $\ell_{animal} \perp (\ell_{mammal} - \ell_{animal})$.
    
*   $\ell_w \perp (\ell_{z_1} - \ell_{z_0}) \quad \text{for } \{z_0, z_1\} \prec w$
    
    Similarly, this means $\ell_{animal} \perp (\ell_{mammal} - \ell_{reptile})$.
    
*   $(\ell_{w_1} - \ell_{w_0}) \perp (\ell_{z_1} - \ell_{z_0}) \quad \text{for } \{z_0, z_1\} \prec \{w_0, w_1\}$
*   $(\ell_{w_1} - \ell_{w_0}) \perp (\ell_{w_2} - \ell_{w_1}) \quad \text{for } w_2 \prec w_1 \prec w_0$

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:

    animals = {
        "mammal": ["beaver", "panther", "lion", "llama", "colobus", ... ], 
        "bird": ["wigeon", "parrot", "albatross", "cockatoo", "magpie", ... ], 
        "fish": ["snapper", "anchovy", "moonfish", "herring", ... ], 
        "amphibian": ["bullfrog", "siren", "toad", "treefrog", ...], 
        "insect": ["mayfly", "grasshopper", "bedbug", "silverfish", ...]
    	}

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](https://github.com/KihoPark/LLM_Categorical_Hierarchical_Representations):

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.

    emotions = {
       'joy': ['mirth', 'thrill', 'bliss', 'relief', 'admiration', ...],
       'sadness': ['dejection', 'anguish', 'nostalgia', 'melancholy', ...],
       'anger': ['displeasure', 'spite', 'irritation', 'disdain', ...],
       'fear': ['nervousness', 'paranoia', 'discomfort', 'helplessness', ...],
       'surprise': ['enthrallment', 'unexpectedness', 'revitalization', ...],
       'disgust': ['detestation', 'displeasure', 'prudishness', 'disdain', ...]
    	}

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):

    nonsense = {
       "random 1": ["toaster", "penguin", "jelly", "cactus", "submarine", ...],
       "random 2": ["sandwich", "yo-yo", "plank", "rainbow", "monocle", ...],
       "random 3": ["kiwi", "tornado", "chopstick", "helicopter", "sunflower", ...],
       "random 4": ["ocean", "microscope", "tiger", "pasta", "umbrella", ...],
       "random 5": ["banjo", "skyscraper", "avocado", "sphinx", "teacup", ...]
    }

Hierarchical features are orthogonal - but so are semantic opposites!?
======================================================================

Now, let's look at their main experimental results (for animals):

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

$\ell_{animal} \perp (\ell_{mammal} - \ell_{animal})$

And this is what we get for emotions:

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

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:

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

Should we really have joy so un-correlated with sadness?

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:

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

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:

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

A plot from the original paper.

And this is what we get for completely random concepts:

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

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](https://math.stackexchange.com/questions/995623/why-are-randomly-drawn-vectors-nearly-perpendicular-in-high-dimensions), but here's a quick intuitive sketch:

Let $\mathbf{v}_1, \mathbf{v}_2, \dots, \mathbf{v}_k$ be $k$ random vectors in $\mathbb{R}^n$ with their components distributed independently and uniformly on the unit sphere. The inner product between two vectors $\mathbf{v}_i$ and $\mathbf{v}_j$ is given by:

$$\\langle \\mathbf{v}\_i, \\mathbf{v}\_j \\rangle = \\sum_{l=1}^{n} v_{i,l} v_{j,l}$$

and has the following variance:

$$\\text{Var}\[\\langle \\mathbf{v}\_i, \\mathbf{v}\_j \\rangle\] = \\frac{1}{n}$$

Thus, as $n$ (the number of dimensions) increases, the variance tends to zero:

$$\\lim_{n \\to \\infty} \\text{Var}\[\\langle \\mathbf{v}\_i, \\mathbf{v}\_j \\rangle\] = 0$$

This implies that, in high dimensions, random vectors are almost orthogonal with high probability:

$$\\langle \\mathbf{v}\_i, \\mathbf{v}\_j \\rangle \\approx 0 \\text{ for } i \\neq j$$  
 

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

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?