1. Home
  2. Explore
  3. Computer Science
  4. Where LLMs Store Facts

Study methods

Flashcards
Quiz
Fill in the blanks
Written test
Lesson
Notes
Podcast
Content

Where LLMs Store Facts

How Multilayer Perceptrons Store Information in Large Language Models

A large language model can often complete a sentence such as “Michael Jordan plays the sport of…” with “basketball.” This suggests that the model has learned an association between a particular person and a particular sport. The association is not stored as a sentence in an obvious database. Instead, it is encoded somewhere within the model’s enormous collection of numerical parameters.

Researchers do not yet have a complete mechanistic explanation of how factual knowledge is stored. However, evidence suggests that an important part of this knowledge may be represented inside structures called multilayer perceptrons, or MLPs. MLPs make up a major portion of transformer networks, alongside attention mechanisms.

The goal of this lesson is to understand:

  • How an MLP processes information
  • How an MLP could, in principle, represent the fact “Michael Jordan plays basketball”
  • Why nonlinear functions are necessary
  • How MLP parameters contribute to the size of a language model
  • Why facts may not be stored in individual neurons
  • How superposition allows networks to represent many more features than their apparent number of dimensions

The Overall Structure of a Transformer

A language model is trained to predict what token comes next in a sequence. A token is a small piece of text. It may be a whole word, part of a word, or another small text fragment.

The model first converts each token into a numerical vector called an embedding. Each embedding is a long list of numbers, so it can be viewed as a point in a high-dimensional space.

The sequence of token vectors then passes repeatedly through several kinds of operations:

  1. Attention, which allows vectors associated with different tokens to exchange information
  2. Normalization, which helps regulate the values flowing through the network
  3. Multilayer perceptrons, which independently transform each vector

After passing through many layers, each vector should contain enough information to help predict the next token. That information can include both:

  • Information from the surrounding context
  • General knowledge encoded in the model’s learned parameters

For example, the vector associated with the token “Jordan” may initially represent something related to that word. After attention and MLP processing, it may also contain information indicating that “Jordan” is part of the name “Michael Jordan,” that the person is an athlete, and that the relevant sport is basketball.

Why vectors can represent meaning

A useful way to think about these vectors is that different directions in the high-dimensional space can represent different features.

For instance, suppose the vector for “woman” is compared with the vector for “man.” The difference between those vectors may represent a direction associated with gender. Adding that direction to the vector for “uncle” could produce a vector near the one for “aunt.”

Symbolically, this relationship can be represented as:

woman−man≈aunt−uncle\text{woman} - \text{man} \approx \text{aunt} - \text{uncle}woman−man≈aunt−uncle

This does not mean that every word is literally stored as one simple direction. Rather, it illustrates the idea that relationships and attributes can correspond to directions in a vector space.

In a high-dimensional representation, a direction can encode a feature, relationship, or kind of meaning.

The vectors in a transformer do not remain simple representations of individual words. As they move through the network, they absorb information from the context and from the model’s learned knowledge. Ultimately, a vector must contain much richer information than the meaning of one token because it must help predict what comes next.

Attention is especially important for gathering information from other tokens. MLPs appear to provide additional computational capacity, including capacity that may be used to store factual associations.

Think About It

If attention allows different tokens to exchange information, why might the model also need MLPs? One answer is that gathering information and transforming or recalling information are different computational tasks. Attention helps a vector access context, while an MLP can process that vector and add learned features to it.

A Toy Representation of “Michael Jordan Plays Basketball”

To understand how an MLP could store a fact, consider a simplified example. The model will be assumed to represent three concepts using three directions in its high-dimensional space:

  • A direction for the first name Michael
  • A nearly perpendicular direction for the last name Jordan
  • A direction for basketball

The word “direction” here is mathematical. A vector’s alignment with a direction can be measured using a dot product.

Suppose a vector EEE is being processed. If its dot product with the “Michael” direction is 111, the vector strongly represents the idea of the first name Michael. If the dot product is 000 or negative, the vector does not meaningfully align with that direction.

