Author order randomized. Authors contributed roughly equally — see attribution section for details.

What kind of document is this?

What you have in front of you is so far a rough writeup rather than a clean text. As we realized that our work is currently highly relevant to recent questions posed by interpretability researchers, we put together a lightly edited version of private notes we've written over the last ~4 months. If you'd be interested in writing up a cleaner version, get in touch, or just do it. We're making these notes public before we're done with the project because of some combination of (1) seeing others think along similar lines and wanting to make it less likely that people (including us) spend time duplicating work, (2) providing a frame which we think provides plenty of concrete immediate problems for people to independently work on[1] (3) seeking feedback to decrease the chance we spend a bunch of time on nonsense.

1 minute summary

Superposition is a mechanism that might allow neural networks to represent the values of many more features than they have neurons, provided that those features are present sparsely in the dataset. However, until now, an understanding of how computation can be done in a compressed way directly on these stored features has been limited to a few very specific tasks (for example here). The goal of this post is to lay the groundwork for a picture of how computation in superposition can be done in general. We hope this will enable future research to build interpretability techniques for reverse engineering circuits that are manifestly in superposition.

Our main contributions are:

  1. Formalisation of some tasks performed by MLPs and attention layers in terms of computation on boolean features stored in superposition.
  2. A family of novel constructions which allow a single layer MLP to compute a large number of boolean functions of features entirely in superposition.
  3. Discussion of how these constructions could be leveraged:
    1. to emulate arbitrary large sparse boolean circuits entirely in superposition
    2. to allow the QK circuit of an attention head to dynamically choose a boolean expression and attend to past token positions where this expression is true.
    3. To explain the tentative observation that transformers may store arbitrary XORs of features
  4. A construction which allows the QK circuit of an attention head to check for the presence of surprisingly many query-key feature pairs simultaneously in superposition, on the order of one pair per parameter[2].

10 minute summary

Thanks to Nicholas Goldowsky-Dill for producing an early version of this summary/diagrams and generally for being instrumental in distilling this post.

Central to our analysis of MLPs is the Universal-AND (U-AND) problem:

  • Given input boolean features . These features are sparse, meaning on most inputs only a few features are true, and encoded as directions in the input space .
  • We want to compute all possible binary conjunctions of these inputs (), and output them in different linear directions. Some small bounded error in these output values is tolerated.
  • We want to compute this in a single MLP layer () with as few neurons as possible, for weight matrix with shape , bias , and ‘readoff’ matrix

This problem is central to understanding computation in superposition because:

  • Many features that people think of are boolean in nature, and reverse engineering the circuits that are involved in constructing them consists of understanding how simpler boolean features are combined to make them.  For example, in a vision model, the feature which is 1 if there is a car in the image may be computed by combing the ‘wheels at the bottom of the image’ feature AND the ‘windows at the top’ feature [3].
  • We will be focusing on the part of the network before the readoff with the matrix . In an analogous way to the toy model of superposition, we consider the first two layers to represent  If we can do this task with an MLP with fewer than neurons, then in a sense we have computed more boolean functions than we have neurons, and the values of these functions will be stored in superposition in the MLP activation space.
  • Any boolean function can be written as a linear combination of ANDs with different numbers of inputs. For example
  • Therefore, if we can compute and linearly represent all the ANDs in superposition, then we can do so for any boolean function.

If (the dimension of the input space), then we can store the input features using an orthonormal basis such as the neuron basis. A naive solution in this case would be to have one neuron per pair which is active if both inputs are true and 0 otherwise. This requires neurons, and involves no superposition:


On this input and are true, and all other inputs are false.

We can do much better than this, computing all the pairwise ANDs up to a small error with many fewer neurons. To achieve this, we have each neuron care about a random subset of inputs, and we choose the bias such that each neuron is activated when at least two of them are on. This requires neurons:


  • A modified version works even when the input features are in superposition. In this case we cannot compute all ANDs of potentially exponentially many features. Instead, we must pick up to logical gates to calculate at each stage.
  • A solution to U-AND can be generalized to compute many ANDs of more than two inputs, and therefore to compute arbitrary boolean expressions involving a small number of input variables, with surprisingly efficient asymptotic performance (superpolynomially many functions computed at once). This can be done simply by increasing the density of connections between inputs and neurons, which comes at the cost of interference terms going to zero more slowly.
  • It may be possible to stack multiple of these constructions in a row and therefore to emulate a large boolean circuit, in which each layer computes boolean functions on the outputs of the previous layer. However, if the interference is not carefully managed, the errors are likely to propagate and eventually become unmanageable. The details of how the errors propagate and how to mitigate this are beyond the scope of this work.
  • We study the performance of our constructions asymptotically in , and expect that insofar as real models implement something like them, they will likely be importantly different in order to have low error at finite .
  • If the ReLU is replaced by a quadratic activation function, we can provide a construction that is much more efficient in terms of computations per neuron. We suspect that this implies the existence of similarly efficient constructions with ReLU, and constructions that may perform better at finite .

Our analysis of the QK part of an attention head centers on the task of skip feature-bigram checking:

  • Given residual stream vectors (for sequence length ) storing boolean features in superposition .
  • Given a set of skip feature-bigrams (SFBs) which specify which keys to attend to from each query in terms of features present in the query and key. A skip feature-bigram is a pair of features such as , and we say that an SFB is present in a query key pair if the first feature is present in the key and the second in the query.
  • We want to compute an attention score which contains, in each entry, the number of SFBs in present in the query and key that correspond to that entry. To do so, we look for a suitable choice of the parameters in the weight matrix , a matrix of rank . Some small bounded error is tolerated.

This framing is valuable for understanding the role played by the attention mechanism in superposed computation because:

  • It is a natural modification of the ‘attention head as information movement’ story that engages with the many independent features stored in residual stream vectors in parallel, rather than treating the vectors as atomic units. Each SFB can be thought of as implementing an operation corresponding to statements like ‘if feature is present in the query, then attend to keys for which feature is present’. 
  • The stories normally given for the role played by a QK circuit can be reproduced as particular choices of . For example, consider the set of ‘identity’ skip feature-bigrams: ‘if feature is present in the query, then attend to keys for which feature is also present’. Checking for the presence of all SFBs in corresponds to attending to keys which are the same as the query. 
  • There are also many sets which are most naturally thought of in terms of performing each check in individually. 

A nice way to construct is as a sum of terms for each skip feature-bigram, each of which is a rank one matrix equal to outer product of the two feature vectors in the SFB. In the case that all feature vectors are orthogonal (no superposition) you should be thinking of something like this:

where each of the rank one matrices, when multiplied by a residual stream vector on the right and left, performs a dot product on each side: 

