What Happens Inside a Single Transformer Layer?

Using the word revenue in a sentence, Anjana shows the four operations every transformer layer repeats: attention, feed-forward, residual connections and layer normalization. Stacking 12 or 96 of them gives models like BERT and GPT.

3:44 video3 min readWatch on YouTube

Every transformer layer does the same four things in the same order, and stacking enough of them gives you every modern language model. In this video, Anjana follows a single token, the word "revenue," through one layer to show what each operation contributes. The sentence used is about expecting revenue growth to moderate.

The four operations

The four operations in a layer are self-attention, a feed-forward network, residual connections and layer normalization. A transformer model can have dozens of layers, but each one repeats this same pattern. The video then takes the operations one at a time, following what the token sees on its way through.

Self-attention: gathering context

In the first step, the token needs to work out its role in the sentence. It creates three vectors from itself: a query, a key and a value. The query asks what the token should pay attention to. Every other token also has a key, and the query is compared against every key to produce a score, where a high score means high relevance. In the example, "revenue" scores high against "growth" and "moderate" because they directly affect its meaning, and low against "we" and "to" because they add no context. The scores become weights, and the weighted sum of all the values produces a new, context-aware representation of "revenue." The word has not changed, but now it knows what surrounds it.

The feed-forward network: processing what attention gathered

Attention told the token what to look at. The feed-forward network decides what to do with that information. It consists of two linear transformations with a non-linearity in between: the vector expands to a higher dimension, passes through an activation function, then compresses back down. This is where raw attention patterns become useful features. The video sums it up by saying attention gathers context and the feed-forward network processes it, and that this network never looks sideways at other tokens.

Residual connections and layer normalization

Two more operations hold the layer together. With residual connections, the original input is saved before attention and before the feed-forward step, and after each operation it is added back to the result. The model can therefore never completely forget what the token started as, and a layer that learns nothing useful passes the token through without damage. Layer normalization runs after each addition and rescales the values so they stay in a stable range. Without it, the video says, values would drift higher and higher through 12 layers and the model would break.

Stacking layers

Residual connections protect the signal and layer norm keeps the numbers in check. Together they are why you can stack 12, 24 or 96 layers and the model still trains. The video states that stacking 12 of these layers gives BERT and stacking 96 gives GPT, with the same four steps repeated each time.

Key takeaways

  • Each transformer layer performs attention, feed-forward, residual connection and layer norm in a fixed pattern.
  • Attention is the only step where a token looks at the rest of the sentence, using a query against every other token's key.
  • Scores from query-key comparison become weights over the value vectors.
  • The feed-forward network works on each token alone, processing what attention gathered.
  • Residual connections mean a layer that learns nothing does no harm.
  • Layer normalization keeps values in a stable range as layers stack.
  • The same building block repeated 12 times gives BERT, and 96 times gives GPT.

Try it yourself

The video ends with a prompt to paste into Claude. Take the sentence about expecting revenue growth to moderate and ask what self-attention would compute for the token "moderate" instead of "revenue," including which words it should score highest against and why. Then ask what the 12th layer would know about "moderate" that the first did not, and how you could check it.

Chapters

  1. 0:00The four operations inside every transformer layer
  2. 0:15Step 1: Self-attention and Query-Key-Value vector scoring
  3. 0:30Step 2: Feed Forward Networks and non-linear feature processing
  4. 0:50Step 3 & 4: Residual connections and layer normalization for stable stacking
  5. 1:10Stacking layers (BERT vs GPT) and hands-on Claude prompt
Full transcript(auto-generated, with timestamps)

The four operations inside every transformer layer

[0:00]Every Transformer layer does the same four things in the same order, and stacking enough of them gives you every modern language model. I'm Anjana. Here's what one token actually sees on its way through one layer. A Transformer model can have dozens of layers, but every layer does

Step 1: Self-attention and Query-Key-Value vector scoring

[0:16]The same four things in the same order. Self-attention, feed-forward, layer norm, residual connection. Here is what one token sees as it passes through one layer. Step one, self-attention. The

Step 2: Feed Forward Networks and non-linear feature processing

[0:30]Token revenue needs to understand its role in the sentence. It creates three vectors from itself, a query, a key, and a value. The query asks, "What should I pay attention to?" Every other token in the sentence also has a key. The query compares against every key and computes a score. High score means high relevance. Revenue scores high against

Step 3 & 4: Residual connections and layer normalization for stable stacking

[0:50]Growth and moderate because they directly affect its meaning. It scores low against we and to because they add no context. The scores become weights. The weighted sum of all values produces a new context-aware representation of revenue. The word has not changed, but now it knows what surrounds it. Step two, the

Stacking layers (BERT vs GPT) and hands-on Claude prompt

[1:11]Feed-forward network. Attention told revenue what to look at. Now the feed-forward network decides what to do with that information. It is two linear transformations with a non-linearity in between. The vector expands to a higher dimension, passes through an activation function that introduces non-linearity, then compresses back down. This is where the model transforms raw attention patterns into useful features. Attention gathers context. The feed-forward network processes it. Two more operations hold everything together. Residual connections. Before attention and before the feed-forward step, the original input was saved. After each operation, the original is added back to the result. This means the model can never completely forget what the token started as. If the layer learns nothing useful, the residual ensures the token passes through unchanged. No damage done. Layer normalization runs after

Each addition. It rescales the values so they stay in a stable range. Without it, values drift higher and higher through 12 layers and the model breaks. Residual connections protect the signal. Layer norm keeps the numbers in check. Together they are why you can stack 12, 24, or 96 layers and the model still trains. Four operations. Attention gathers context. Feed forward processes it. Residual connections protect the signal. Layer norm keeps it stable. Stack 12 of these and you have BERT. Stack 96 and you have GPT. Same four steps repeated. That is a transformer. Let's recap with Claude. Attention is the only step where a token looks at the rest of the sentence. It gathers context and it does it with a query against every other token's key. The feed forward

Network never looks sideways. It processes what attention gathered. The residual connection means a layer that learns nothing does no harm and layer norm keeps the numbers from drifting as you stack. Four operations. That is the entire building block. Your turn. Take the sentence we expect revenue growth to moderate and walk me through what self attention would compute for the token moderate instead of revenue. Which other words should it score highest against and why? Then tell me honestly, if I stacked 12 of these layers, what does the 12th layer know about moderate that the first one didn't and how would I even check? Paste that into Claude and find out whether you can predict what a layer will pay attention to before it does. Attention, feed forward, residual, norm. That's Enjana.

More from Humanitarians AI Fellows

Humanitarians AI Lyrical Literacy Project