Where LLMs Store Facts


Where LLMs Store Facts

Corey
Suppose we give a language model the phrase, “Michael Jordan plays the sport of blank,” and it predicts “basketball.” That suggests the model contains some internal representation connecting a specific person with a specific sport. More broadly, anyone who has used a large language model gets the sense that it has absorbed an enormous number of facts, so a natural question is: where do those facts live, and how are they represented?

Hope
Researchers at Google DeepMind studied that question using examples of athletes and their sports. A complete mechanistic explanation is still unsolved, but their partial results point toward a broad conclusion: factual information appears to be associated especially with the multi-layer perceptrons, or MLPs, inside transformer networks.

Corey
That is the focus today. We have already looked at transformers and at attention, which lets different token representations exchange information. MLPs make up the other major part of the network. Their computation is comparatively simple—essentially two matrix multiplications with a basic nonlinear function between them—but understanding what those computations mean is much harder.

Hope
Let’s quickly place the MLP in the larger language-model pipeline. The model receives text, breaks it into tokens—usually words or pieces of words—and turns each token into a high-dimensional vector. That sequence of vectors repeatedly passes through attention, normalization steps, and MLPs.

Corey
After many such layers, each vector should contain enough information to help predict the next token. It has absorbed information from the surrounding context through attention, as well as general knowledge encoded in the model’s learned parameters. The vector associated with a token therefore represents much more than the isolated meaning of that token.

Hope
A key mental model is that these vectors live in a very high-dimensional space, where different directions can represent different features. A familiar example comes from word embeddings: subtract the embedding for “man” from “woman,” then add that difference to “uncle,” and you land near the corresponding feminine noun. In that sense, a direction can encode something like gender.

Corey
The same general idea could apply to many other features. In our toy example, we’ll imagine one direction representing the first name Michael, another nearly perpendicular direction representing the last name Jordan, and a third direction representing basketball.

Hope
To make that precise, imagine taking a processed vector and computing its dot product with the “Michael” direction. If the dot product is one, we’ll say the vector encodes the first name Michael. If it is zero or negative, we’ll say it does not substantially align with that direction. We’ll use the same simplified interpretation for the Jordan and basketball directions.

Corey
A vector representing the full name Michael Jordan would therefore have a dot product of one with both the Michael direction and the Jordan direction. Because the name spans two tokens, we also have to assume that an earlier attention block has passed information from one token to the other, so that the vector at the relevant position represents both names together.

Hope
Once that information is present in one vector, the MLP processes it independently. Every token vector in the sequence goes through the same short series of operations, and all of those computations happen in parallel. The vectors do not communicate with one another during this MLP step, which means we can understand the block by studying a single vector.

Corey
The MLP’s output is another vector with the same dimension as the input. That output is then added to the original vector, and the sum becomes the vector flowing out of the block. In our example, if the input vector encodes Michael and Jordan, the MLP should produce an additional basketball direction, which gets added to that vector.

Hope
The first operation is an up-projection: multiplying the input vector by a large learned matrix. Let’s call the input vector E and the matrix W up. Matrix multiplication can be understood row by row, because each row takes a dot product with E and produces one component of the intermediate vector.

Corey
Imagine the first row of W up is exactly the Michael direction. Then the first output component is one when E represents Michael, and zero or negative when it does not. But we can make the row more interesting: suppose it equals the Michael direction plus the Jordan direction, which we’ll write as M plus J.

Hope
The dot product distributes across addition, so that row produces M dot E plus J dot E. If E encodes both Michael and Jordan, the result is two. If it encodes only one of them, the result is one, and for unrelated inputs it could be smaller than one or even negative.

Corey
Each row can be thought of as asking a different question about the input vector. One row might probe for Michael, another for Jordan, and others might probe for entirely different combinations of features. In GPT-3, the up-projection has just under fifty thousand rows, so it produces nearly fifty thousand intermediate values.

Hope
The matrix multiplication commonly includes a learned bias vector as well. For the Michael-plus-Jordan example, suppose the first component of the bias is negative one. Then the relevant intermediate value becomes the dot product with M plus J, minus one.

Corey
That gives us a useful behavior. The value is positive when both Michael and Jordan are present, but zero or negative when only one—or neither—is present. The bias effectively sets a threshold that helps the computation respond to the combination rather than merely to either feature independently.

Hope
Why is that threshold important? Because the first matrix operation is linear. Without a nonlinear step, a detector for Michael plus Jordan would also respond in a graded way to combinations like Michael plus Phelps or Alexis plus Jordan, even though those combinations represent different people.

Corey
The nonlinear step solves that problem. A common choice is the rectified linear unit, or ReLU. ReLU leaves positive values unchanged and maps every negative value to zero. So in our simplified example, a value of one for Michael Jordan remains one, while zero or negative values become zero.

Hope
That makes the neuron behave somewhat like an AND gate: it activates when the relevant combination of features is present. Modern models often use a smoother variant called GELU, but for understanding the basic mechanism, ReLU is easier to picture.

Corey
When people talk about a transformer’s neurons, they generally mean these intermediate values after the linear operation and nonlinear function. A neuron is active when its value is positive and inactive when its value is zero. The familiar neural-network diagram with dots and connecting lines is representing this combination of matrix multiplication followed by a term-by-term nonlinear function.