where are the feature bigrams in with feature directions , and is a residual stream vector at sequence position . Each of these rank one matrices contributes a value of to the value of if and only if the corresponding SFB is present. Since the matrix cannot be higher rank than , typically we can only check for up to SFBs this way.

In fact we can check for many more SFBs than this, if we tolerate some small error. The construction is straightforward once we think of as this sum of tensor products: we simply add more rank one matrices to the sum, and then approximate the sum as a rank matrix, using the SVD or even a random projection matrix . This construction can be easily generalised to the case that the residual stream stores features in superposition (provided we take care to manage the size of the interference terms) in which case can be thought of as being constructed like this: 

is a sum of outer products of feature direction vectors, with the vectors on the right projected down to a -dimensional subspace

When multiplied by a residual stream vector on the right and left, this expression is


  • It turns out that the interference becomes larger than the signal when roughly one SFB has been checked for per parameter:
  • When there is structure to the set of SFBs that are being checked for, we can exploit this to check for even more SFBs with a single attention head.
  • If there is a particular linear structure to the geometric arrangement of feature vectors in the residual stream, many more SFBs can be checked for at once, but this time the story of how this happens isn’t the simplest to describe in terms of a list of SFBs. This suggests that our current description of what the QK circuit does is lacking. In fact, this example exemplifies computation performed by neural nets that we don’t think is best described by our current sparse boolean picture. It may be a good starting point for building a broader theory than we have so far that takes into account other structures.

Indeed, there are many open directions for improving our understanding of computation in superposition, and we’d be excited for others to do future research (theoretical and empirical) in this area.

Some theoretical directions include:

  • Fitting the OV circuit into the boolean computation picture
  • Studying error propagation when U-AND is applied sequentially
  • Finding constructions with better interference at finite
  • Making the story of boolean computation in transformers more complete by studying things that have not been captured by our current tasks
  • Generalisations to continuous variables

Empirical directions include:

  • Training toy models to understand if NNs can learn U-AND and related tasks, and how learned algorithms differ.
  • Throwing existing interp techniques at NNs trained on these tasks and trying to study what we find. Which techniques can handle the superposition adequately?
  • Trying to find instances of computation in superposition happening in small language models. 

Structure of the Post

In Section 1, we define the U-AND task precisely, and then walk through our construction and show that it solves the task. Then we generalise the construction in 2 important ways: in Section 1.1, we modify the construction to compute ANDs of input features which are stored in superposition, allowing us to stack multiple U-AND layers together to simulate a boolean circuit. In Section 1.2 we modify the construction to compute ANDs of more than 2 variables at the same time, allowing us to compute all sufficiently small[4] boolean functions of the inputs with a single MLP. Then in Section 1.3 we explore efficiency gains from replacing the ReLU with a quadratic activation function, and explore the consequences.

In Section 2 we explore a series of questions around how to interpret the maths in Section 1, in the style of FAQs. Each part of Section 2 is standalone and can be skipped, but we think that many of the concepts discussed there are valuable and frequently misunderstood.

In section 3 we turn to the QK circuit, carefully introducing the skip feature-bigram checking task, and we explain our construction. We also discuss two scenarios that allow for more SFBs to be checked for than the simplest construction would allow.

We discuss the relevance of our constructions to real models in Section 4, and conclude in Section 5 with more discussion on Open Directions.

Notation and Conventions

  • is the dimension of some activation space. may also be used for the dimension of the input space, and for the number of neurons in an MLP
  • is the number of input features. If the input features are stored in superposition, , otherwise
  • denotes an orthogonal basis of vectors. The standard basis refers to the neuron basis.
  • All vectors are denoted with arrows on top like this:
  • We use single lines to denote the size of a set like this: or the norm of a vector like this:
  • We say that a boolean function has been computed -accurately for some small parameter if the computed output never differs from by more than . That is, whenever the function has the output , the computation outputs a number between and whenever the function outputs , the computation outputs a number between .
  • We say that a pair of unit vectors is -almost orthogonal (for a fixed parameter ) if their dot product is (equivalently, if they are orthogonal to -accuracy). We say that a collection of unit vectors is -almost-orthogonal if they are pairwise almost orthogonal. We assume to be a fixed small number throughout the paper (unless specified otherwise).
  • It is known that for fixed one can fit exponentially (in ) many almost orthogonal vectors in a -dimensional Euclidean space. Throughout this paper, we will assume present in each NN activation space a suitably “large” collection of almost-orthogonal vectors, which we call an overbasis.
  • Vectors in this overbasis will be called f-vectors[5], and denoted . We assume they correspond to binary properties of inputs relevant to a neural net (such as “Does this picture contain a cat?”). When convenient, we will assume these f-vectors are generated in a suitably random way: it is known that a random collection of vectors is, with high probability, an almost orthogonal overbasis, so long as the number of vectors is not superexponentially large in [6].

In this post we make extensive use of Big-O notation and its variants, little o, . See wikipedia for definitions. We also make use of tilde notation, which means we ignore log factors. For example, by saying a function is , we mean that there are nonzero constants and a natural number such that for all , we have . By saying a quantity is , we mean that this is true up to a factor that is a polynomial of — i.e., that it is asymptotically between and .

1 The Universal AND

We introduce a simple and central component in our framework, which we call the Universal AND component or U-AND for short. We start by introducing the most basic version of the problem this component solves. We then provide our solution to the simplest version of this problem. We later discuss a few generalizations: to inputs which store features in superposition, and to higher numbers of inputs to each AND gate. More elaboration on U-AND — in particular, addressing why we think it’s a good question to ask — is provided in Section 2.

1.1 The U-AND task

  The basic boolean Universal AND problem: Given an input vector which stores an orthogonal set of boolean features, compute a vector from which can be linearly read off the value of every pairwise AND of input features, up to a small error. You are allowed to use only a single-layer MLP and the challenge is to make this MLP as narrow as possible.

More precisely: Fix a small parameter and let and be integers with [7]. Let be the standard basis in , i.e. is the vector whose th component is and whose other components are . Inputs are all at most -composite vectors, i.e., for each index set with , we have the input . So, our inputs are in bijection with binary strings that contain at most ones[8]. Our task is to compute all pairwise ANDs of these input bits, where the notion of ‘computing’ a property is that of making it linearly represented in the output activation vector . That is, for each pair of inputs , there should be a linear function , or more concretely, a vector , such that . Here, the indicates equality up to an additive error and is iff both bits and of are 1. We will drop the subscript going forward.

We will provide a construction that computes these features with a single -neuron ReLU layer, i.e., a matrix and a vector such that , with . Stacking the readoff vectors we provide as the rows of a readout matrix , you can also see us as providing a parameter setting solving , where denotes the vector of all pairwise ANDs. But we’d like to stress that we don’t claim there is ever something like this large, size , layer present in any practical neural net we are trying to model. Instead, these features would be read in by another future model component, like how the components we present below (in particular, our U-AND construction with inputs in superposition and our QK circuit) do.

