AI Engineer World's Fair 2024
Spreadsheets-are-all-you-need: Decoding the Decoder LLM without de code
Read the talk
Spreadsheets are all you need: a decoder model on the operating table
Ishan Anand opens up a language model in Excel, follows a weekday prediction through its layers, and changes a completion by adding a vector.
From a talk by Ishan Anand
Turn sentence completion into a spreadsheet calculation
How can a computer complete Mike is quick, he moves with quickly? Ishan Anand approaches that question wearing scrubs: the audience will become AI brain surgeons, GPT-2 Small is the patient, and an Excel workbook is the operating table. His Spreadsheets are all you need project implements the model using pure Excel functions, without Python or model API calls. Anand describes more than 150 tabs and more than 124 million parameter cells. For engineers without a machine-learning degree, the demonstration offers three ways into that machinery: study its anatomy, inspect it with a virtual MRI, then intervene with a little brain surgery.
Computers already know how to complete a different kind of expression: 2 + 2 = 4. To make sentence completion computational, the model turns a word problem into a numerical one. It breaks text into tokens, maps those tokens to embeddings, and processes the resulting numbers through multi-headed attention and a multilayer perceptron, or MLP. An embedding is a vector of many numbers, not the single number used in the introductory illustration. The output also differs from elementary arithmetic: instead of one exact answer, the model produces a distribution over possible next tokens. Selecting a token and converting it back into text completes the path from language to numbers and back again.
Suggest correction
This note stays in this page until you copy or download it. Nothing is submitted; reloading clears the draft.
Inspect tokens and their 768-number embeddings
The workbook makes that path navigable through its tabs. Entering the opening prompt produces quickly. For this spreadsheet's next-token calculation, Anand reports a wait of about 30 seconds. Excel is serving as an inspection tool here; he explicitly warns against using this implementation in production.
Tokenization is the first operation to inspect. The words in the initial example fit into individual tokens, but that is not a general rule. Two contrasting examples expose the difference between a tokenizer's units and a reader's intuition:
funologysplits intofunandology, a division that resembles meaningful word parts.reinjurysplits intoreinandjury, rather than the intuitive prefixrefollowed byinjury.
The algorithm selects frequent subword units. Those units can line up with morphemes, but they need not preserve a word's linguistic structure. A token is therefore neither reliably a whole word nor reliably a meaningful part of one.
Next comes the embedding lookup. Each token in GPT-2 Small has a 768-number embedding. In the displayed sheet, tokens occupy separate rows, with their embeddings beginning in column 3. The row for Mike stretches through column 770. Scrolling across that row makes the representation tangible: the model processes a long vector for each token, not a single numerical label.
Suggest correction
This note stays in this page until you copy or download it. Nothing is submitted; reloading clears the draft.
Read a causal attention head and an MLP
The next tabs contain the model's layers. Attention lets a token position gather context from other positions: he can refer back to Mike, while the position containing moves can draw on the earlier quick. That context matters because quick can describe physical speed, wit, the sensitive tissue beneath a fingernail, or—in an older usage—the living. At moves, the surrounding phrase supports a continuation about movement, such as quickly or fast. The model has twelve blocks, numbered 0 through 11, each with attention followed by an MLP.
Inside one attention head, a table shows how strongly each token position attends to the others. The zeros above the diagonal encode a constraint: a position can use itself and earlier positions, but cannot look ahead. This is causal masking. Each row's attention weights sum to one, and the initial Mike position can only attend to itself. In the displayed head, the query token he assigns approximately 0.48 of its attention weight to the key token Mike. That is an interpretable relationship in this particular head; other heads are less immediately legible, and an attention weight alone does not establish a token's causal importance to the final answer.
Further down the sheet, the MLP makes another part of the computation visible. Excel's MMULT performs matrix multiplication by learned weights, and an activation function supplies the nonlinear transformation. The spreadsheet exposes these as ordinary calculations: attention gathers contextual information, and the MLP transforms the resulting representation.
Suggest correction
This note stays in this page until you copy or download it. Nothing is submitted; reloading clears the draft.
Project the final state into next-token scores
The language head turns the final token position's representation into scores for possible continuations. This operation is called unembedding: a projection into the vocabulary, rather than a literal reversal of the original embedding lookup. The workbook uses greedy selection—the behavior described here as temperature zero—so its output is the highest-scoring candidate.
The displayed calculation starts with block 11's output, applies LayerNorm, then uses another MMULT with the unembedding matrix. The resulting values are logits, or raw token scores. Probabilities are a normalized interpretation of those scores; the two should not be confused. For greedy selection, the distinction does not change the winner: the largest logit also corresponds to the largest probability. The next sheet finds that maximum, obtains its token ID, and looks up the corresponding text. That finishes the forward pass for one next-token prediction.
Suggest correction
This note stays in this page until you copy or download it. Nothing is submitted; reloading clears the draft.
Use the residual stream as an inspection point
Before the virtual MRI, one architectural detail changes how to picture the whole network: residual connections. Addition operations preserve an existing representation while adding contributions from attention or the MLP. Information therefore has a path around each transformation, rather than having to be replaced by that transformation's output.
Imagine the residual stream as a highway with one lane per token position. Attention moves information between lanes; the MLP transforms information within each lane. Successive layers read from and write to this shared stream. The logit lens uses that arrangement as an inspection point: apply the language head to intermediate representations and examine the candidate tokens it exposes. These projections provide a vocabulary-level view of the computation before the final layer. They are useful observations of intermediate states, rather than literal transcripts of the model's thoughts.
Suggest correction
This note stays in this page until you copy or download it. Nothing is submitted; reloading clears the draft.
Follow Wednesday through the network
The MRI example begins with If today is Tuesday, tomorrow is, which the model completes with Wednesday. The talk reports correct next-day completion for all seven weekday variants of this prompt. Yet the intermediate views do not steadily announce the correct answer. At block 3, the final token position's leading candidates are not, still, and just. None is the desired weekday.
The inspection then searches for Wednesday elsewhere in the chart. At block 0, it appears among the displayed candidates at the position containing Tuesday, then disappears from the displayed lists. In later layers, time-related candidates surface: tomorrow, forever, Tuesday, and Friday. Wednesday returns in third place before rising to the leading position and remaining there. Disappearing from these short candidate lists does not mean all information about Wednesday has vanished from the residual stream.
The talk reports a circuit of four components sufficient for correct completion across the seven weekday variants. The components are:
- The layer-0 MLP.
- One attention head in layer 9.
- The layer-9 MLP.
- Attention in layer 10.
That component-isolation result is attributed to researchers; it is a stronger claim than simply observing the logit-lens chart. The visible trace is consistent with early processing followed by useful information becoming prominent again in later layers. Together, the components illustrate a circuit for this particular task, with different layers communicating through the residual stream.
Suggest correction
This note stays in this page until you copy or download it. Nothing is submitted; reloading clears the draft.
Find a feature that can be steered
With the anatomy and MRI complete, the demonstration moves to surgery. Its inspiration is Golden Gate Claude, the bridge-obsessed version of Claude associated with Anthropic's Mapping the mind of a large language model. The conceptual tool is a sparse autoencoder: another learned model that decomposes residual-stream activations into features whose meanings researchers investigate. Once a feature has an interpretable association, an intervention can amplify or suppress its contribution to the residual stream and change the language model's behavior.
The talk credits Joseph Bloom, Neel Nanda, and collaborators with developing sparse-autoencoder features for open models such as GPT-2 Small. The feature selected for this operation is associated with Jedi: feature 7650 in the demonstration's layer-2 autoencoder. Its index identifies a feature within that particular autoencoder, not a universal Jedi coordinate shared by language models.
Suggest correction
This note stays in this page until you copy or download it. Nothing is submitted; reloading clears the draft.
Change the completion by adding a decoder vector
The intervention begins with the Jedi feature's decoder vector. The workbook multiplies that vector by a coefficient, arranges it for injection, and adds it to the residual stream at the start of block 2. If the existing residual representation is r, the decoder direction is d_Jedi, and the coefficient is α, the operation is simply:
The prompt is Mike pulls out his. Without the intervention, the displayed completion is phone. Turning on the Jedi direction changes the model's internal representation while leaving those input words fixed.
Selecting Calculate now starts the spreadsheet's recalculation. While Excel works, the talk distinguishes the current operation from nearby steering methods:
- Anthropic's feature intervention shares the idea of changing internal features, but its procedure differs from this decoder-vector addition.
- Representation engineering, as described here, derives a steering direction using principal component analysis, or PCA.
- Activation steering can construct a direction from contrasting activations: run the model on an input associated with what should be amplified, such as Jedi, and another associated with what should be suppressed, such as phone. Subtract the latter activations from the former and inject the resulting direction into the residual stream.
Then the calculation finishes. Against the earlier phone baseline, the completion is now lightsaber:
| Fixed prompt | Intervention state | Displayed completion |
|---|---|---|
Mike pulls out his | Jedi direction off | phone |
Mike pulls out his | Scaled Jedi decoder vector added at block 2 | lightsaber |
The audience cheers: the patient has become a Jedi. The successful-operation metaphor lands because the change is so concrete—the same prompt, with an added internal vector, now produces a different continuation.
Suggest correction
This note stays in this page until you copy or download it. Nothing is submitted; reloading clears the draft.
Carry architectural understanding into prompting
Opening the model helps engineers understand tool behavior and limitations, follow new research, and explain results to stakeholders without treating the system as magic. The closing example brings that architectural knowledge back to an everyday engineering task: arranging a prompt.
The talk compares a conventional transformer prompt template with one for RWKV. The RWKV template shown recommends swapping the relative order of instructions and context, because its mechanism does not access earlier information in the same way as transformer attention. This is a recommendation attached to the demonstrated template, rather than a universal rule about prompt order. It shows how a difference inside the model can affect the way an engineer supplies information at its input.
The closing handoff points to the research behind the demonstration and invites viewers to download the workbook. At the time of the recording, Anand also announces a Maven course covering the spreadsheet step by step. The workbook itself offers the immediate experiment: enter a prompt on your own machine, move through the tabs, and follow the numbers that produce its continuation.
Suggest correction
This note stays in this page until you copy or download it. Nothing is submitted; reloading clears the draft.
Resources
From the talk
Anand's workbook makes the model's forward pass inspectable through ordinary spreadsheet functions.
The 2024 feature-steering work behind Golden Gate Claude, contrasted with Anand's GPT-2 intervention.
Further reading
Current tooling for sparse autoencoders; use a matching historical checkpoint before attempting to reproduce the Jedi feature.
Read the complete timestamped transcript
- 0:00
[upbeat music] Hope you're all having a good conference. And I hope you're ready because if you came to this conference or the AI engineering field
- 0:24
without a machine learning degree, then this is gonna be your crash course in how machine learning models actually work under the hood.
- 0:35
Let's, let's bring up, uh, the slides. There we go. Thank you. Okay. So I'm Ishan, and I'm dressed in scrubs because today we're all going to be AI brain surgeons, and our patient will be none other than GPT-2, an early precursor to ChatGPT.
- 0:58
And our operating table will be a table, but it'll be a table of numbers. It'll be an Excel spreadsheet. This Excel spreadsheet implements all of GPT-2 Small entirely in pure Excel functions.
- 1:15
No API calls, no Python. In theory, you can understand GPT-2 just by going tab by tab, function by function through this spreadsheet. But you wanna hold onto those VLOOKUPs because there's over 150 tabs and over 124 million cells for every single one of the parameters in GPT-2 Small.
- 1:36
I will give you the abbreviated tour. So we'll do three things today in our little med school. First, we'll study the anatomy of our patient, how he's put together.
- 1:46
Then we're gonna put him through a virtual MRI to see how he thinks. And then finally, we're gonna change his thinking with a little AI brain surgery.
- 1:57
Okay. Let's start with anatomy. You're probably familiar with the concept that large language models are trained to complete sentences, to fill in the blank of phrases like this one.
- 2:07
Mike is quick, he moves. And as a human, you might reasonably guess quickly. But how do we get a computer to do that? Well, here's a fill-in-the-blank that computers are very good at.
- 2:17
Two plus two equals four, right? They're really good at math. In fact, you can make it very complex and they do it very well. So what we're gonna do, in essence, is we're gonna take a word problem and turn it into a math problem.
- 2:29
In order to do that, we take our whole sentence or our phrases and we break them into sub-word units called tokens, and then we map each of those tokens onto numbers called embeddings.
- 2:40
Now, I've shown it for simplicity here as a single number, but in the embedding for each token is many, many, many numbers, as we'll see in a bit. And then instead of the simple arithmetic shown here, we're doing the much more complex math of multi-headed attention and the multi-layer perceptron.
- 2:55
Multi-layer perceptron, just another name for a neural network. And then finally, instead of getting one precise, exact answer like you used to get in elementary school, we're gonna interpret the result as a probability distribution as to what the next token should be.
- 3:10
So here's our setup. We get input text, we turn that text into tokens, we turn those tokens into numbers, we do some number crunching, and then we reverse the process.
- 3:21
We turn the numbers back out into tokens or text, and then get our next-token prediction.
- 3:26
So this handy chart shows where each of those actions maps to one or more tabs inside our friendly patient spreadsheet. Let's take a look. So the first thing you do is we get our prompt, right?
- 3:38
Here the prompt is, "Mike is quick, he moves." And then it will output after about 30 seconds since we're running in a spreadsheet, don't use this in production, the next predicted token of quickly.
- 3:49
So the first step is to split this into tokens. Now, you see that every word here goes into a single token, but that's not always the case. In fact, it's not uncommon to be two or more tokens.
- 4:00
Let me give you some examples. So here's another version of the sheet. Let me zoom this up so you can see it a little better. Right. I've put actually some fake words.
- 4:08
Reinjury is a real word, but funology isn't a real word. Uh, but you know what it means, right? Because it's the word fun with ology put together. Those are the morphemes as linguists like to call them.
- 4:18
And the tokenization algorithm actually is able to recognize that in some cases. Whoa, there we go. Right there.
- 4:28
You see fun split into fun and ology. If we zoom that one up.
- 4:34
There we go. But it doesn't always work. So notice how reinjury got split up right here. It's rain and jury, and that's 'cause the algorithm's a little dumb. It just picks the most common sub-word units it finds in its iterations, and it doesn't always map to your native intuition.
- 4:49
And so in practice, machine learning experts feel like it's a necessary evil. Um, and then the next step is we have to map each of these tokens to the embeddings.
- 5:00
So let's go back to the original one, and that's in this tab here. So we have each of our tokens in a separate row, and then right here, starting in column three, is where our embeddings begin.
- 5:10
So this is row right here. The second row is all the embeddings for Mike. Now, in the case of GPT-2 Small, the embeddings are 768 numbers, so we're starting column three.
- 5:20
So that means if we go to column 770, we will see the last end of this. And so there's the end of our embeddings for Mike. And let's go back.
- 5:31
And each one of these, again, is the embedding for, uh, each token. Okay. Then we get to the layers. This is the heart of the number crunching. So there are two key components.
- 5:42
There's attention, and then the neural network or multi-layer perceptron. And in the attention phase, basically the tokens look around at the other tokens next to them to figure out the context in which they sit.
- 5:52
So the token he might look at the word Mike to look at the antecedent for its pronoun, or moves might look at the word quick because quick actually has multiple meanings.
- 6:03
Quick can mean movement in physical space, it can mean smart as in quick of wit, it can mean a body part like the quick of your fingernail, and in Shakespearean English, it can mean alive or dead, like the quick or the dead.
- 6:15
And seeing that the word moves here helps it disambiguate for the next layer, the perceptron, that, oh, we're talking about moving in physical space. So maybe it's quickly or maybe it's fast or maybe it's around, but it's certainly not something about your fingernail.
- 6:29
So let's see where this is all happening. So these are our layers. Now, there's twelve of them. So this is block zero all the way to block eleven. Each one's a tab.
- 6:37
And then if you go up here, we can't go through all of this in the time we have, but this is one of the attention heads. This is step seven.
- 6:43
This is where you can see where each token is paying attention to every other token. And you'll notice that there's a bunch of zeros up at the top right, and that's because no token is allowed to look forward.
- 6:54
They can only look backwards in time. And you'll see here that Mike is looking at Mike a hundred percent of the time. Higher values mean more attention. These are all normalized to one.
- 7:03
Uh, here is the word he, or the token he, I should say. And you'll notice zero point four eight, so about half of its attention, is focused on its an- the antecedent of its pronoun.
- 7:11
Now, this is just one of many heads. If I scroll to the right, you'll see a lot more. Uh, there aren't always as directly interpretable as that, uh, but it gives you a sense of how the attention mechanism works.
- 7:21
And then if we scroll further down, we'll see the multi-layer perceptron right here. If you know something about neural nets, you know they're just a large combination of, uh, multiplications and additions or a, a ma-matrix multiply.
- 7:33
And so I don't know if you can see this in the back. There's a MMULT, which is how you do an Excel matrix multiply, and that's basically multiplying it times its weight.
- 7:40
And then here we put it through its activation function to get the next prediction. Okay, let's keep going.
- 7:49
Okay. Next, we have the language head, and this is where we actually reverse the process. So what we do is we take the last token and we unembed it and reverse the embedding process we did before, and we probabilistically look at which are the tokens the closest to the final last token's unembedding.
- 8:11
And we interpret that as a probability distribution. Now, if you're at temperature zero, like we are in this spreadsheet, then you just take the thing with the highest probability.
- 8:19
But if your temperature is higher, then you sample it according to some algorithm like beam search. Let's take a look.
- 8:27
And we'll go here. So, um, again, I don't know if you can see in the back, but this function here is basically... There we go.
- 8:40
This function in the back basically is taking block eleven, the output of the very last block. It's putting it through a step called LayerNorm. Then we multiply it, another MMULT, times the unembedding matrix, and these are what are known as our logits.
- 8:54
And then to predict the next most likely token,
- 8:58
we just go to the next one. I don't know if you can see this function. It basically is looking at max of the previous column you saw in the previous sheet.
- 9:06
Um, and it's taking the, the highest probability token just like that, and that's our, our predicted token. We get a token ID, then we look it up in the matrix, and we know what the, the next likely token is.
- 9:16
Okay. So that's the forward pass of how GPT-2 works. But how do all those components work together? So let's take our patient and put him through a virtual MRI so we can see how he thinks.
- 9:27
Before we do that, there's something I forgot to mention. These are called residual connections. Inside every layer, there's an addition operation. And what this lets the model do is it lets it route information around and completely skip any part of these layers, either attention or the perceptron.
- 9:44
And so you can reimagine the model as actually a communication network or a communication stream. So the residual stream here is every one of those tokens and information is flowing through them like an information superhighway.
- 9:57
And what each layer is doing is we've got attention moving information across the lanes of this highway and then the perceptron trying to figure out what the likely token is for every single lane of the highway.
- 10:08
But there are multiple of these layers, so they're really reading and writing to each other information in this communication bus. What we can do is we can do a technique called logit lens.
- 10:17
We can take the language head we talked about earlier and stick it in between every single layer of the network and what was it thinking at that layer. So that's what I've done in this sheet.
- 10:29
So I gave it the prompt, "If today is Tuesday, tomorrow is," and the predicted token is Wednesday. And GPT-2 does this correctly for all seven days. And what you see in this chart is essentially the columns here from three through nine are all those lanes of the information superhighway.
- 10:45
And for example, here at block three, this is the top most predicted token at the last token position. So it predicted not. The second most likely word was gonna be still, then it was gonna be just.
- 10:58
These are all wrong. So let's look for what we know is the right answer, Wednesday. So over here at block zero, we see Wednesday. It's at the bottom of the Tuesday stream for some reason on that highway.
- 11:09
Well, it makes sense it'd be close to Tuesday. And then it completely disappears.
- 11:13
And then, oh, over here towards the last few layers, suddenly we see tomorrow, forever, Tuesday, Friday. It knows we're talking about time, we're talking about days. And it gets Wednesday, but it's still the third most likely token.
- 11:24
And then finally it moves it up to the final position, and then it locks it into place. So what's going on here? Well, a series of researchers, uh, basically took this logit lens technique on steroids and isolated that only four components out of the entire network were responsible for doing this correctly over all seven days.
- 11:43
What they found was that all you needed was the perceptron from layer zero, attention from layer nine, and actually only one head, uh, the perceptron from layer nine, and then attention from layer ten.
- 11:55
And that's kind of what we saw in the sheet, right? At the top, we saw Wednesday, and then it disappeared until the later layers pulled it back up and up in probability at towards the end of the process.
- 12:05
So it's an example of where you can see each layer acting as a communication bus trying to jointly figure out and create what they call a circuit to accomplish a task.
- 12:15
Okay, we are now out of med school and ready for surgery.
- 12:19
So you may have heard about, uh, the pioneering work that Anthropic has done about scaling mono-semanticity. This gave rise to what was known as Golden Gate Claude. It was a version of Claude that was very obsessed with the Golden Gate Bridge.
- 12:31
To some, it felt like it thought it was the Golden Gate Bridge. Uh, conceptually, here's how this process worked. You have a large language model, and then you have this residual stream we talked about earlier, and then you use another AI technique, an autoencoder.
- 12:45
This one's a sparse autoencoder, and you ask it to look at the residual stream and separate it out into interpretable features. And you then try and deduce what each feature is, and then you can actually turn up and down each of these features back in the residual stream in order to amplify or suppress certain concepts.
- 13:04
It turns out a team of researchers led by Joseph Bloom, Neel Nanda, and others are building out sparse autoencoder features for open source models like GPT-2 Small. So here, for example, is layer two's feature 7650.
- 13:21
I don't know if you can see it in the back. It's basically everything Jedi.
- 13:25
So gone to our friendly patient again, and I've taken the vector for
- 13:34
that feature while we wait for Excel to wake up. There it is. That first row is essentially what they call the decoder vector corresponding to Jedi. And then I've basically multiplied by a coefficient, and then I've basically formatted it so that I can inject it right into the residual stream.
- 13:50
So this is the start of the block. You can see that steer block two, it's basically just taking that vector I showed you and adding it into the residual stream.
- 13:58
Simple addition. Now we go to our prompt, and originally, normally you ask GPT-2, Mike pulls out his... Makes sense. He pulls out his phone. But if we turn the Jedi steering vector on, I'll give you one guess what he's probably gonna pull out.
- 14:15
Let's see. Okay, so now we hit Calculate now. Um, and this is where you get to witness the 30 seconds it takes. Um, and while we wait for it to, to run, a couple notes.
- 14:24
So first of all, the way Anthropic did their steering was slightly different, but similar in spirit. There's a few other ways to do this kind of steering. One of those is called representation engineering, where the steering vector is deduced via PCA or Principal component analysis.
- 14:39
And there's another technique called activation steering, where what you do is you take the thing you wanna amplify, like Jedi, and you'd run the model through just on that token, and then you'd run it on something you might wanna suppress, like in this case, phone, and then you'd create a phone-- a Jedi minus phone vector and inject
- 14:56
that into the residual stream. Okay, there it is. There it is. Mike pulls out his lightsaber. There we go. [audience cheering] We have done it. [audience applauding]
- 15:08
Our operation has been a success. We've created the world's first GPT-2 Jedi. Stick that on LM系Siriina. Okay. Uh, well, hopefully I've given you a little better insight into how large language models work, but also why they work.
- 15:24
But the root message I wanna leave with is that to be a better AI engineer, it does help to un-rock the black box. Partly, this is about just knowing your tools and their behavior and their limitations better.
- 15:34
Uh, but also we're in a very fast-moving field, and if you wanna understand the latest research, it helps to know how these work. And then last but not least, when you communicate with non-technical stakeholders, there's very often a perception of magic, and the more you can clear that up, the more you can clear up misunderstandings.
- 15:50
I'll give you just one example of where this bubbles up, where architecture bubbles up to how you use them. So this is the, uh, instructions for RWKV, which is a different type of model.
- 15:59
But the template for a normal transformer's at the top, the template for an RWKV, uh, prompt is at the bottom. And what's interesting is that they recommend you swap the traditional order of instructions and context because the attention mechanism or the pseudo-attention mechanism in RWKV can't look back the same way a regular transformer can.
- 16:17
So it's a great example of where model architecture matters all the way up to prompting. Okay, here are the references for the research we talked about today. And then if you want to learn more, you can go to Spreadsheets-are-all-you-need.ai, and you can download this spreadsheet, and you can run it on your own device.
- 16:36
If you want to see me go through every single step of this spreadsheet, I just launched a course on Maven today, um, and the link to it is on that website as well.
- 16:46
Um, and that's it. Thank you. [upbeat music]