Skip to content
AI360Xpert
Core ML

Visual explainer

Transformers

A visual walkthrough of the Transformer architecture, from self-attention and positional encodings to the full encoder-decoder stack.

Self-Attention resolves ambiguity by processing tokens in context.
Self-Attention resolves ambiguity by processing tokens in context.

Traditional networks process text sequentially, creating a bottleneck and struggling with long-term dependencies. Transformers break this limit by processing everything at once. Their secret is Self-Attention — a mechanism where every token looks at every other token to figure out its contextual meaning. In the example above, the word "bank" heavily attends to "river", clarifying that it's a river bank, not a financial institution.

Knowing the Order

Positional encodings inject sequence order into parallel representations.
Positional encodings inject sequence order into parallel representations.

Because self-attention reads all tokens in parallel, the model has no inherent sense of sequence. If you scramble a sentence, a naive parallel model would output the exact same final representations. To fix this, Transformers inject Positional Encodings — unique mathematical signals — directly into the word embeddings. This addition creates position-aware vectors, letting the network know exactly where each word sits in the text.

The End-to-End Architecture

The complete architecture connects an Encoder stack to an autoregressive Decoder stack.
The complete architecture connects an Encoder stack to an autoregressive Decoder stack.

The complete Transformer relies on a tightly coupled Encoder-Decoder structure:

  1. The Encoder takes the input sequence and passes it through layers of Self-Attention and Feed-Forward networks. This builds a deep, contextual representation of the entire text.
  2. The Decoder uses that learned representation via Cross-Attention to generate the final output, one token at a time. It uses Masked Attention to ensure it can only look at tokens it has already generated, preventing it from "cheating" by looking into the future.