dopetalk does not endorse any advertised product nor does it accept any liability for it's use or misuse


Our Discord Notification Server invitation link is https://discord.gg/jB2qmRrxyD

Author Topic: What Happens Inside a Transformer Block ? Is Attention Really All You Need ?  (Read 702 times)

Offline Chip (OP)

  • Server Admin
  • Admin
  • Hero Member
  • ****
  • Administrator
  • *****
  • Restrictive
  • *
  • RC Discussion
  • **
  • Private
  • ***
  • Owner
  • *****
  • Join Date: Dec 2014
  • Location: Australia
  • Posts: 7516
  • Reputation Power: 0
  • Chip has hidden their reputation power
  • Gender: Male
  • Last Login:Yesterday at 09:59:55 PM
  • Deeply Confused Learner
  • Profession: IT Engineer now retired
Multi Head Attention:

How 8 Attention heads work in parallel and combine their output.

Skip Connections and Layer Normalization:

Why Transformers use shortcuts and how they help deep networks train effective.

The Feed Forward Network:

How each token is processed independently to build richer representations.

Stacking Encoder Blocks:

How multiple blocks transform the input into increasingly useful representations.

“Encoding” is tarnslating text into numbers, and “Decoding” is translating numbers into text

Quote
Self attention gets all the hype, but did you know roughly two thirds of a transformer's trainable parameters lie outside attention ?

So is attention really all you need ? Let's explore everything inside a transformer block step by step.

We're translating English to French and our input sentence is "The cat sat on the mat."

6 tokens, each token becomes an embedding, and positional encoding is added, giving us our input matrix x 6 by 512, x enters the encoder.

Inside one encoder block, there are 4 steps and 2 skip/residual connections. Attention holds one third of the parameters, the feed forward  network the other two thirds.

Step one, multi head attention, each token looks at the others and gathers the information it needs. 8 heads work in parallel, then their outputs are combined. The output is z.

Step two, add and normalize. 

We add the original input x to the attention output z through a skip connection (also called a residual connection) 

This lets the model build on the original representation while helping gradients flow backward, making deeper networks easier to train.

Then layer norm normalizes each token row by row, keeping its value stable.

Step three, feed forward network.

Attention gathers information from other token.

The feed forward network processes it, transforming each token's representation independently.

We multiply by a 512 by 2048 weight matrix, giving us  6 by 2048.

We add a bias, then apply ReLU (rectified linear unit), introducing non-linearity so the network can learn complex patterns.

Then we multiply by a 2048 by 512 weight matrix, add another bias, and return to 6 by 512.

Step four, add and normalize.

We add the feed forward output to its input, then normalize.

The result is still 6 by 512. That's one complete encoder block.

The original transformer stacks 6 blocks.

Every block preserves the 6 by 512 shape, so its output becomes the next block's input.

After 6 blocks, the encoder produce 6 representations, each 512 numbers long.
« Last Edit: October 18, 2026, 08:55:38 AM by Chip »
friendly
0
funny
0
informative
0
agree
0
disagree
0
like
0
dislike
0
No reactions
No reactions
No reactions
No reactions
No reactions
No reactions
No reactions
Our Discord Server invitation link is https://discord.gg/jB2qmRrxyD

Tags:
 


dopetalk does not endorse any advertised product nor does it accept any liability for it's use or misuse





TERMS AND CONDITIONS

In no event will d&u or any person involved in creating, producing, or distributing site information be liable for any direct, indirect, incidental, punitive, special or consequential damages arising out of the use of or inability to use d&u. You agree to indemnify and hold harmless d&u, its domain founders, sponsors, maintainers, server administrators, volunteers and contributors from and against all liability, claims, damages, costs and expenses, including legal fees, that arise directly or indirectly from the use of any part of the d&u site.


TO USE THIS WEBSITE YOU MUST AGREE TO THE TERMS AND CONDITIONS ABOVE


Founded December 2014
SimplePortal 2.3.6 © 2008-2014, SimplePortal