There is another kind of notion of a set of features having been computed, perhaps one that’s more native to the superposition picture: that of the activation vector (approximately) being a linear combination of f-vectors — we call these vectors f-vectors— corresponding to these properties, with coefficients that are functions of the values of the features. We can also consider a version of the U-AND problem that asks for output vectors which represent the set of all pairwise ANDs in this sense, maybe with the additional requirement that the f-vectors be almost orthogonal. Our U-AND construction solves this problem, too — it computes all pairwise ANDs in both senses. See the appendix for a discussion of some aspects of how the linear readoff notion of stuff having been computed, the linear combination notion of something having been computed, and almost orthogonality hang together.

1.2 The U-AND construction

We now present a solution to the U-AND task, computing new features with an MLP width that can be much smaller than . We will go on to show how our solution can be tweaked to compute ANDs of more than 2 features at a time, and to compute ANDs of features which are stored in superposition in the inputs.

To solve the base problem, we present a random construction: (with shape ) has entries that are iid random variables which are with probability , and each entry in the bias vector is . We will pin down what should be later. 

We will denote by the set of neurons that are ‘connected’ to the th input, in the sense that elements of the set are neurons for which the th entry of the row of the weight vector that connects to that neuron is . is used to denote the indicator set of : the vector which is for every neuron in and otherwise. So is also the th column of .

Then we claim that for this choice of weight matrix, all the ANDs are approximately linearly represented in the MLP activation space with readoff vectors (and feature vectors, in the sense of Appendix B) given by

for all , where we continue our abuse of notation to write as shorthand for the vector which is an indicator for the intersection set, and is the size of the set.

We preface our explanation of why this works with a technical note. We are going to choose and (as functions of ) so that with high probability, all sets we talk about have size close to their expectation. To do this formally, one first shows that the probability of each individual set having size far from its expectation is smaller than any using the Chernoff bound (Theorem 4 here), and one follows this by a union bound over all only sets to say that with probability , none of these events happen. For instance, if a set has expected size , then the probability its size is outside of the range is at most (following these notes, we let denote the expectation and denote the number of -sized deviations from the expectation — this bound works for which is the case here). Technically, before each construction to follow, we should list our parameters and all the sets we care about (for this first construction, these are the double and triple intersections between the ) and then argue as described above that with high probability, they all have sizes that only deviate by a factor of from their expected size and always carry these error terms around in everything we say, but we will omit all this in the rest of the U-AND section.

So, ignoring this technicality, let’s argue that the construction above indeed solves the U-AND problem (with high probability). First, note that . We require that is big enough to ensure that all intersection sets are non-empty with high probability, but subject to that constraint we probably want to be as small as possible to minimise interference[9]. We'll choose , such that the intersection sets have size . We split the check that the readoff works out into a few cases:

  • Firstly, if input features , , and at most other input features are present (recall that we are working with -composite inputs), then letting denote the post-ReLU activation vector, we have plus an error that is at most times [the sum of sizes of triple intersections involving and each of the other features which are on, divided by the size of the ]. This is very likely less than for all polynomially many pairs and sets of other inputs at once[10], at least assuming . The expected value of this error is .
  • Secondly, if only one of is present together with some at most other features, then we get nonzero terms in the sum that expanding the dot product precisely for neurons in a triple intersection of , and one of the other features, so the readoff — more precisely, (again, assuming ), and in expectation).
  • Finally, if neither of is present, then the error corresponds to quadruple intersections, so it is even more likely at most (still assuming ), and in expectation.

So we see that this readoff is indeed the AND of and up to error .

To finish, we note without much proof that everything is also computed in the sense that 'the activation vector is a linear combination of almost orthogonal features' (defined in Appendix B). The activation vector being an approximate linear combination of pairwise intersection indicator vectors with coefficients being given by the ANDs follows from triple intersections being small, as does the almost-orthogonality of these feature vectors.

U-AND allows for arbitrary XORs to be efficiently calculated

A consequence of the precise (up to ) nature of our universal AND is the existence of a universal XOR, in the sense of every XOR of features being computed. In this post by Sam Marks, it is tentatively observed that real-life transformers linearly compute XOR of arbitrary features in the weak sense of being able to read off tokens where XOR of two tokens is true using a linear probe (not necessarily with accuracy). This weak readoff behavior for AND would be unsurprising, as the residual stream already has this property (using the readoff vector which has maximal value if and only if and are both present). However, as Sam Marks observes, it is not possible to read off XOR in this weak way from the residual stream. We can however see that such a universal XOR (indeed, in the strong sense of -accuracy) can be constructed from our strong (i.e., -accurate) universal AND. To do so, assume that in addition to the residual stream containing feature vectors and , we’ve also already almost orthogonally computed universal AND features into the residual stream. Then we can weakly (and in fact, -accurately) read off XOR from this space by taking the dot product with the vector . Then we see that if we had started with the two-hot pair the result of this readoff will be, up to a small error  

This gives a theoretical feasibility proof of an efficiently computable universal XOR circuit, something Sam Marks believed to be impossible.

1.3 Handling inputs in superposition: sparse boolean computers

Any boolean circuit can be written as a sequence of layers executing pairwise ANDs and XORs[11] on the binary entries of a memory vector. Since our U-AND can be used to compute any pairwise ANDs or XORs of features, this suggests that we might be able to emulate any boolean circuit by applying something like U-AND repeatedly. However, since the outputs of U-AND store features in superposition, if we want to pass these outputs as inputs to a subsequent U-AND circuit, we need to work out the details of a U-AND construction that can take in features in superposition. In this section we explore the subtleties of modifying U-AND in this way. In so doing, we construct an example of a circuit which acts entirely in superposition from start to finish — nowhere in the construction are there as many dimensions as features! We consider this to be an interesting result in its own right.

U-ANDs ability to compute many boolean functions of inputs features stored in superposition provides an efficient way to use all the parameters of the neural net to compute (up to a small error) a boolean circuit with a memory vector that is wider than the layers of the NN[12]. We call this emulating a ‘boolean computer’. However, three limitations prevent any boolean circuit from being computed:

  1. An injudicious choice of a layer executing XORs applied to a sparse input can fail to give a sparse output vector. Since U-AND only works on inputs with sparse features, this means that we can only emulate circuits with the property than on sparse inputs, their memory vector is sparse throughout the computation. We call these circuits ‘sparse boolean circuits’.
  2. Even if the outputs of the circuit remain sparse at every layer, the errors involved in the boolean read-offs compound from layer to layer. We hope that it is possible to manage this interference (perhaps via subtle modifications to the constructions) enough to allow multiple steps of sequential computation, although we leave an exploration of error propagation to future work.
  3. We can't compute an unbounded number of new features with a finite-dimensional hidden layer. As we will see in this section, when input features are stored in superposition (which is true for outputs of U-AND and therefore certainly true for all but possibly the first layer of an emulated boolean circuit), we cannot compute more than (number of parameters in the layer) many new boolean functions at a time.

