Free guide · All levels · 10 min read
How AI actually works
No maths or coding needed. Start with one simple idea, build on it step by step, and by the end you will understand how a chatbot like ChatGPT writes its answers.
Created
Each part uses the one before it. If you already know some AI, still read Part 1. It only takes two minutes, and everything after it is built on that one example.
Part 1 · For everyone
The big idea: learning from examples
A normal computer program follows rules that a person wrote down. A calculator, a banking app or a spreadsheet does exactly what it was told, step by step.
That works well until you meet a problem nobody can write rules for. Try writing rules to recognise a cat in a photo. “Has pointy ears.” So does a fox. “Has whiskers.” So does a seal. The cat might be curled up with its ears hidden. You would never finish the list.
AI turns the problem around. Instead of writing the rules, we show the computer thousands of examples with the right answers, and it works out the rules by itself.
A tiny AI you can train yourself
Let's make this concrete with the simplest problem I can think of. You have five pizzas, and you know the size and price of each one. You want a rule that guesses the price of any pizza.
Our “AI” is just a straight line. It has two knobs: how steep the line is (how much each extra centimetre costs), and how high it sits. Every combination of knob settings is a different guess. The red lines show how far off the guess is for each pizza. That distance is the error.
Try it: move the two knobs and make the red lines as short as you can. Then press Let the computer learn.
Once the knobs are set, the line can price a pizza it has never seen: just read off any size. That is what people mean when they say an AI model makes a prediction.
Part 2 · Going deeper
Inside a neural network
A straight line is fine for pizza prices. But recognising a cat or translating a sentence needs a much more flexible guessing machine. The one that powers almost all modern AI is called a neural network. Here it is in three steps.
Step 1: everything becomes numbers
Our pizza model took a number (size) and gave back a number (price). A computer can only work with numbers, so everything else has to be turned into numbers first. A photo, for example, is a grid of tiny squares called pixels, and each pixel is just a number for how bright it is.
Step 2: a neuron is the pizza line, plus a bend
The building block of a neural network is the artificial neuron. You already know how it works. Imagine our pizza model taking more than one input: size, number of toppings, and whether it is delivered. Each input is multiplied by its own knob, and the results are added up. These knobs are called weights.
Then comes one extra step, a small bend: if the total is below zero, the neuron outputs zero. That's all. The bend sounds trivial, but it matters a lot. Stacking straight lines only ever gives you another straight line. Adding bends lets the network build curves, corners, and, with enough of them, almost any shape it needs.
Step 3: stack many neurons in layers
A neural network is many of these neurons arranged in layers. The outputs of one layer become the inputs of the next. Every line in the picture below is one knob.
Our pizza line had 2 knobs. A small network that reads handwritten digits has about 100,000. The largest AI models today have hundreds of billions. That's the only real difference in kind: far more knobs, so far more patterns they can capture.
How a network learns: walking downhill in the fog
Training a neural network is exactly the loop you saw in Figure 2. Show it an example, let it guess, measure the error, nudge every knob a little. Repeat millions of times.
The tricky part is knowing which way to nudge each knob. Picture yourself on a hillside in thick fog, trying to reach the bottom of the valley. You can't see the valley, but you can feel which way the ground slopes under your feet. So you take a small step downhill, and feel again. Height is the error, and your position is the knob settings.
This method is called gradient descent (the gradient is the slope). Working out the slope for every knob in a deep network uses a clever bookkeeping trick called backpropagation: it starts from the error at the output and works backwards through the layers, figuring out how much each knob contributed to the mistake.
Part 3 · How chatbots write
How chatbots like ChatGPT write
Chatbots such as ChatGPT, Claude and Gemini are built on large language models (LLMs). “Large” means many knobs. “Language model” means a model of text. Under the hood, it's a neural network like the one in Part 2, with one twist in how its layers talk to each other.
Words become numbers too
Text is first split into small pieces called tokens: whole words, or parts of longer words. Then, just like the pixels, each token is turned into a list of numbers. You can think of these numbers as a position on a map. This position is called an embedding.
Nobody draws this map by hand. The positions are knobs too, set during training. And because the model is trying to predict text, words used in similar ways end up close together.
The only job: guess the next word
Here is the part that surprises most people. A language model is trained on one simple task: given some text, guess the next token. It gives each possible next word a probability.
The pizza came out of the ___
To write a whole answer, the chatbot picks a word from this list, adds it to the text, and guesses again. Word by word, sentence by sentence. Training is our familiar loop: take real text from books, websites and code, hide the next word, let the model guess, and measure the error as how surprised was it by the real word? Then nudge the knobs downhill. Do this over trillions of words.
To get good at guessing the next word in any text, the model is pushed to pick up grammar, facts, styles of writing and even patterns of reasoning, because all of those help it guess better.
Context changes meaning: attention
Back to “bat”. Its meaning depends on the words around it, so the model needs a way for words to influence each other. This is what attention does. In each layer, every word looks at the other words in the text, decides which ones matter most to it, and updates its own numbers using them. In effect, it moves to a better spot on the map.
Try it: switch sentences and watch what “bat” pays attention to, and where it moves on the map.
A modern model stacks dozens of these attention layers, each followed by ordinary neuron layers like the ones in Part 2. This design is called the Transformer, introduced by Google researchers in 2017 in a paper titled Attention Is All You Need. It is the “T” in ChatGPT.
From word guesser to helpful assistant
A model that only predicts the next word would happily continue your question with more questions. Turning it into an assistant takes two more rounds of training, using the same knob-nudging loop:
- 1Pre-training. Predict the next word across a huge amount of text. This is where almost all the knowledge comes from.
- 2Fine-tuning. Keep training on example conversations written by people, so it learns the shape of a helpful answer.
- 3Learning from feedback. People (and other models) rate different answers, and the knobs are nudged towards the preferred ones.
Why chatbots sometimes make things up
You now know enough to understand this one yourself. The model was trained to produce text that is likely, not text that is checked. Most of the time, likely and true are the same. When the model has seen little about a topic, the most likely-sounding answer can be confidently wrong. This is called a hallucination. So use chatbots like a smart colleague, not an encyclopedia: check important facts, and give them the source material when accuracy matters.
The whole guide in one picture
Pizza line2 knobs, learns a price from examples.
Neural networkThousands of knobs, learns to recognise images.
Language modelBillions of knobs, learns to predict the next word.
Same loop every time: guess → measure the error → nudge the knobs → repeat.
Words you now know
- Model
- A guessing machine with knobs.
- Weights (parameters)
- The knobs. What the model has learned.
- Training
- Adjusting the knobs to make errors smaller, using examples.
- Neural network
- Layers of neurons; each neuron is weighted inputs, added up, then a bend.
- Gradient descent
- Taking small steps downhill on the error.
- Backpropagation
- Working backwards from the error to find how each knob should change.
- Token
- A word or piece of a word.
- Embedding
- A token's position on the word map, as a list of numbers.
- Attention
- How each word looks at the other words to update its meaning.
- Transformer
- The design behind modern language models: attention layers plus neuron layers.
- Hallucination
- A confident answer that is likely-sounding but wrong.