esc
  • WorkflowsPages
  • Case studiesPages
  • Machine Learning FoundationsLearn
  • AI EngineeringLearn
  • AI Guardrails & Red TeamingLearn
  • UI/UXLearn
  • Design SystemsLearn
  • Production System DesignLearn
  • AI papersPages
  • Interview KitPages
  • Book a callContact
  • Download ResumeContact
Let’s talk

I’ll build the agent for it.

What Is a Transformer?

What a transformer is, how self-attention lets it weigh the words around each word, and where it sits under today's language models, explained for your AI interview.

In short

A transformer is a neural network design built on self-attention, which lets each word in a text weigh the other words it is allowed to see while it works out meaning. It was introduced in 2017, and the GPT family of language models is built on it.

10 min readBeginnerVery common · estimateFacts checked 26 November 2026

Say it out loud

Read it once, then say it without looking. Start with the short one; use the long one when they ask you to go deeper.

A transformer is a neural network design from 2017. Its main idea is self-attention: each word in a text weighs the other words it can see to work out its meaning. Older models read word by word, so transformers train faster in parallel. The GPT family of language models is built on it. The trade-offs I always mention are that the model needs extra position information, and that long inputs cost more.

What is a transformer, in plain words?

A transformer is a kind of neural network. A neural network is software that learns patterns from many examples, instead of following rules a programmer wrote by hand.

The design comes from a 2017 paper called "Attention Is All You Need". The authors proposed a model built only from attention, with no step-by-step loops. The Hugging Face Transformers library now covers text, computer vision, audio and video models.

  • “A neural network architecture developed at Google that relies on self-attention mechanisms to transform a sequence of input embeddings into a sequence of output embeddings without relying on convolutions or recurrent neural networks.”

    Google's machine learning glossary

  • “We propose a new simple network architecture, the Transformer, based solely on attention mechanisms, dispensing with recurrence and convolutions entirely.”

    The 2017 paper

Think of a claims handler at an insurer working through a long file. When she reads the word it in one note, she checks back through every earlier note to see what it points to. A transformer does a version of that check for every word in the text. It is how a language model works out that a pronoun points to an invoice and not to a garage.

Key words

Transformer
A neural network design built on self-attention, with no step-by-step loops.
Self-attention
Each word weighs how much the other words it can see matter to its meaning. An encoder sees every word; a decoder sees only the words before it.
Encoder
The part that reads a text and builds a picture of it.
Decoder
The part that writes the output, one token at a time.

How does a transformer work, step by step?

Your text is first cut into tokens, the units the model reads and predicts. Each token then goes through the same steps.

  1. 1

    Turn each token into numbers

    Each token becomes a list of numbers. The model also adds a position signal, because without it the model would not know which word came first.

  2. 2

    Let each word look at the words it can see

    This is self-attention. The model compares each word with the words it can see and mixes in the ones that matter most.

  3. 3

    Give each word its own step

    A small network then refines each word on its own, using what attention found.

  4. 4

    Stack the steps and repeat

    Those steps form one block, and the model stacks many blocks. Each pass gives every word a richer meaning, and the last layer gives the result.

What a transformer does with your text

Input text

a claim note, a contract clause

Repeated many times

Self-attention

each word looks at the words it may see

Per-word step

each word is refined on its own

Result

a label, a summary, the next word

  1. 1Each word is turned into a list of numbers and given its position.
  2. 2Each word gathers hints from the words it is allowed to see.
  3. 3After the last round, the refined words give the result.
Words go in, and each one looks at the words it may see. A small step then refines every word, and the stack repeats this. The last step gives the result, such as a label or the next word.

The 2017 paper describes its design as stacked self-attention and point-wise, fully connected layers for both the encoder and decoder. The point-wise part means one small network applied to each word on its own. Read the design as a stack of repeated blocks, each one a round of attention plus that per-word step.

Why did it replace the older models, and what does it cost?

  • “Experiments on two machine translation tasks show these models to be superior in quality while being more parallelizable and requiring significantly less time to train.”

    The 2017 paper, on translation tests

  • “we must inject some information about the relative or absolute position of the tokens in the sequence”

    The 2017 paper, on word order