The same reasoning applies to the “Jordan” and “basketball” directions.

If a vector represents the full name “Michael Jordan,” it should align with both the Michael direction and the Jordan direction. This requires an earlier attention operation to combine information from the two tokens. Since “Michael Jordan” consists of two tokens, the vector associated with the later token might receive information from the earlier one through attention.

For simplicity, let:

  • MMM represent the Michael direction
  • JJJ represent the Jordan direction
  • BBB represent the basketball direction
  • EEE represent the vector currently being processed

A vector representing “Michael Jordan” would satisfy approximately:

M⋅E=1M \cdot E = 1M⋅E=1

and

J⋅E=1J \cdot E = 1J⋅E=1

A vector representing only Michael might have a high value for M⋅EM \cdot EM⋅E but a low value for J⋅EJ \cdot EJ⋅E. A vector representing only Jordan would show the opposite pattern.

The MLP can use these alignments to detect the combined feature “Michael and Jordan.”

What an MLP Does

An MLP processes each vector independently. It does not allow vectors from different token positions to communicate with one another during this step. Every vector passes through the same sequence of operations in parallel.

If one sequence contains many token vectors, the MLP applies its computation separately to each one:

E1,E2,E3,…,EnE_1, E_2, E_3, \ldots, E_nE1​,E2​,E3​,…,En​

Each vector produces its own transformed output. The operation can therefore be understood by studying just one input vector EEE.

The basic MLP computation consists of:

  1. An upward matrix multiplication
  2. Addition of an upward bias
  3. A nonlinear function
  4. A downward matrix multiplication
  5. Addition of a downward bias
  6. Addition of the result back to the original vector

The final addition is called a residual connection. It means that the MLP does not completely replace the original vector. Instead, it adds a learned modification to it.

Step 1: The Up Projection

The first operation multiplies the input vector EEE by a large matrix. This matrix contains learned parameters. During training, those parameters are adjusted so that the network develops useful behaviors.

The matrix is often called the up projection matrix, written as WupW_{\text{up}}Wup​, because it maps the vector into a space with more dimensions.

The operation can be written as:

WupEW_{\text{up}}EWup​E

A matrix multiplication can be understood row by row. Each row of WupW_{\text{up}}Wup​ acts like a vector that takes a dot product with EEE. Therefore, each row asks a question about the input.

For example, suppose the first row of WupW_{\text{up}}Wup​ is the Michael direction MMM. The first output component would be:

M⋅EM \cdot EM⋅E

This value measures how strongly the input vector aligns with Michael.

Other rows can ask other questions. For example, suppose one row is:

M+JM + JM+J

Its dot product with EEE is:

(M+J)⋅E(M+J)\cdot E(M+J)⋅E

By the distributive property of the dot product:

(M+J)⋅E=M⋅E+J⋅E(M+J)\cdot E = M\cdot E + J\cdot E(M+J)⋅E=M⋅E+J⋅E

If EEE represents both Michael and Jordan, then each term could be approximately 111, giving:

M⋅E+J⋅E=1+1=2M\cdot E + J\cdot E = 1+1=2M⋅E+J⋅E=1+1=2

If EEE represents only Michael, the result might be about 111. If it represents neither, the result might be 000 or negative.

This row is therefore acting like a detector for the combined presence of Michael and Jordan, although it is still a linear detector and has an important limitation.

The upward bias

The up projection commonly includes a learned bias vector, written as BupB_{\text{up}}Bup​. The bias is added after the matrix multiplication:

WupE+BupW_{\text{up}}E + B_{\text{up}}Wup​E+Bup​

For the toy example, suppose the relevant bias component is −1-1−1. Then the component associated with the row M+JM+JM+J becomes:

M⋅E+J⋅E−1M\cdot E + J\cdot E - 1M⋅E+J⋅E−1

For a vector representing both Michael and Jordan, this could be:

