What is a transformer model? Explained with a highlighter
A transformer is the neural network design behind chatbots: it reads a whole passage at once and weighs which words matter for each word. Explained with an editor marking a sentence with a highlighter.
- Author
Umair Mateen- Published
- Reading time
- 5 min
- Category
- AI
In one sentence: A transformer is the type of neural network behind today's chatbots and large language models; it reads a whole passage at once and, for every word, uses a step called attention to weigh which other words matter most for its meaning.
The everyday picture
Picture an editor at a desk with a printed sentence and a highlighter: "I arrived at the bank after crossing the river." On its own, "bank" could mean a place for money or the edge of a river.
So the editor stops at "bank" and highlights the words that help explain it. "River" gets a thick mark. "The" gets almost none. Now "bank" is clear. The editor does this for every word, not just the tricky ones.
Now imagine a whole office of editors. Each one takes a different word, and they all work at the same moment. Each editor also has several highlighter colours, one for each kind of link they look for. That office is a transformer.
Words go in with their positions, the highlighter scores which other words matter, several colours look for different links, and repeated read-throughs end in a guess at the next word.
How it works, step by step
- Tokens (the words on the page) come first. The text is cut into small pieces, and each piece becomes a list of numbers called an embedding. A positional encoding (a small number written beside each word showing where it sits) is added, because the editors read all words at once and would otherwise lose the order. IBM's guide describes both steps.
- Self-attention (the highlighter) compares each word with every other word in the passage and gives each one a score: how much it helps explain this word. Google's 2017 post used the same "bank" and "river" example. The scores are scaled so they add up to one, like sharing out a fixed amount of ink.
- The word's meaning is updated (the editor writes a note in the margin). Information from the highlighted words is blended in, heaviest marks first. "Bank" now carries a hint of "river".
- Multi-head attention (the different colours) runs several highlighters side by side. Each learns to look for a different kind of link, such as which word "it" points to, or which words describe which.
- Layers (several read-throughs) repeat the process. Each pass starts from the notes of the last one, so later passes can spot deeper links. In a chatbot, the final notes are used to pick the next word, which is added to the page, and the whole thing runs again.
Try it · Put it in order
Put the editor's highlighting steps in order
Tap the steps in the order they happen.
Where the picture stops
- A human editor understands the sentence. A transformer only works with numbers. Its "highlighting" is arithmetic, and the habits behind it were learned from huge amounts of example text, not from knowing what words mean.
- Nobody tells it which words to mark. What each highlighter colour looks for is learned during training, and people often can't say exactly what one colour has learned.
- Real highlighting is cheap. For a model, every word is compared with every other word, so doubling the length of a passage roughly quadruples the comparisons. That is one reason long inputs cost more and take longer.
Why it matters for your business
- It is the engine under most AI tools you use. IBM names GPT, Claude and Llama as transformer-based language models. When you judge an AI product, you are mostly judging a transformer plus the data and safeguards around it.
- Speed came from reading everything at once. Older models read one word at a time. The original paper says the transformer is easier to run in parallel and needs much less time to train. That made today's large models practical, and it is why they run on chips built for parallel work.
- Length costs money. Because every word is weighed against every other word, very long documents and chats use more computing. Sending only what the task needs keeps bills and wait times down.
- Good at context, not at facts. Attention helps the model read meaning from surrounding words. It does not check whether an answer is true, so important outputs still need a human check.
An example
Imagine a 15-person law office that uses an AI assistant to sort incoming letters. One letter says: "The tenant told the landlord she would pay next week." Older keyword tools might file it under the landlord. The transformer's attention links "she" with the right person from the rest of the letter and files it under the tenant's late payment. A paralegal still checks each label before anything is sent, because the model can link words wrongly.
Frequently asked questions
Are ChatGPT and Claude transformers?
Yes. The models behind them are large language models built on the transformer design. They generate text one token at a time, each time predicting the next piece from everything before it.
What is attention in AI?
Attention is the step where a model scores how much each part of the input matters to each other part, then blends information using those scores. It lets a word's meaning depend on its context.
Where did the transformer come from?
It was introduced by researchers at Google in the 2017 paper "Attention Is All You Need". It was first tested on translating between languages.
Do transformers only work with text?
No. Vision transformers cut an image into small patches and treat each patch like a word. The same design is also used for speech and for models that mix images and text.
Related explainers
The DevDrift builds AI features with human checks and audit trails: see how.
Sources
Could you explain this to a colleague now?
Mark it and posts that mention it will show a tick. Saved in this browser only.