Hope
Now comes the second matrix multiplication, called the down projection because it maps the large intermediate vector back down to the original embedding dimension. We’ll call its matrix W down, and it can also include a learned bias, B down.

Corey
For this multiplication, it is more useful to think column by column. Each column has the same dimension as the original embedding space, so each column can be viewed as a direction in that space. The output is the sum of these columns, each multiplied by the activation of its corresponding neuron, plus the down-projection bias.

Hope
Suppose the first column of W down is the basketball direction. If the first neuron activates for Michael Jordan, that column contributes basketball to the output. If the neuron is inactive and has value zero, that column contributes nothing.

Corey
A column could contain more than just basketball, too. It could encode basketball along with other features the model has learned to associate with the detected pattern. Every other column specifies what gets added when its corresponding neuron is active. The down-projection bias is added every time, regardless of the neuron values; its precise role is harder to interpret, so we can set it aside in this toy explanation.

Hope
Finally, the MLP’s result is added to the vector that entered the block. So if that input represented Michael Jordan, the relevant neuron activates, the down projection contributes the basketball direction, and the output vector now represents the name together with basketball. Again, this same process occurs independently and in parallel for every token position.

Corey
In compact form, the MLP is two learned matrix products, each with a bias, separated by a simple nonlinear function. It is structurally similar to the basic neural network used to recognize handwritten digits, but here it is one component inside a much larger transformer, and interpreting it depends on understanding information as directions in a high-dimensional space.

Hope
There is also a useful parameter-counting perspective. In GPT-3, the up-projection has just under fifty thousand rows, and each row has 12,288 parameters. That gives about 604 million parameters for the up matrix. The down matrix has the same number, so the two matrices together contain roughly 1.2 billion parameters in one MLP.

Corey
GPT-3 has 96 distinct MLP blocks. Across all of them, the MLP parameters add up to about 116 billion—around two-thirds of the network’s total. The remaining parameters include attention, embeddings, and unembedding. Together, those components give the advertised total of about 175 billion parameters, while normalization parameters and biases make up only a comparatively small portion.

Hope
But we should be careful not to take the Michael Jordan example as a literal description of how real models store facts. Mathematically, rows of the first matrix do define directions that measure how much an input aligns with them, and columns of the second matrix define what gets added when a neuron is active.

Corey
However, evidence suggests that individual neurons rarely correspond to one clean feature such as Michael Jordan. A possible explanation is an idea called superposition. It may help explain both why these models are difficult to interpret and why their performance scales so effectively.

Hope
Here is the basic intuition. In an n-dimensional space, if every feature must be represented by a direction exactly perpendicular to every other feature, you can fit at most n such directions. That limit is essentially what the mathematical notion of dimension means.

Corey
But suppose we tolerate a little interference and allow directions to be nearly perpendicular rather than exactly perpendicular—for example, angles between 89 and 91 degrees. In two or three dimensions, that barely creates extra room. In high dimensions, though, the number of nearly perpendicular vectors can grow dramatically.

Hope
A rough illustration uses 10,000 random vectors in a 100-dimensional space. Even before optimization, random vectors tend to have angles near 90 degrees. If you iteratively adjust them to become more perpendicular, their pairwise angles can be concentrated between 89 and 91 degrees, despite there being 100 times as many vectors as dimensions.

Corey
The Johnson-Lindenstrauss lemma gives a more formal perspective: the number of vectors that can fit while remaining nearly perpendicular grows exponentially with the number of dimensions. For a language model, that means a high-dimensional space may represent far more independent ideas than the number of dimensions would suggest.

Hope
That could help explain why increasing model size can have such a large effect. A space with ten times as many dimensions can store substantially more than ten times as many nearly independent features. The same reasoning applies not only to the embedding space, but also to the large vector of neuron activations in the middle of an MLP.

Corey
So an MLP with about 50,000 neurons might not be probing only 50,000 features. It could use combinations of neurons to represent many more features. Under this superposition hypothesis, an individual fact or concept would not appear as one neuron lighting up; it might appear as a particular pattern across several neurons.

Hope
That is why interpreting these models is so challenging. The clean toy story—one neuron detects Michael Jordan and one output column adds basketball—is useful for understanding the computation, but real representations may be distributed across overlapping combinations of neurons.

Corey
Researchers studying interpretability use tools such as sparse autoencoders to try to recover those underlying features, even when they are superimposed across many neurons. That line of work is one way people investigate what the model may actually be representing internally.

Hope
So the main lesson is twofold. First, MLPs perform a simple sequence: an up projection, a nonlinear activation, and a down projection, followed by adding the result back to the original vector. Second, those simple operations can use high-dimensional representations to transform detected patterns into useful features—potentially including factual associations such as Michael Jordan and basketball.

Corey
And we should end with what comes next in the larger story. The transformer architecture has now been covered at a high level, though not every detail. The next major topic is training: backpropagation, the cost function used for language modeling, fine-tuning with reinforcement learning from human feedback, and scaling laws.

Hope
Exactly. Understanding the architecture tells us what the model computes, while understanding training explains how its parameters acquire those computations and associations in the first place.

Ask anything
We've read this whole study set, so questions about it get the best answers.