How AI works, explained
A chat AI works by predicting what text comes next. It learned patterns from a very large amount of writing, and it builds each answer one small piece at a time, choosing pieces that are likely to follow everything written so far.
The tiny AI in the lesson above does this in the simplest possible way: it counts which word followed which in 30 sentences. Systems such as ChatGPT, Claude and Gemini are built on the same idea, carried out at a vastly larger scale and with far more subtlety.
How an AI learns
Before anyone can chat with an AI, it goes through training. Nobody types in facts for it to look up. Instead the AI is shown text and asked, again and again, to guess what comes next.
Start with a huge amount of text. Books, articles, websites, computer code.
Hide what comes next and ask for a guess.
Compare the guess with the real text. Early on, the guesses are close to random.
Adjust slightly. The AI is made of billions of numbers, called parameters. Each one is nudged a tiny amount so that “mat” becomes a little more likely next time.
Repeat an enormous number of times. To keep guessing well across so much text, the AI ends up picking up grammar, facts, writing styles and ways of reasoning through a problem.
Training happens before you ever use the AI, and it is expensive: it runs for a long time on large numbers of specialised computer chips. The finished result is called a model. Chat assistants then get a further round of training, with feedback from people, that teaches the model to behave like a helpful assistant.
What happens when you ask something
Once trained, the model does one thing. It takes the text so far, which includes your question, and works out how likely every possible next piece is. One piece is chosen and added, and the model runs again on the slightly longer text.
That loop is the whole answer being written. It is why replies appear on screen a bit at a time, and why the lesson had you add one word after another.
The pieces are called tokens, and they are often parts of words. You can watch your own text split into tokens in another lesson.
The tiny AI and the real thing
The tiny AI is a fair picture of the idea and a poor picture of the scale. Three differences matter most.
It only looks at the last word. That is why it wrote “the cat sat on the park”. A real model takes the whole conversation into account, often many thousands of words, which lets it stay on topic and follow instructions.
Its learning is a table of counts. That table has nothing to say about a word it has never seen, and no idea that “sofa” and “bed” are similar things. A real model stores what it learned as billions of numbers, which lets it treat similar words in similar ways and cope with text it has never met.
It read 30 sentences. A real model learns from more text than a person could read in many lifetimes.
What this explains
Knowing that an AI predicts likely text makes its odd behaviour easier to anticipate.
- It can be confidently wrong. In the last step of the lesson, the tiny AI repeated your sentence without checking it. A real AI can do the same with a mistake it picked up, or with a gap it fills in.
- The same question can get different answers. A little randomness is used when choosing each piece, as you saw when the tiny AI rolled the dice.
- It may not know recent events. Training stops at a cut-off date. Anything after that has to be supplied, for example through web search.
- The model itself does not remember you. Each answer is produced from the text in front of it. Many chat apps add a memory feature that saves notes about you and puts them back into later chats. See what a context window is for how that limit works.
Common questions
Is AI just autocomplete?
The basic move is the same: predict what comes next. The difference is scale and reach. A phone keyboard looks at the last few words. A modern AI system takes the whole conversation into account and learned from an enormous amount of text, which is enough for it to explain, translate, summarise and write code.
Does AI understand what it says?
Researchers disagree, and it depends on what you mean by understand. An AI learned from data alone, with no life in the world behind its words. Yet it captures patterns of meaning well enough to be useful on problems it has never seen. The practical advice is the same either way: treat it as a very capable predictor and check anything important.
Where does AI get its information?
Mostly from the text it was trained on, which stops at a cut-off date. Many apps also let the AI search the web or read files you attach, so it can take in fresh information before answering.
Why does AI make things up?
It is built to produce text that is likely, not text that has been checked. When it has not seen the answer, the most likely-sounding continuation can still be wrong, and it is written in the same confident style as everything else. This is often called a hallucination.
Does AI learn from my chats?
The AI model itself does not change while you chat, so telling it something does not teach it for everyone else. Two things can still carry over. Many chat apps have a memory feature that saves details about you and adds them to your later chats. And a company may use conversations to train future versions, depending on its policies and your settings, so check the privacy settings of the app you use.
What is the difference between AI, machine learning and an LLM?
AI is the broad name for computer systems that do tasks we associate with human thinking. Machine learning is the main way AI is built today: the system learns patterns from examples instead of following hand-written rules. An LLM, or large language model, is one kind of machine learning system, trained on text, and it is what powers chat AIs.
Last updated