Therefore, the boolean circuits we expect can be emulated in superposition (1) are sparse circuits (2) have few layers (3) have memory vectors which are not larger than the square of the activation space dimension.

Construction details for inputs in superposition

Now we generalize U-AND to the case where input features can be in superposition. With f-vectors , we give each feature a random set of neurons to map to, as before. After coming up with such an assignment, we set the th row of to be the sum of the f-vectors for features which map to the th neuron. In other words, let be the matrix with th row given by the components of in the neuron basis:

Now let \hat{W} be a sparse matrix (with shape ) with entries that are iid Bernoulli random variables which are with probability . Then:

Unfortunately, since the are random vectors, their inner product will have a typical size of . So, on an input which has no features connected to neuron , the preactivation for that neuron will not be zero: it will be a sum of these interference terms, one for each feature that is connected to the neuron. Since the interference terms are uncorrelated and mean zero, they start to cause neurons to fire incorrectly when neurons are connected to each neuron. Since each feature is connected to each neuron with probability this means neurons start to misfire when [13]. At this point, the number of pairwise ANDs we have computed is .

This is a problem, if we want to be able to do computation on input vectors storing potentially exponentially many features in superposition, or even if we want to be able to do any sequential boolean computation at all:

Consider an MLP with several layers, all of width , and assume that each layer is doing a U-AND on the features of the previous layer. Then if the features start without superposition, there are initially features. After the first U-AND, we have new features, which is already too many to do a second U-AND on these features!

Therefore, we will have to modify our goal when features are in superposition. That said, we're not completely sure there isn't any modification of the construction that bypasses such small polynomial bounds. But e.g. one can't just naively make sparser — can't be taken below without the intersection sets like becoming empty. When features were not stored in superposition, solving U-AND corresponded to computing many new features. Instead of trying to compute all pairwise ANDs of all (potentially exponentially many) input features in superposition, perhaps we should try to compute a reasonably sized subset of these ANDs. In the next section we do just that. 

A construction which computes a subset of ANDs of inputs in superposition

Here, we give a way to compute ANDs of up to particular feature pairs (rather than all ANDs) that works even for that is superpolynomial in [14]. (We’ll be ignoring factors in much of what follows.)

In U-AND, we take to be a random matrix with iid 0/1 entries with probability . If we only need/want to compute a subset of all the pairwise ANDs — let be this set of all pairs of inputs for which we want to compute the AND of and — then whenever , we might want each pair of corresponding entries in the corresponding columns and of the adjacency matrix , i.e., each pair , to be a bit more correlated than an analogous pair in column and with . Or more precisely, we want to make such pairs of columns have a surprisingly large intersection for the general density of the matrix — this is to make sure that we get some neurons which we can use to read off the AND of , while choosing the general density in to be low enough that we don’t cross the density threshold at which a neuron needs to care about too many input features.

One way to do this is to pick a uniformly random set of neurons for each , and to set the column of corresponding to input to be the indicator vector of the union of these sets (i.e., just those assigned to gates involving ). This way, we can compute up to around pairwise ANDs without having any neuron care about more than input features, which is the requirement from the previous section to prevent neurons misfiring when input f-vectors are random vectors in superposition with typical interference size .

1.4 ANDs with many inputs: computation of small boolean circuits in a single layer

It is known that any boolean circuit with inputs can be written as a linear combination (with possibly exponential in terms, which is a substantial caveat) ANDs with up to inputs (fan-in up to )[15]. This means that, if we can compute not just pairwise ANDs, but ANDs of all fan-ins up to , then we can write down a ‘universal’ computation that computes (simultaneously, in a linearly-readable sense) all possible circuits that depend on some up to inputs.

The U-AND construction for higher fan-in

We will modify the standard, non-superpositional U-AND construction to allow us to compute all ANDs of a specific fan-in .

We'll need two modifications:

  1. We're now interested in -wise intersections between the . The size of these intersections is smaller than double intersections, so we need to increase to guarantee they are nonempty. A sensible choice for fan-in is .
  2. We only want neurons to fire when of the features that connect to them are present at the same time, so we require the bias to be .

Now we read off the AND of a set of input features along the vector .

We can straightforwardly simultaneously compute all ANDs of fan-ins ranging from to by just evenly partitioning the neurons into groups — let’s label these — and setting the weights into group and the biases of group as in the fan-in U-AND construction.

A clever choice of density can give us all the fan-ins at once

Actually, we can calculate all ANDs of up to some constant fan-in in a way that feels more symmetric than the option involving a partition above[16] by reusing the fan-in U-AND with (let’s say) and a careful choice of . This choice of   is larger than for any , ensuring that every intersection set is non-empty. Then, one can read off from as usual, but one can also read off with the composite vector

In general, one can read off the AND of an index set with the vector where  One can show that this inclusion-exclusion style formula works by noting that if the subset of indices of which are on is , then the readoff will be approximately . We’ll leave it as an exercise to show that this is if and if

Extending the targeted superpositional AND to other fan-ins

It is also fairly straightforward to extend the construction for a subset of ANDs when inputs are in superposition to other fan-ins, doing all fan-ins on a common set of neurons. Instead of picking a set for each pair that we need to AND as above, we now pick a set for each larger AND gate that we care about. As in the previous sparse U-AND, each input feature gets sent to the union of the sets for its gates, but this time, we make the weights depend on the fan-in. Letting denote the max fan-in over all gates, for a fan-in gate, we set the weight from each input to , and set the bias to . This way, still with at most about gates, and at least assuming inputs have at most some constant number of features active, we can read the output of a gate off with the indicator vector of its set.

1.5 Improved Efficiency with a Quadratic Nonlinearity

It turns out that, if we use quadratic activation functions instead of ReLU's we can write down a much more efficient universal AND construction. Indeed, the ReLU universal AND we constructed can compute the universal AND of up to features in a -dimensional residual stream. However, in this section we will show that with a quadratic activation, for -composite vectors, we can compute all pairwise ANDs of up to [17] features stored in superposition (this is exponential in , so superpolynomial in (!)) that admit a single-layer universal AND circuit.

The idea of the construction is that, on the large space of features the AND of the boolean-valued feature variables can be written as a quadratic function ; explicitly, Now if we embed feature space onto a smaller in an -almost-orthogonal way, it is possible to show that the quadratic function on is well-approximated on sparse vectors by a quadratic function on (with error bounded above by on 2-sparse inputs in particular). Now the advantage of using quadratic functions is that any quadratic function on can be expressed as a linear read-off of a special quadratic function given by the composition of a linear function and a quadratic element-wise activation function on which creates a set of neurons which collectively form a basis for all quadratic functions. Now we can set to be the dimension of the residual stream and work with an -dimensional subspace of the residual stream, taking the almost-orthogonal embedding . Then the map provides the requisite universal AND construction. We make this recipe precise in the following section

