About

What Is a Transformer? Parallel Processing with Self-Attention

How it got past the sequential limits of RNNs

Transformer is a design, not a model. It comes from Google's 2017 paper "Attention Is All You Need". Use only the Encoder and you get BERT. Use only the Decoder and you get LLMs like GPT, Claude and Gemini.

Before it, RNNs and LSTMs had to read a sentence one word at a time from the front, which made them hard to parallelize, and early information faded in long sentences. Transformer uses Self-Attention to look at every position in the sentence at once. Each token gets Query, Key and Value vectors, and the model computes how much to rely on every other token (the attention score). Order information is added separately with Positional Encoding.

Don't mix up three kinds of names

I once watched a chain of questions go from "How is an LLM different from deep learning?" to "Is BERT a subcategory of deep learning?" to "Is Claude part of the GPT family?" The sticking point was always the same: architecture names (Transformer, Encoder, Decoder), model names (BERT, GPT, Claude) and tool names (Hugging Face transformers, Claude Code) mixed in one sentence. Separating the three cleared it all up.

For Rails developers this analogy landed fastest.

MVC pattern       <->  Transformer architecture     (the concept, a design)
Rails / Django    <->  Hugging Face transformers    (code that makes the concept easy to use)

Transformer is a design. Models pick parts of it.Transformer (2017)Attention Is All You NeedEncoder-onlyBERTunderstand: classify, searchDecoder-onlyGPT, Claude, Gemini, Llamagenerate: chat, writeEncoder-Decoderoriginal paper, T5convert: translateEncoder sees both sides of a blank. Decoder only sees what came before.HF transformers is a Python library, not the architecture.

The Encoder/Decoder difference is whether you can see ahead. The Encoder fills a blank like "I am a [?]" by looking at both sides. The Decoder sees only "I am a" and predicts the next token, with everything after hidden by a causal mask.

BERT (Encoder) GPT-style LLM (Decoder)
Training Fill in the blank Predict the next token
Good at Classification, search, embeddings Generation, chat, reasoning
Size 110M (base), 340M (large) parameters Billions and up

A few more names worth sorting out. GPT is OpenAI's model brand, so it doesn't mean "decoder-only". Claude and Gemini are decoder-based LLMs built separately by Anthropic and Google, not GPT variants. Claude Code and ChatGPT are tools and apps that use models, not models.

LLM is a different axis

Saying "Transformer contains LLMs and BERT" mixes two axes. Encoder-only and decoder-only are about architecture. LLM (large language model) is about size and purpose. They get used like synonyms only because almost every LLM today happens to be decoder-only.

Same architecture, different performance

The skeletons are similar, sure. The differences come from outside the architecture: size (parameters, layers), training data, post-training (RLHF and the like) and the tokenizer all differ, and the weights that result are completely different. Shopify and a personal blog are both MVC, and nobody calls them similar apps. What the weights actually hold is continued in Architecture is the circuit, weights are the knob positions.

If model names and architecture keep getting mixed up in your team's discussions, feel free to ask negabaro.

Key Concepts

1

Split input text into tokens → convert each token to an embedding vector

2

Add Positional Encoding — add position information to vectors

3

Generate Query (Q), Key (K), Value (V) vectors for each token

4

Compute Attention Score: softmax(QK^T / √d) × V — determines how much each token attends to others

5

Multi-Head Attention: perform multiple attentions in parallel → capture diverse relationship patterns

6

Generate final output with Feed-Forward Network + Layer Normalization + Residual Connection

Pros

  • ✓ Fully parallelizable → maximizes GPU utilization
  • ✓ No information loss in long sequences (Self-Attention)
  • ✓ Universally applicable to diverse tasks
  • ✓ Scaling law (larger models yield better performance)

Cons

  • ✗ O(n²) memory — memory usage scales quadratically with sequence length
  • ✗ Requires massive GPU/TPU for large-scale training
  • ✗ Position information must be encoded separately
  • ✗ Directly reflects biases in training data

Use Cases

GPT series (GPT-4, GPT-4o) Claude (Anthropic) BERT / RoBERTa (sentence understanding) T5 / BART (translation, summarization) Vision Transformer (ViT)
← What Is a Neural Network? Layers, Weights, and Backpropagation What Is Pre-training? How LLMs Learn General Knowledge →