1+1−1=11+1-1=11+1−1=1

For a vector representing only one of them, it could be:

1+0−1=01+0-1=01+0−1=0

For a vector representing neither, it could be negative.

This makes the value positive specifically when both name components are present.

Why the linear operation is not enough

The linear detector alone cannot perfectly represent an “and” condition. A row based on M+JM+JM+J may also respond to combinations such as:

  • Michael plus another last name
  • Another first name plus Jordan

The linear calculation measures additive alignment. It does not naturally express the idea that both specific features must be present and that unrelated combinations should be rejected.

A nonlinear function is needed to create a more selective response.

Step 2: The ReLU Nonlinearity

The intermediate vector is passed through a simple nonlinear function. A common choice is the rectified linear unit, or ReLU.

For a value xxx, ReLU is defined as:

ReLU⁡(x)=max⁡(0,x)\operatorname{ReLU}(x)=\max(0,x)ReLU(x)=max(0,x)

This means:

  • Negative values become 000
  • Zero remains 000
  • Positive values remain unchanged

In piecewise form:

ReLU⁡(x)={0,x≤0x,x>0\operatorname{ReLU}(x)= \begin{cases} 0, & x\leq 0\\ x, & x>0 \end{cases}ReLU(x)={0,x,​x≤0x>0​

Returning to the Michael Jordan detector:

M⋅E+J⋅E−1M\cdot E + J\cdot E - 1M⋅E+J⋅E−1

If the input represents both names, the value may be 111, so ReLU produces 111.

If the input represents only one name, the value may be 000, so ReLU produces 000.

If the input represents neither, the value may be negative, so ReLU also produces 000.

Thus, in this simplified example, ReLU converts the detector into something resembling an AND gate:

  • Michael present: yes
  • Jordan present: yes
  • Both present: activate
  • Otherwise: remain inactive

A neuron is said to be active when its post-nonlinearity value is positive. It is inactive when its value is zero.

When neural-network diagrams show a layer of dots connected to another layer, the dots often represent values produced by a linear transformation followed by a nonlinear function such as ReLU. In transformer terminology, these intermediate values are commonly called neurons.

GELU

Modern language models often use a related activation function called the Gaussian error linear unit, or GELU. GELU has a smoother shape than ReLU but serves a similar general purpose: it introduces nonlinearity into the network.

The toy explanation uses ReLU because its behavior is easier to interpret as a sharp on-or-off detector.

Think About It

Without a nonlinear function, the MLP would consist only of linear transformations. Multiple linear transformations can be combined into one larger linear transformation, so the network would lack the ability to create selective behaviors such as “activate only when both Michael and Jordan are present.” The nonlinear function gives the network additional expressive power.

Step 3: The Down Projection

After the nonlinear function, the MLP multiplies the intermediate vector by another large matrix. This matrix maps the vector back down to the original embedding dimension, so it is called the down projection matrix, written as WdownW_{\text{down}}Wdown​.

The complete transformed output can be represented schematically as:

WdownReLU⁡(WupE+Bup)+BdownW_{\text{down}}\operatorname{ReLU}(W_{\text{up}}E+B_{\text{up}})+B_{\text{down}}Wdown​ReLU(Wup​E+Bup​)+Bdown​

where:

  • EEE is the input vector
  • WupW_{\text{up}}Wup​ is the upward projection matrix
  • BupB_{\text{up}}Bup​ is the upward bias
  • ReLU⁡\operatorname{ReLU}ReLU is the nonlinear activation
  • WdownW_{\text{down}}Wdown​ is the downward projection matrix
  • BdownB_{\text{down}}Bdown​ is the downward bias

The down projection is especially useful to understand column by column.

Matrix multiplication can be viewed as taking each column of WdownW_{\text{down}}Wdown​, multiplying it by the corresponding neuron’s activation, and adding all the resulting vectors together.

If the first column of WdownW_{\text{down}}Wdown​ is the basketball direction BBB, then an activation in the first neuron causes a basketball component to be added to the output.

If the neuron activation is 111, the contribution is:

1⋅B=B1\cdot B=B1⋅B=B

If the neuron is inactive and its value is 000, the contribution is:

0⋅B=00\cdot B=00⋅B=0

Therefore, the corresponding column determines what information that neuron writes back into the embedding space.

The column could contain more than just the basketball direction. It might encode several directions that the model has learned to associate with the detected feature. Other columns specify the information added when other neurons become active.

The down bias BdownB_{\text{down}}Bdown​ is added regardless of the neuron activations:

WdownH+BdownW_{\text{down}}H+B_{\text{down}}Wdown​H+Bdown​

where HHH is the post-activation intermediate vector. The exact role of every learned bias is difficult to determine from the equation alone, so the toy explanation treats this bias as secondary.

Step 4: The Residual Addition

The MLP’s output is added to the original input vector:

Eout=E+WdownReLU⁡(WupE+Bup)+BdownE_{\text{out}} = E + W_{\text{down}}\operatorname{ReLU}(W_{\text{up}}E+B_{\text{up}})+B_{\text{down}}Eout​=E+Wdown​ReLU(Wup​E+Bup​)+Bdown​

This structure allows the MLP to add information without destroying what was already present.

In the toy example:

  1. Attention combines the two name tokens so that a vector represents Michael and Jordan.
  2. A row of WupW_{\text{up}}Wup​ detects the combination.
  3. The bias shifts the detector so that the combined feature becomes positive.
  4. ReLU activates the corresponding neuron.
  5. The matching column of WdownW_{\text{down}}Wdown​ contributes the basketball direction.
  6. The basketball direction is added to the original vector.

The output vector therefore represents a richer combination:

  • Michael
  • Jordan
  • Basketball

This does not prove that real models store this exact fact in this exact clean arrangement. It is a toy model showing how such storage could work mathematically.

MLPs Process Token Positions Independently

An MLP applies the same computation separately to every token vector in the sequence. If an input has nnn token positions, the MLP produces nnn separate transformations.

The vectors do not exchange information with one another inside the MLP. That communication happens through attention.

This division of labor is important:

  • Attention allows information to move between token positions.
  • The MLP processes the information present at each position and can add learned transformations or features.

For example, attention might move information about “Michael” into the vector associated with “Jordan.” The MLP at that position can then detect the combined representation and add basketball-related information.

How Many Parameters Do MLPs Contain?

MLPs account for a very large fraction of the parameters in a large language model.

Consider the numerical example associated with GPT-3:

  • The embedding dimension is 12,28812{,}28812,288.
  • The up projection has just under 50,00050{,}00050,000 rows.
  • Each row has 12,28812{,}28812,288 parameters.

The number of parameters in the up projection is therefore approximately:

50,000×12,288≈604,000,00050{,}000\times 12{,}288 \approx 604{,}000{,}00050,000×12,288≈604,000,000

The down projection has the same number of parameters because its shape is reversed. Together, the two matrices contain approximately:

604 million+604 million≈1.2 billion604\text{ million}+604\text{ million} \approx 1.2\text{ billion}604 million+604 million≈1.2 billion

The bias vectors add parameters as well, but their contribution is small compared with the matrices.

The model contains 969696 separate MLP blocks. Therefore, the total number of MLP parameters is approximately:

96×1.2 billion≈116 billion96\times 1.2\text{ billion} \approx 116\text{ billion}96×1.2 billion≈116 billion

This represents roughly two-thirds of the model’s total parameters. When the MLP parameters are combined with the parameters from attention, embeddings, and unembedding, the total reaches approximately:

175 billion175\text{ billion}175 billion

Normalization steps also contain learned parameters, but their contribution is relatively small compared with the MLP matrices.

Why the intermediate dimension is larger

The up projection expands the vector into a much larger intermediate space. In the example, the intermediate space has nearly 50,00050{,}00050,000 dimensions, compared with 12,28812{,}28812,288 dimensions in the embedding space.

This gives the network many intermediate values—or neurons—that can respond to different patterns. The down projection then combines those activations to produce a modification in the original embedding space.

The expansion and contraction can be compared to taking a compact description, unpacking it into many possible features, applying selective nonlinear processing, and then recombining the useful results.

The Limits of the Simple “One Neuron, One Fact” Picture

The toy example makes it tempting to believe that:

  • One neuron detects “Michael Jordan”
  • One corresponding output column writes “basketball”
  • Each neuron represents one clean feature

The mathematics permits this kind of arrangement. A row of the up projection can act as a detector for a direction, and a column of the down projection can specify what is added when that detector activates.

However, evidence suggests that individual neurons in real language models very rarely represent one clean, isolated feature. A neuron may respond to several seemingly unrelated concepts, and one concept may be distributed across many neurons.

One possible explanation is superposition.

Superposition in High-Dimensional Spaces

Suppose a vector space has nnn dimensions. If every feature must be represented by a direction that is exactly perpendicular to every other feature, then at most nnn independent feature directions can fit into the space.

This is closely related to the mathematical meaning of dimension: the number of mutually independent perpendicular directions available.

However, exact perpendicularity may be unnecessarily strict. If a small amount of overlap or noise is acceptable, features can be represented by directions that are only approximately perpendicular.

For example, two vectors may be allowed to have an angle between 898989 and 919191 degrees rather than exactly 909090 degrees. These directions are not perfectly independent, but they are close enough that they can represent separate features with limited interference.

In low-dimensional spaces, relaxing the requirement in this way does not provide much additional capacity. In high-dimensional spaces, however, the effect becomes dramatic.

Random high-dimensional vectors tend naturally to have angles near 909090 degrees. For example, one can generate 10,00010{,}00010,000 random vectors in a 100100100-dimensional space. Although their pairwise angles can initially range widely, the distribution already tends to concentrate near 909090 degrees. An optimization process can then adjust the vectors so that nearly all pairwise angles fall into a narrow range, such as 898989 to 919191 degrees.

The result is a large collection of vectors that are almost perpendicular even though there are far more vectors than dimensions.

The Johnson–Lindenstrauss relationship

A consequence associated with the Johnson–Lindenstrauss lemma is that the number of nearly perpendicular vectors that can fit into a space grows exponentially with the number of dimensions.

This has an important implication:

A high-dimensional space can represent far more approximately independent features than its raw number of dimensions might suggest.

If a model’s representation space becomes ten times larger, its capacity for approximately independent ideas can grow by much more than a factor of ten.

This may help explain why increasing model size can produce surprisingly large gains in capability. Larger spaces do not merely provide proportionally more room; they can provide dramatically more capacity for representing separate features.

Superposition and MLP Neurons

Superposition may occur not only in the embedding space but also in the intermediate neuron space of an MLP.

A simple interpretation might assume that an MLP with approximately 50,00050{,}00050,000 neurons can probe only 50,00050{,}00050,000 features. But if features are represented using combinations of nearly perpendicular directions, the effective number of represented features could be much larger.

In that case, a feature would not appear as one neuron lighting up. Instead, it might appear as a particular pattern across many neurons:

  • Several neurons may activate together
  • Different features may share some neurons
  • The identity of a feature may be encoded by the overall combination

This is why interpreting a model by inspecting individual neurons can be misleading. A single neuron may participate in multiple features, while a single feature may be distributed across multiple neurons.

The term superposition refers to this overlapping representation of many features in the same available dimensions.

Why superposition makes interpretation difficult

If every neuron represented one simple concept, interpretability would be relatively straightforward. A researcher could inspect a neuron, identify what it responds to, and understand how it affects the output.

Under superposition, the interpretation must instead consider combinations of neurons and directions. The researcher must ask questions such as:

  • Which neurons tend to activate together?
  • What combination of activations corresponds to a particular feature?
  • How much overlap exists between two represented features?
  • What information is added when a particular activation pattern appears?

This makes the internal computation harder to read, but it may also allow the model to store and process many more features than a one-neuron-per-feature design would permit.

Sparse Autoencoders and Feature Discovery

A tool called a sparse autoencoder is used by some interpretability researchers to investigate these hidden features.

The motivation is that the true features may be superimposed across many neurons. A sparse autoencoder attempts to transform the model’s activations into a representation where only a small number of feature components are active at a time.

The important idea is not that individual neurons necessarily reveal the model’s true concepts. Instead, a separate analysis may be needed to recover the underlying features from patterns distributed across the neuron activations.

How the Pieces Fit Together

The toy example can now be summarized as a complete information pathway.

Suppose an earlier attention operation has caused a vector to represent both “Michael” and “Jordan.”

The MLP then performs the following sequence:

  1. Feature detection
    A row of WupW_{\text{up}}Wup​ computes a dot product that measures alignment with a combined Michael-plus-Jordan direction.

  2. Threshold adjustment
    The upward bias shifts the value so that the detector becomes positive only when the combined pattern is sufficiently present.

  3. Nonlinear selection
    ReLU removes negative and zero values, turning the detector into an approximate activation gate.

  4. Feature writing
    The corresponding column of WdownW_{\text{down}}Wdown​ contributes a basketball direction when the neuron is active.

  5. Residual preservation
    The resulting basketball information is added to the original vector rather than replacing it.

The final vector can therefore carry information about the person and the sport together.

Real models may implement this association in a much more distributed and overlapping manner. Nevertheless, the example illustrates the essential computational roles of the two projections and the nonlinear activation.

Comprehensive Review

A large language model represents tokens as high-dimensional vectors. As those vectors move through transformer layers, attention allows them to exchange contextual information, while MLPs independently transform each vector at each token position.

An MLP consists primarily of two matrix multiplications with a nonlinear activation between them. The first matrix, WupW_{\text{up}}Wup​, expands the vector into a larger intermediate space. Its rows can be viewed as detectors that measure how strongly the input aligns with various directions or combinations of directions.

A bias vector shifts the detector values. The ReLU function then removes negative responses and preserves positive ones:

ReLU⁡(x)=max⁡(0,x)\operatorname{ReLU}(x)=\max(0,x)ReLU(x)=max(0,x)

This nonlinearity allows the MLP to behave like a selective gate, such as an approximate AND operation.

The second matrix, WdownW_{\text{down}}Wdown​, maps the activations back into the original embedding space. Its columns can be viewed as directions that are added to the output when corresponding neurons activate. In the toy example, one active neuron adds a basketball direction when the input represents Michael Jordan.

The MLP output is added to the original vector through a residual connection:

Eout=E+WdownReLU⁡(WupE+Bup)+BdownE_{\text{out}} = E + W_{\text{down}}\operatorname{ReLU}(W_{\text{up}}E+B_{\text{up}})+B_{\text{down}}Eout​=E+Wdown​ReLU(Wup​E+Bup​)+Bdown​

MLPs contain a majority of the parameters in large language models. In the GPT-3 numerical example, the MLP blocks contain approximately 116116116 billion of the model’s roughly 175175175 billion parameters.

The simple picture of one neuron representing one fact is useful for understanding the computation, but it is probably not an accurate description of most real model representations. Through superposition, many features can be encoded using overlapping combinations of nearly perpendicular directions. In high-dimensional spaces, the number of such approximately independent directions can grow exponentially with the number of dimensions, a fact related to the Johnson–Lindenstrauss lemma.

As a result, a model may represent many more features than the number of neurons or dimensions suggests. Individual facts may be distributed across patterns of neurons rather than stored in isolated neurons, which explains both the power of large language models and the difficulty of interpreting their internal representations.

Ask anything

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

FlashcardsQuizFill in the blanksWritten testLessonNotesPodcastContent