Construction Details

In this section we use slightly different notation to the rest of the post, dropping overarrows for vectors, and we drop the distinction between features and f-vectors.

Let be as above. There is a finite-dimensional space of quadratic functions on , with basis of size (such that we can write every quadratic function as a linear combination of these basis functions); alternatively, we can write for the basis vectors. We note that this space is spanned by a set of functions which are squares of linear functions of :

The squares of these functions are a valid basis for the space of quadratic functions on since and for we have There are distinct functions of type , and functions each of type and , for a total of basis functions as before. Thus there exists a single-layer quadratic-activation neural net from such that any quadratic function on is realizable as a "linear read-off", i.e., given by composing with a linear function In particular, we have linear "read-off" functions such that

Now suppose that is a collection of f-vectors which are -almost-orthogonal, i.e., such that for any and Note that (for fixed ), there exist such collections with exponential (in ) number of vectors . We can define a new collection of symmetric bilinear functions (i.e., functions in two vectors which are linear in each input independently and symmetric to switching ), for a pair of (not necessarily distinct) indices defined by (this is a product of two linear functions, hence quadratic). We will use the following result:

Proposition 1 Suppose is as above and is another pair of (not necessarily distinct) indices associated to feature vectors Then

This proposition follows immediately from the definition of and the almost orthogonality property.

Now define the single-valued quadratic function by applying the bilinear form to two copies of the same vector and dividing by 2. Then the proposition above implies that, for two pairs of distinct indices and we have the following behavior on the sum of two features (the superpositional analog of a two-hot vector):

The first formula follows from bilinearity (which is equivalent to the statement that the two entries in behave distributively) and the last formula follows from the proposition since we assumed are distinct indices, hence cannot match up with a pair of identical indices or Moreover, term in the formula above is bounded in absolute value by .

Combining this formula with Proposition 1, we deduce:

Proposition 2

Moreover, by the triangle inequality, the linear constants inherent in the notation are

Corollary where the notation returns when the two pairs of indices are equal and otherwise.

We can now write down the universal AND function by setting above. Assume we have This guarantees (with probability approaching ) that random vectors in are (-)almost orthogonal, i.e., have dot products We assume the vectors are initially embedded in (Note that we can instead assume they were initially randomly embedded in then re-embedded in by applying a random projection and rescaling appropriately.) Let be the universal quadratic map as above; we let be the quadratic functions as above. Now we claim that is a universal AND with respect to the feature vectors Note that, since the function is quadratic on it can be factorized as for some linear function on [18]. We now see that the linear maps are valid linear read-offs for ANDs of features: indeed,

where is the two-hot boolean indicator vector with s in positions and . Thus the AND of any two indices can be computed via the readout linear function on any two-hot input . Moreover, applying the same argument to a larger sparse sum gives where is the sparsity[19]

Scaling and comparison with ReLU activations

It is surprising that the universal AND circuit we wrote down for quadratic activations is so much more expressive than the one we have for ReLU activations, since the conventional wisdom for neural nets is that the expressivity of different (suitably smooth) activation functions does not increase significantly when we replace arbitrary activations by quadratic ones. We do not know if this is a genuine advantage of quadratic activations over others (and indeed might be implemented in transformers in some sophisticated way involving attention nonlinearities), or whether there is some yet-unknown reason that (perhaps assuming nice properties of our features), ReLU's can give more expressive universal AND circuits than we have been able to find in the present work. We list this discrepancy as an interesting open problem that follows from our work.


Note that the nonlinear function above lets us read off not only the AND of two sparse boolean vectors, but more generally the sum of products of coordinates of any sufficiently sparse linear combination of feature vectors (not necessarily boolean). More generally, if we replace quadratic activations with cubic or higher, we can get cubic expressions, such as the sum of triple ANDs (or, more generally, products of triples of coordinates). A similar effect can be obtained by chaining sequential levels of quadratic activations to get polynomial nonlinearities with exponent . Then so long as we can fit [20] features in the residual stream in an almost-orthogonal way (corresponding to a basis of monomials of degree on -dimensional space), we can compute sums of any degree- monomial over features, and thus any boolean circuit of degree , up to where the linear constant implicit in the depends on the exponent . This implies that for any value there is a dimension universal nonlinear map with quadratic activations such that any sparse boolean circuit involving elements is linearly represented (via an appropriate readoff vector). Moreover, keeping fixed, grows only as However, the constant associated with the big-O notation might grow quite quickly as the exponent increases. It would be interesting to analyse this scaling behavior more carefully, but that is outside the scope of the present work.

1.6 Universal Keys: an application of parallel boolean computation

So far, we have used our universal boolean computation picture to show that superpositional computation in a fully-connected neural network can be more efficient (specifically, compute roughly as many logical gates as there are parameters rather than non-superpositional implementations, which are bounded by number of neurons). This does not fully use the universality of our constructions: i.e., we must at every step read a polynomial (at most quadratic) number of features from a vector which can (in either the fan-in-k or quadratic-activation contexts) compute a superpolynomial number of boolean circuits. At the same time, there is a context in transformers where precisely this universality can give a remarkable (specifically, superpolynomial in certain asymptotics) efficiency improvement. Namely, recall that the attention mechanism of a transformer can be understood as a way for the last-token residual stream to read information from past tokens which pass a certain test associated to the query-key component. In our simplified boolean model, we can conceptualize this as follows:

  • Each token possesses a collection of “key features” which indicate bits of information about contexts where reading information from this token is useful. These can include properties of grammar, logic, mood, or context (food, politics, cats, etc.)
  • The current token attends to past tokens whose key features have a certain combination of features, which we conceptualize as tokens on whose features a certain boolean “relevance” function, returns . For example, the current token may ‘want’ to attend to all keys which have feature 1 and feature 4 but not feature 9, or exactly one of feature 2 and feature 8. This corresponds to the boolean function . Importantly, the choice of varies from token to token. We abstract away the question of generating this relevance function as some (possibly complicated) nonlinear computation implemented in previous layers. 
  • Each past token generates a key vector in a certain vector space (associated with an attention head) which is some (possibly nonlinear) function of the key features; the last token then generates a query vector which functions as a linear read-off, and should return a high value on past tokens for which the relevance formula evaluates to True. Note that the key vector is generated before the query vector, and before the choice of which to use is made.