Older models had to read word by word. Training could not run in parallel across the words of one text, because each word waited for the one before it. The paper says this sequential nature blocks parallel work.

During training, a transformer handles the whole text in one pass, so training can run in parallel on modern chips. In 2017, Google's team said the design needs less computation to train and fits modern hardware better, speeding up training by up to an order of magnitude, which means up to about ten times faster.

Reading word by word, or in one pass

Older step-by-step models

Word 1

read first

Word 2

waits for word 1

Transformer

All words

in training, read in one pass

Faster training

work runs in parallel

  1. 1Word 2 has to wait, because the old model reads word 1 before word 2.
  2. 2During training, every word is handled in one pass, so the work runs in parallel and finishes sooner.
The older way goes word by word. During training, a transformer reads the whole text together, so training can run in parallel on modern chips.

The costs are real. The model has no built-in sense of order, so position has to be added. Each word is also compared with many others, so a long input costs more work for the computer.

Are all transformers built the same way?

Transformers come in three shapes. The shape depends on the job.

  • Encoder only

    Reads and builds a picture

    Good for text classification, such as sorting claim notes into queues. BERT is built on the encoder part of the Transformer.

  • Decoder only

    Writes one token at a time

    Predicts the next token from the ones before it. Large language models such as the GPT family work this way.

  • Both halves

    Reads, then writes

    The encoder reads the input and the decoder writes the output. The 2017 translation design used both halves.

How does it read a real claims note?

An insurer's claims team uses a model to read each claim note and sort it into a review queue. One note says: "The garage sent the invoice on 3 March, but it was never matched to the claim." The model must decide what it points to, because a wrong guess sends the claim to the wrong team.

  1. 1

    Each word starts with context

    The word it starts as a list of numbers. Self-attention then lets it look at garage, invoice and claim at the same time.

  2. 2

    Weights decide the focus

    The model gives more weight to invoice, because the note is about an invoice that was never matched. The weights are learned from training data, not typed in by hand.

  3. 3

    Repeat through the stack

    Each block refines the reading, so the meaning of it gets sharper before the queue is chosen.

  4. 4

    Test before trusting it

    Run a sample of real notes with known queues. Check the wrong guesses by hand before the model sorts live claims.

Tip

In an interview, tell this story. It shows the job, the failure and the trade-off in one example.

What does the interviewer want to hear?

A strong answer covers

  • A plain definition: a neural network built on self-attention, from the 2017 paper.
  • Self-attention in one line: each word weighs the other words it can see.
  • Why it beat older models: in training, all words go through one pass, so work runs in parallel.
  • Position: the model needs extra information to know word order.
  • Encoder, decoder or both, and which one fits which job.
  • The cost: each word is compared with many others, so long inputs cost more.

Common traps

  • Trap"A transformer is the same as GPT."

    BetterGPT is one family built on transformers. The transformer is the design underneath it.

  • Trap"It reads text one word at a time."

    BetterThat describes the older models. During training, a transformer handles the whole text together.

  • Trap"It understands text like a person."

    BetterIt learns patterns from large amounts of text. Say what it does, then test it on your own data.

Can you spot the wrong line?

Spot the wrong line

A colleague pasted these lines into the team's onboarding doc. Which one is wrong?

Quick check

Why does a transformer need position information?

Can you answer these from memory?

Flash cards · tap a card to flip it

1 / 6

What will they ask next?

  1. Q042Why did transformers replace RNNs and LSTMs?11 min
  2. Q043What is self-attention?11 min
  3. Q044What are queries, keys and values?11 min
  4. Q046What is multi-head attention?10 min
  5. Q047What is positional encoding, and why is it needed?11 min
  6. Q049Encoder-only vs decoder-only vs encoder-decoder?11 min

Learn it in depth

Last updated on 26 November 2026

Building an AI product on transformer models?

I design and build AI products and agents, the interface and the system behind it. Book a short call and tell me what you need.