# How Neural Networks Work: Transformers Explained Simply

> A beginner's guide to neural networks and the transformer architecture: neurons, layers, training, attention and how ChatGPT writes, with interactive demos.

By Amal V S, Backend & AI Systems Architect · Published 2026-11-11 · Updated 2026-11-11
Source: https://amal.vs.binarybit.in/blog/6af3fb0b02386f0d9ee372e6

> **What is a neural network?** A neural network is a computer program that learns patterns from examples instead of following hand-written rules. It is made of many simple units called neurons, arranged in layers. Each neuron multiplies its inputs by learned weights, adds them up and passes the result on. During training, the network adjusts those weights millions of times until its answers become accurate.

Every time you unlock your phone with your face, get a translation, or chat with ChatGPT, a neural network is doing the work. They sound mysterious, but the core idea is surprisingly simple. By the end of this guide you will understand how a single neuron works, how a network learns, and how the **transformer**, the architecture behind today's AI chatbots, reads and writes text.

No maths degree needed. There are three small interactive demos along the way, so you can see each idea in action.

## Neural networks in 60 seconds

| Idea | In plain words |
| --- | --- |
| Neuron | A tiny calculator: multiply inputs by weights, add them up, squash the result |
| Weight | How much one input matters. Learning means finding good weights |
| Layer | A group of neurons. Stacking layers lets the network learn complex patterns |
| Training | Show examples, measure the error, nudge the weights to reduce it, repeat |
| Deep learning | Neural networks with many layers |
| Transformer | A neural network design that uses "attention" to understand how words relate. It powers ChatGPT, Claude and Gemini |

## Part 1: What is a neural network?

Think about how you learned to recognise a cat. Nobody gave you a rulebook ("pointed ears + whiskers + fur = cat"). You simply saw many cats, and your brain learned the pattern. Neural networks learn the same way: **from examples, not rules**.

The name comes from the brain's neurons, but the resemblance is loose. An artificial neural network is really just a lot of simple arithmetic, organised cleverly and repeated at enormous scale.

## How a single neuron works

Imagine one neuron deciding whether you should go to the beach. It looks at three yes/no questions, each with a **weight** that says how much that question matters:

![Diagram of one artificial neuron: three inputs (sunny, weekend, friends going) multiplied by weights, summed with a bias, and squashed into an output of 0.73 meaning go to the beach](https://blog.api.binarybit.in/api/media/f/images/2026/11/57280d81-2953-4435-8799-ee5628a1e40a.png)

- **Multiply** each input by its weight. Sunny (1) × 0.6, weekend (0) × 0.3, friends going (1) × 0.9.
- **Add them up** and subtract a **bias** (how hard it is to say yes): 0.6 + 0 + 0.9 − 0.5 = 1.0.
- **Squash** the total with an **activation function**, here the sigmoid, which turns any number into a value between 0 and 1. 1.0 becomes 0.73.

0.73 is above 0.5, so the answer is "go to the beach", with about 73% confidence. Try it yourself:

That is genuinely all a neuron does. The magic is not in one neuron, but in connecting millions or billions of them and letting the computer find the weights.

### Why the activation function matters

Without the "squash" step, stacking neurons would only ever produce straight-line relationships, no matter how many layers you add. The activation function adds a bend, which lets the network learn curved, complicated patterns. Modern networks often use a simple one called **ReLU**: keep positive numbers, turn negatives into zero.

## Layers: how neurons team up

![A neural network with an input layer, two hidden layers and an output layer, connected by weighted lines, ending in outputs cat 92 percent and dog 8 percent](https://blog.api.binarybit.in/api/media/f/images/2026/11/e68588f0-f4fd-40f1-b59b-f702868c9f80.png)

Neurons are arranged in **layers**, and each layer passes its results to the next:

- **Input layer:** the raw data. For a photo, that is the brightness of every pixel.
- **Hidden layers:** where patterns are found. Early layers spot simple things like edges; later layers combine them into shapes, then into ears, eyes and faces.
- **Output layer:** the answer, often as probabilities, such as "cat 92%, dog 8%".

A network with many hidden layers is called a **deep** neural network, which is where the term **deep learning** comes from.

## How neural networks learn

A new network starts with random weights, so its answers are random too. Training fixes that through a loop that repeats millions of times:

- **Guess:** show the network an example, such as a photo of a cat, and let it predict.
- **Measure the error:** compare the prediction with the right answer. This error score is called the **loss**.
- **Assign blame:** work backwards through the layers to find how much each weight contributed to the error. This step is called **backpropagation**.
- **Adjust:** nudge every weight slightly in the direction that reduces the error. This is **gradient descent**.

> **Gradient descent, explained like a hike:** imagine you are on a foggy mountain and want to reach the valley. You cannot see far, so you feel which way the ground slopes and take a small step downhill. Repeat enough times and you reach the bottom. The "mountain" is the error, and every step is a small change to the weights.

After seeing enough examples, the weights settle into values that give good answers, even for examples the network has never seen. That is what "learning" means for a machine. The set of learned weights is what people mean by a model's **parameters**. Large language models have billions of them.

### Types of neural networks

| Type | Best at | Example |
| --- | --- | --- |
| Feed-forward (basic) | Simple predictions from numbers | Predicting house prices |
| Convolutional (CNN) | Images | Face unlock, medical scans |
| Recurrent (RNN, LSTM) | Sequences, one step at a time | Older translation and speech systems |
| **Transformer** | Language, and now images, audio and code | ChatGPT, Claude, Gemini, Llama |

Recurrent networks read a sentence one word at a time, like reading through a keyhole. They were slow to train and tended to forget the start of long sentences. The transformer solved both problems.

## Part 2: The transformer architecture explained

In 2017, a team at Google published a paper called [Attention Is All You Need](https://arxiv.org/abs/1706.03762) (Vaswani et al.). It introduced the **transformer**, and it changed AI. The "T" in ChatGPT stands for transformer: **Generative Pre-trained Transformer**.

The big idea: instead of reading words one by one, a transformer looks at **all the words at once** and works out how each word relates to every other word. Here is the journey your text takes:

![Transformer architecture step by step: tokenize, embed with position, repeated layers of self-attention and feed-forward, predict next token, repeat](https://blog.api.binarybit.in/api/media/f/images/2026/11/98eafca3-7ad3-4806-be32-619cfddf4b3d.png)

### Step 1: Tokenization, cutting text into pieces

First, text is split into **tokens**: whole words, parts of words or punctuation. "Transformers are amazing" might become [Transform] [ers] [are] [amazing]. A token is roughly three-quarters of an English word on average, which is why AI pricing and limits are counted in tokens.

### Step 2: Embeddings, turning words into numbers

Computers only understand numbers, so each token becomes a long list of numbers called an **embedding**, often hundreds or thousands of numbers long. These numbers act like coordinates in a "meaning space": words with similar meanings, like _king_ and _queen_, or _cat_ and _kitten_, end up close together.

Because the transformer sees all words at once, it also adds **positional information** to each embedding, so it knows that "dog bites man" is different from "man bites dog".

### Step 3: Self-attention, the key idea

This is the heart of the transformer. For every word, **self-attention** asks: _which other words in this sentence help me understand this one?_

Take the sentence "The animal didn't cross the street because it was too tired." What does "it" mean? You know instantly it is the animal. Change "tired" to "wide", and "it" becomes the street. Attention lets the model make that same judgement:

How does it decide? Each word creates three things, often explained with a library analogy:

- **Query (Q):** what this word is looking for. "it" is looking for the thing it refers to.
- **Key (K):** what each word offers, like a label on a library book.
- **Value (V):** the actual information each word passes on if it is chosen.

The model compares each query with every key to get a relevance score, turns the scores into percentages, and blends the values accordingly. In the paper's notation:

```
Attention(Q, K, V) = softmax(Q·Kᵀ / √d) · V
```

You do not need the formula to understand the idea: **score every pair of words, turn the scores into percentages, and mix information based on those percentages**.

**Multi-head attention** runs several attention calculations side by side. One "head" might track which noun a pronoun refers to, another grammar, another tone. Their results are combined.

### Step 4: Feed-forward network

After attention mixes information between words, each word's numbers pass through a small neural network of the kind from Part 1. This is where much of the model's stored knowledge lives.

### Step 5: Stack the layers

Attention plus feed-forward makes one **transformer layer** (also called a block). Models stack many of them: the original transformer used 6, and GPT-3 used 96. Two tricks keep deep stacks stable: **residual connections**, which let information skip ahead, and **layer normalisation**, which keeps the numbers in a sensible range.

### Step 6: Predict the next token, then repeat

At the end, the model turns the final numbers into a probability for every token in its vocabulary. It picks one, adds it to the text and runs the whole process again. That is why chatbots appear to type one word at a time. They really are writing **one token at a time**.

This is also why the same question can get different answers: there is a controlled amount of randomness in the choice, set by the **temperature**.

### Encoder, decoder, or both?

| Design | What it does | Famous examples |
| --- | --- | --- |
| Encoder-only | Reads and understands text | BERT (search, classification) |
| Decoder-only | Generates text, one token at a time | GPT, Claude, Llama, Gemini |
| Encoder-decoder | Reads one sequence, writes another | The original 2017 transformer, T5 (translation) |

## Why transformers took over AI

- **Parallel training:** all words are processed at once, so training uses modern GPUs efficiently and can learn from enormous amounts of text.
- **Long-range understanding:** any word can directly attend to any other word, however far apart they are.
- **They scale:** bigger transformers trained on more data have kept getting better, which led to today's large language models.
- **They work beyond text:** the same design now handles images, audio, video, code and even protein structures.

## Limits of neural networks and transformers

- **They predict, they don't know.** A language model produces likely-sounding text, which can include confident mistakes, often called hallucinations.
- **Attention gets expensive.** Comparing every word with every other word means the cost grows quickly as the text gets longer.
- **They need huge data and compute** to train, which is why only a few organisations train the largest models.
- **They are hard to explain.** Billions of weights make it difficult to say exactly why a model gave a particular answer.
- **They learn from their data,** including its biases. That is why models get extra safety training (see [what happens when it is removed](https://amal.vs.binarybit.in/blog/6af155f57a6bd947ceecfc09)).

Researchers are actively working on these limits: [mixture-of-experts models](https://amal.vs.binarybit.in/blog/6ae56ac47027b216982aa5bc) activate only part of the network per token, [next-concept models](https://amal.vs.binarybit.in/blog/6ae426797027b216982aa27c) generate text coarse-to-fine instead of token by token, and [decision models like Jev](https://amal.vs.binarybit.in/blog/6aeabc6d7027b216982aacdb) answer structured questions without writing text at all.

## Glossary: key terms in one place

| Term | Meaning |
| --- | --- |
| Neuron | A unit that multiplies inputs by weights, adds a bias and applies an activation function |
| Weight / parameter | A number the network learns; models have millions to trillions of them |
| Bias | An extra learned number that shifts a neuron's threshold |
| Activation function | The "squash" step (sigmoid, ReLU) that lets networks learn complex patterns |
| Loss | A score for how wrong the network's prediction was |
| Backpropagation | Working backwards to find how much each weight contributed to the error |
| Gradient descent | Adjusting weights in small steps to reduce the loss |
| Token | A piece of text, roughly ¾ of an English word on average |
| Embedding | A list of numbers representing a token's meaning |
| Self-attention | How each token weighs every other token to understand context |
| Context window | How many tokens a model can consider at once |
| Temperature | How random the next-token choice is |

## Summary

A neural network is layers of simple neurons whose weights are learned from examples. Training repeats one loop: guess, measure the error, assign blame, adjust. A transformer is a neural network built around **attention**: it turns text into tokens and numbers, lets every word look at every other word, and predicts the next token, over and over. That one idea, introduced in 2017, is behind almost every AI tool you use today.

## FAQ

### What is a neural network in simple terms?

A program made of many simple connected units, called neurons, that learns patterns from examples by adjusting the importance (weights) of its connections.

### How does a neural network learn?

It makes a prediction, measures how wrong it was (the loss), works out how each weight contributed to the error (backpropagation), and adjusts the weights slightly to reduce it (gradient descent). This repeats millions of times.

### What is the transformer architecture?

A neural network design from the 2017 paper "Attention Is All You Need". It processes all words at once and uses self-attention to work out how words relate to each other. It powers models like ChatGPT, Claude and Gemini.

### What is self-attention?

A mechanism where each word scores how relevant every other word is to it, then combines their information based on those scores. It is how a model knows what "it" refers to in a sentence.

### What does GPT stand for?

Generative Pre-trained Transformer: a transformer that generates text and was pre-trained on large amounts of text before being fine-tuned.

### What is the difference between AI, machine learning, deep learning and neural networks?

AI is the broad goal of making machines smart. Machine learning is AI that learns from data. Neural networks are one kind of machine learning model. Deep learning means neural networks with many layers.

### Do neural networks work like the human brain?

Only loosely. They were inspired by brain neurons, but artificial neurons are simple arithmetic, and the way they learn is very different from biological brains.

---

Reference: Vaswani et al., [Attention Is All You Need](https://arxiv.org/abs/1706.03762) (2017). Interactive examples use illustrative values to explain the concepts.

(Interactive charts and tools in the original page are not included in this text version.)