Importantly, there is an information asymmetry between the “past” tokens (which contribute the key) and the last token that implements the linear read-off via query: in generating the boolean relevance function, the past token can use information that is not accessible to the token generating the key (as it is in its “future” – this is captured e.g. by the attention mask). One might previously have assumed that in generating a key vector, tokens need to “guess” which specific combinations of key features may be relevant to future tokens, and separately generate some read-off for each; this limits the possible expressivity of choosing the relevance function g to a small (e.g. linear in parameter number) number of possibilities.

However, our discovery of circuits that implement universal calculation suggests a surprising way to resolve this information asymmetry: namely, using a universal calculation, the key can simultaneously compute, in an approximately linearly-readable way, ALL possible simple circuits of up to inputs. This increases the number of possibilities of the relevance function to allow all such simple circuits; this can be significantly larger than the number of parameters and asymptotically (for logarithmic fan-ins) will in fact be superpolynomial[21]. As far as we are aware, this presents a qualitative (from a complexity-theoretic point of view) update to the expressivity of the attention mechanism compared to what was known before.

Sam Marks’ discovery of the universal XOR was done in this context: he observed using a probe that it is possible for the last token of a transformer to attend to past tokens that return True as the XOR of an arbitrary pair of features, something that he originally believed was computationally infeasible. 

We speculate that this will be noticeable in real-life transformers, and can partially explain the observation that transformers tend to implement more superposition than fully-connected neural networks.

2 U-AND: discussion

We discuss some conceptual matters broadly having to do with whether the formal setup from the previous section captures questions of practical interest. Each of these subsections is standalone, and you needn’t read any to read Section 3.

Aren't the ANDs already kinda linearly represented in the U-AND input?

This subsection refers to the basic U-AND construction from Section 1.1, with inputs not in superposition, but the objection we consider here could also be raised against other U-AND variants. The objection is this: aren’t ANDs already linearly present in the input, so in what sense have we computed them with the U-AND? Indeed, if we take the dot product of a particular 2-hot input with , we get 0 if neither the th nor the th features are present, if 1 of them is present, and 1 if they are both present. If we add a bias of , then without any nonlinearity at all, we get a way to read off pairwise U-AND for . The only thing the nonlinearity lets us do is to reduce this “interference” to a smaller Why is this important? 

In fact, one can show that you can't get more accurate than without a nonlinearity, even with a bias, and is not good enough for any interesting boolean circuit. Here’s an example to illustrate the point:

Suppose that I am interested in the variable . takes on a value in depending on whether both, one, or neither of the ANDs are on. The best linear approximation to is , which has completely lost the structure of . In this case, we have lost any information about which way the 4 variables were paired up in the ANDs. 

In general, computing a boolean expression with terms without the signal being drowned out by the noise will require if the noise is correlated, and if the noise is uncorrelated. In other words, noise reduction matters! The precision provided by -accuracy allows us to go from only recording ANDs to executing more general circuits in an efficient or universal way. Indeed, linear combinations of linear combinations just give more linear combinations – the noise reduction is the difference between being able to express any boolean function and being unable to express anything nonlinear at all. The XOR construction (given above) is another example that can be expressed as a linear combination involving the U-AND and would not work without the nonlinearity.

Aren’t the ANDs already kinda nonlinearly represented in the U-AND input?

This subsection refers to the basic U-AND construction from Section 1.1, with inputs not in superposition, but the objection we consider here could also be raised against other U-AND variants. While one cannot read off the ANDs linearly before the ReLU, except with a large error, one could certainly read them off with a more expressive model class on the activations. In particular, one can easily read off with a ReLU probe, by which we mean ), with and . We think there’s some truth to this: we agree that if something can be read off with such a probe, it’s indeed at least almost already there. And if we allowed multi-layer probes, the ANDs would be present already when we only have some pre-input variables (that our input variables are themselves nonlinear functions of). To explore a limit in ridiculousness: if we take stuff to be computed if it is recoverable by a probe that has the architecture of GPT-3 minus the embed and unembed and followed by a projection on the last activation vector of the last position residual stream, then anything that is linearly accessible in the last layer of GPT-3 is already ‘computed’ in the tuple of input embeddings. And to take a broader perspective: any variable ever computed by a deterministic neural net is in fact a function of the input, and is thus already ‘there in the input’ in an information-theoretic sense (anything computed by the neural net has zero conditional entropy given the input). The information about the values of the ANDs is sort of always there, but we should think of it as not having been computed initially, and as having been computed later[22].

Anyway, while taking something to be computed when it is affinely accessible seems natural when considering reading that information into future MLPs, we do not have an incredibly strong case that it’s the right notion. However, it seems likely to us that once one fixes some specific notion of stuff having been computed, then either exactly our U-AND construction or some minor variation on it would still compute a large number of new features (with more expressive readoffs, these would just be more complex properties — in our case, boolean functions of the inputs involving more gates). In fact, maybe instead of having a notion of stuff having been computed, we should have a notion of stuff having been computed for a particular model component, i.e. having been represented such that a particular kind of model component can access it to ‘use it as an input’. In the case of transformers, maybe the set of properties that have been computed as far as MLPs can tell is different than the set of properties that have been computed as far as attention heads (or maybe the QK circuit and OV circuit separately) can tell. So, we’re very sympathetic to considering alternative notions of stuff having been computed, but we doubt U-AND would become much less interesting given some alternative reasonable such notion.

If you think all this points to something like it being weird to have such a discrete notion of stuff having been computed vs not at all, and that we should maybe instead see models as ‘more continuously cleaning up representations’ rather than performing computation: while we don’t at present know of a good quantitative notion of ‘representation cleanliness’, so we can’t at present tell you that our U-AND makes amount of representation cleanliness progress and is sort of large compared to some default, it does seem intuitively plausible to us that it makes a good deal of such progress. A place where linear read-offs are clearly qualitatively important and better than nonlinear read-offs is in application to the attention mechanism of a transformer.

Does our U-AND construction really demonstrate MLP superposition?

This subsection refers to the basic U-AND construction from Section 1.1, with inputs not in superposition, but the objection we consider here could also be raised against other U-AND variants. One could try to tell a story that interprets our U-AND construction in terms of the neuron basis: we can also describe the U-AND as approximately computing a family of functions each of which record whether at least two features are present out of a particular subset of features[23]. Why should we see the construction as computing outputs into superposition, instead of seeing it as computing these different outputs on the neurons? Perhaps the 'natural' units for understanding the NN is in terms of these functions, as unintuitive as they may seem to a human.

In fact, there is a sense in which if one describes the sampled construction in the most natural way it can be described in the superposition picture, one needs to spend more bits than if one describes it in the most natural way it can be described in this neuron picture. In the neuron picture, one needs to specify a subset of size for each neuron, which takes bits to specify. In the superpositional picture, one needs to specify subsets of size , which takes about bits to specify[24]. If, let’s say, , then from the point of view of saving bits when representing such constructions, we might even prefer to see them in a non-superpositional manner!

