Stacked blocks that mix across tokens with attention, then refine each token with a feed-forward net — held stable by residual shortcuts and normalization.
The transformer, introduced in the 2017 paper *Attention Is All You Need*, processes a whole sequence at once instead of stepping word by word like an RNN. That parallelism is what made training on internet-scale data practical, and it's the backbone under GPT, BERT, and essentially every modern LLM.
A transformer block has two sub-layers. First, multi-head self-attention lets tokens exchange information — this is the only step where tokens see each other. Second, a small feed-forward network (two linear layers with a non-linearity between them) refines each token *on its own*, identically across positions. Attention mixes across tokens; the feed-forward layer thinks per token.
# one transformer block (pre-norm, as in most modern LLMs)
a = x + MultiHeadAttention(LayerNorm(x)) # mix across tokens
y = a + FeedForward(LayerNorm(a)) # refine each token
return yThe original 2017 model was an encoder-decoder for translation: 6 encoder blocks and 6 decoder blocks, d_model = 512, a feed-forward inner size of 2048, and 8 attention heads. Modern models keep the block but scale the count — GPT-3 stacks 96 decoder blocks.
d_model — usually accounts for roughly two-thirds of a transformer's weights. Attention routes information; the feed-forward layers store much of what the model knows.