We can imagine cases (of something that looks like this U-AND showing up in a model) in which we’d agree with this counterargument. For any fixed U-AND construction, we could imagine a setup where for each neuron, the inputs feeding into it form some natural family — slightly more precisely, that whether two elements of this family are present is a very natural property to track. In fact, we could imagine a case where we perform future computation that is best seen as being about these properties computed by the neurons — for instance, our output of the neural net might just be the sum of the activations of these neurons. For instance, perhaps this makes sense because having two elements of one of these families present is necessary and sufficient for an image to be that of a dog. In such a case, we agree it would be silly to think of the output as a linear combination of pairwise AND features.

However, we think there are plausible contexts in which such a circuit would show up in which it seems intuitively right to see the output as a sparse sum of pairwise ANDs: when the families tracked by particular neurons do not seem at all natural and/or when it is reasonable to see future model components as taking these pairwise AND features as inputs. Conditional on thinking that superposition is generic, it seems fairly reasonable to think that these latter contexts would be generic. 

Is universal calculation generic?

The construction of the universal AND circuit in the “quadratic nonlinearity” section above can be shown to be stable to perturbations; a large family of suitably “random” circuits in this paradigm contain all AND computations in a linearly-readable way. This updates us to suspect that at least some of our universal calculation picture might be generic: i.e., that a random neural net, or a random net within some mild set of conditions (that we can’t yet make precise), is sufficiently expressive to (weakly) compute any small circuit. Thus linear probe experiments such as Sam Marks’ identification of the “universal XOR” in a transformer may be explainable as a consequence of sufficiently complex, “random-looking” networks. This means that the correct framing for what happens in a neural net executing superposition might not be that the MLP learns to encode universal calculation (such as the U-AND circuit), but rather that such circuits exist by default, and what the neural network needs to learn is, rather, a readoff vector for the circuit that needs to be executed. While we think that this would change much of the story (in particular, the question of “memorization” vs. “generalization” of a subset of such boolean circuit features would be moot if general computation generically exists), this would not change the core fact that such universal calculation is possible, and therefore likely to be learned by a network executing (or partially executing) superposition. In fact, such an update would make it more likely that such circuits can be utilized by the computational scheme, and would make it even more likely that such a scheme would be learned by default. 

We hope to do a series of experiments to check whether this is the case: whether a random network in a particular class executes universal computation by default. If we find this is the case, we plan to train a network to learn an appropriate read-off vector starting from a suitably random MLP circuit, and, separately, to check whether existing neural networks take advantage of such structure (i.e., have features – e.g. found by dictionary learning methods – which linearly read off the results of such circuits). We think this would be particularly productive in the attention mechanism (in the context of “universal key” generation, as explained above).

What are the implications of using -accuracy? How does this compare to behavior found by minimizing some loss function?

A specific question here is:

Are algorithms that are -accurate at U-AND the same as algorithms which minimize the MSE or some other loss function we might write down for training a neural net on the task? 

The answer is that sometimes they are not going to be the same. In particular, our algorithm may not be given a low loss by MSE. Nevertheless, we think that -accuracy is a better thing to study for understanding superposition than MSE or other commonly considered loss functions (cross entropy would be much less wise than either!) This point is worth addressing properly, because it has implications for how we think about superposition and how we interpret results from the toy models of superposition paper and from sparse autoencoders, both of which typically use MSE. 

For our U-AND task, we ask for a construction that approximately equals a 1-hot target vector , with each coordinate allowed to differ from its target value by at most epsilon. A loss function which would correspond to this task would look like a cube well with vertical sides (the inside of the region ). This non-differentiable loss function would be useless for training. Let’s compare this choice to alternatives and defend it.

If we know that our target is always a 1-hot vector, then maybe we should have a softmax at the end of the network and use cross-entropy loss. We purposefully avoid this, because we are trying to construct a toy model of the computation that happens in intermediate layers of a deep neural network, taking one activation vector to a subsequent activation vector. In the process there is typically no softmax involved. Also, we want to be able to handle datapoints in which more than 1 AND is present at a time: the task is not to choose which AND is present, but *which of the ANDs* are present.

The other ubiquitous choice of loss function is MSE. This is the loss function used to evaluate model performance in two tasks that are similar to U-AND: the toy model of superposition and SAEs. Two reasons why this loss function might be principled are

  1. If there is reason to think of the model as a Gaussian probability model
  2. If we would like our loss function to be basis independent.

We see no reason to assume the former here, and while the latter is a nice property to have, we shouldn’t expect basis independence here: we would like the ANDs to be computed in a particular basis and are happy with a loss function that privileges that basis.

Our issue with MSE (and in general for finite ) can be demonstrated with the following example:

Suppose the target is . Let and , where all vectors are -dimensional. Then and . For large enough , the latter loss is larger than 1[25]. Yet intuitively, the latter model output is likely to be a much better approximation to the target value, from the perspective of the way the activation vector will be used for subsequent computation. Intuitively, we expect that for the activation vector to be good enough to trigger the right subsequent computation, it needs to be unambiguous whether a particular AND is present, and the noise in the value needs to be below a certain critical scale that depends on the way the AND is used subsequently, to avoid noise drowning out signal. To understand this properly we’d like a better model of error propagation.

It is no coincidence that our U-AND algorithm may be -accurate for small , but is not a minimum of the MSE. In general, -accuracy permits much more superposition than minimising the MSE, because it penalises interference less.

For a demonstration of this, consider a simplified toy model of superposition with hidden dimension and inputs which are all 1-hot unit vectors. We consider taking the limit as the number of input features goes to infinity and ask: what is the optimum number of inputs that the model should store in superposition, before sending the rest to the zero vector?

If we look for -accurate reconstruction, then we know how to answer this: a random construction allows us to fit at least vectors into -dimensional space.

As for the algorithm that minimises the MSE reconstruction loss (ie not sent to the zero vector in the hidden space), consider that we have already put of the inputs into superposition, and we are trying to decide whether it is a good idea to squeeze another one in there. Separating the loss function into reconstruction terms and interference terms (as in the original paper):

  • The th input being stored subtracts a term of order from the reconstruction loss
  • Storing this input will also lead to an increase in the interference loss. As for how much, let us write for the average mean squared dot product between the th feature vector and one of the feature vectors that were already there. Since the th feature has distinct features to interfere with, storing it will contribute a term of order to the interference loss.

So, the optimum number of features to store can be found by asking when the contribution to the loss switches from negative to positive, so we need an estimate of . If feature vectors are chosen randomly, then and we find that the optimal number of features to store is . In fact, feature vectors are chosen to minimise interference, which allows us to fit a few more feature vectors in (the advantage this gives us is most significant at small ) before the accumulating interferences become too large, and empirically we observe that the optimal number of features to store is . This is much much less superposition that we are allowed with -accurate reconstruction!

See the figure below for experimental values of for a range of . We conjecture that for each is the minimum of an exponential function which is independent of and something like a polynomial which depends on .

Experimental values of for a range of

3 The QK part of an attention head can check for many skip feature-bigrams, in superposition

In this section, we present a story for the QK part of an attention head which is analogous to the MLP story from the previous section. Note that although both focus on the QK component, this is a different (though related) story to the story about universal keys from section 1.4.

We begin by specifying a simple task that we think might capture a large fraction of the role performed by the QK part of an attention head. Roughly, the task (analogous to the U-AND task for the MLP) is to check for the presence of one in a large set of ‘skip bigrams’[26] of features[27].

We’ll then provide a construction of the QK part of an attention head that can perform this task in a superposed manner — i.e., a specification of a low-rank matrix  that checks for a given set of skip feature-bigrams. A naive construction could only check for feature bigrams; ours can check for feature bigrams. This construction is analogous to our construction solving the targeted superpositional AND from the previous sections.

3.1 The skip feature-bigram checking task

Let be a set of ‘skip feature-bigrams’; each element of is a pair of features . Let’s define what we mean by a skip feature-bigram being present in a pair of residual stream positions. Looking at residual stream activation vectors just before a particular attention head (after layernorm is applied), we say that the activation vectors at positions contain the skip feature-bigram if feature is present in and feature is present in . There are two things we could mean by the feature being present in an activation vector . The first is that is always either or for any in some relevant data set of activation vectors, and . The second notion assumes the existence of some background set in terms of which each activation vector has a given background decomposition, . In fact, we assume that all , with at most some constant number of for any one activation vector, and we also assume that the are random vectors (we need them to be almost orthogonal). The second notion guarantees the first but with better control on the errors, so we’ll run with the second notion for this section[28].

Plausible candidates for skip feature-bigrams to check for come from cases where if the query residual stream vector has feature , then it is helpful to do something with the information at positions where is present. Here are some examples of checks this can capture:

  • If the query is a first name, then the key should be a surname.
  • If the query is a preposition associated with an indirect object, then the key should be a noun/name (useful for IOI).
  • If the query is token T, then the key should also be token T (useful for induction heads, if we can do this for all possible tokens).
  • If the query is ‘Jorge Luis Borges’’, then the key should be ‘Tlön, Uqbar, Orbis Tertius’.
  • If the mood of the paragraph before the query is solemn, then the topic of the paragraph before the key should be statistical mechanics.
  • If the query is the end of a true sentence, then the key should be the end of a false sentence.
  • If the query is a type of pet, then the key should be a type of furniture.

The task is to use the attention score (the attention pattern pre-softmax) to count how many of these conditions are satisfied by each choice of query token position and key token position. That is, we’d like to construct a low-rank bilinear form such that the entry of the attention score matrix contains the number of conditions in which are satisfied for the query residual stream vector in token position and the key residual stream vector in the token position . We'll henceforth refer to the expression as , a matrix of size that we choose freely to solve the task subject to the constraint that its rank is at most . If each property is present sparsely, then most conditions are not satisfied for most positions in the attention score most of the time.

We will present a family of algorithms which allow us to perform this task for various set sizes . We will start with a simple case without superposition analogous to the 'standard' method for computing ANDs without superposition. Unlike for U-AND though, the algorithm for performing this task in superposition is a generalization of the non-superpositional case. In fact, given our presentation of the non-superpositional case, this generalization is fairly immediate, with the main additional difficulty being to keep track of errors from approximate calculations.

3.2 A superposition-free algorithm

Let’s make the assumption that is at most . For the simplest possible algorithm, let’s make the further (definitely invalid) assumption that the feature basis is the neuron basis. This means that is a vector in . In the absence of superposition, we do not require that these features are sparse in the dataset.

To start, consider the case where contains only one feature bigram .  The task becomes: ensure that is 1 if feature is present in and feature is present in and 0 otherwise. The solution to this task is to choose to be a matrix with zero everywhere except in the component: —with this matrix, iff the entry of is 1 and the entry of is 1. Note that we can write where , , and denotes the outer product/tensor product/Kronecker product. This expression makes it manifest that is rank 1. Whenever we can decompose a matrix into a tensor product of two vectors (this will prove useful), we will call it a _pure tensor_ in accordance with the literature. Note that this decomposition allows us to think of in terms of the query part and key part separately: first we project the residual stream vector in the query position onto the th feature vector which tells us if feature is present at the query position, then we do the same for the key, and then we multiply the results. 

In the next simplest case, we take the set to consist of pairs . To solve the task for this , we can simply perform a sum over for each bigram in , since there is no interference. That is, we choose

The only new subtlety that is introduced in this modification comes from the requirement that the rank of be at most which won't be true in general. The rank of is not trivial to calculate for a given . This is because we can factorize terms in the sum:

which is a pure tensor. The rank requirement is equivalent to the statement that can contain at most terms _after maximum factorisation_ (a priori, not necessarily in terms of such pure tensors of sums of subsets of basis vectors). Visualizing the set as a bipartite graph with nodes on the left and right, we notice that pure tensors correspond to any subgraphs of that are _complete_ bipartite subgraphs (cliques). A sufficient condition for the rank of being at most is if the edges of can be partitioned into at most cliques. Thus, whether we can check for all feature bigrams in this way depends not only on the size of , but also its structure.. In general, we can’t use this construction to guarantee that we can check for more than skip feature-bigrams. 

Generalizing our algorithm to deal with the case when the feature basis is not neuron-aligned (although it is still an orthogonal basis) could not be simpler. All we do is replace with the new feature basis, use the same expression for , and we are done.

3.3 Checking for a structured set of skip feature-bigrams with activation superposition

We now consider the case where the residual stream contains sparsely activated features stored in superposition. We'll assume that the feature vectors are random unit vectors, and we'll switch notation from to from now on to emphasize that the f-vectors are not an orthogonal basis. We'd like to generalize the superposition-free algorithm to the case when the residual stream vector stores features in superposition, but to do so, we'll have to keep track of the interference between non-orthogonal f-vectors. We know that the root mean square dot product between two f-vectors is . Every time we check for a bigram that isn't present and pick up an interference term, the noise accumulates - for the signal to beat the noise here, we need the sum of interference terms to be less than . We’ll ignore log factors in the rest of this section.

We'll assume that most of the interference comes from checking for bigrams where isn’t in and also  isn’t in — that cases where one feature is present but not the other are rare enough to contribute less can be checked later. These pure tensors typically contribute an interference of . We can also consider the interference that comes for checking for a clique of bigrams: let and be sets of features such that . Then, we can check for the entire clique using the pure tensor . Checking for this clique of feature bigrams on key-query pairs which don't contain any bigram in the clique contributes an interference term of