Level 1 Use AI · Getting Started
Large Language Models, Explained Simply
What ChatGPT, Claude and Gemini actually are. A model trained to predict the next piece of text, at enormous scale, then taught to act as a helpful assistant. Why that makes them fluent, useful and sometimes confidently wrong.
- Level
- ●●●●● Beginner
- Reading
- 11 min
- To learn it well
- 45 minutes to read
- Builds on
- 2 concepts →
- Quiz
- 5 questions ↓
Read first
How Machines LearnThe full path from zero — 2 concepts before this one
- What Is AI?
- How Machines Learn
- Large Language Models, Explained Simply
Read them roughly in this order. See it on the concept map →
Why it matters
Since ChatGPT appeared in November 2022, hundreds of millions of people have started talking to computers in ordinary language. These systems — ChatGPT from OpenAI, Claude from Anthropic, Gemini from Google, Llama from Meta and many more — are all built on the same kind of program: a large language model, or LLM.
LLMs are strange tools. They can explain quantum physics to a ten-year-old, translate a legal contract, write working software and draft a wedding speech. They can also invent a book that doesn't exist, fail at counting the letters in a word, and agree with whatever you suggest. Both behaviours come from the same mechanism. Once you understand that mechanism you will use these tools much better: you'll know when to trust them, when to check them, and how to ask.
This chapter uses no maths. The technical details are in Language Modeling and Next-Token Prediction, The Transformer and GPT and Decoder-Only Models.
The intuition: autocomplete, scaled up enormously
Your phone keyboard suggests the next word as you type. After "see you", it offers "soon", "tomorrow", "later". It learned this from lots of text: after "see you", those words are common.
An LLM is the same idea taken to an extreme. It is a program trained to do one thing: given some text, predict what comes next. This is called next-token prediction. But where your keyboard looks at the last word or two, an LLM looks at everything written so far — thousands of words or more. And where the keyboard learned from your messages, an LLM learned from a large fraction of all the text humans have published online: websites, books, encyclopedias, scientific papers, forums and code.
Here is the surprising part. To predict the next word well across all that text, a model has to pick up a great deal about the world. To continue "The capital of France is…", it helps to know geography. To continue a maths proof, it helps to follow the logic. To continue a Python program, it helps to understand Python. Nobody programmed these skills in. They were learned because they made the next-word guesses better.
To write a whole answer, the model predicts one piece, adds it to the text, then predicts the next piece given everything so far, and so on, hundreds of times. That is why chatbot answers appear word by word: you are watching the loop run.
Key idea An LLM is a next-word predictor trained on a huge amount of text, then taught to behave like a helpful assistant. Its knowledge, its fluency and its mistakes all come from that.
How it works
Tokens: the pieces of text
LLMs don't actually work with words but with tokens: common words, chunks of words, punctuation and spaces. "Unbelievable" might be split into "un", "believ" and "able". A rough rule for English is that one token is about three-quarters of a word, so 1,000 tokens is about 750 words. Each token gets an ID number, and the model works with those numbers. See Tokenization.
Tokens explain some odd failures. Asked how many times the letter "r" appears in "strawberry", earlier chatbots often said two. The model never sees individual letters, only token chunks such as "str", "aw" and "berry", so counting letters is surprisingly hard for it.
The model: billions of knobs
The predictor itself is a neural network of a type called the Transformer, invented at Google in 2017. As in How Machines Learn, it is a recipe with adjustable knobs (parameters). GPT-3 (2020) had 175 billion of them. Modern models have hundreds of billions or more, but most companies no longer say exactly how many.
The Transformer's key trick is attention: when predicting the next token, every part of the text can "look at" every other part to decide what matters. In "The trophy didn't fit in the suitcase because it was too big", attention helps the model link "it" to "trophy". See Attention.
The model's output is not a single word but a probability for every token in its vocabulary (typically between about 50,000 and a few hundred thousand tokens): "Paris" 92%, "a" 2%, "the" 1%, and so on. The program then chooses one. Choosing is called sampling. Always taking the top choice gives dull, repetitive text, so systems usually pick at random in proportion to the probabilities, with a setting called temperature controlling how adventurous they are. That's why asking the same question twice can give different answers. See Decoding: Temperature, Top-k and Top-p.
Training stage 1: pretraining
In pretraining, the model reads an enormous amount of text and practises next-token prediction on all of it. Each time it guesses wrong, its knobs are nudged to make the right token a bit more likely, using gradient descent. This is the same loop as in How Machines Learn, repeated trillions of times.
The numbers are hard to picture. Meta's Llama 3 models (2024) were pretrained on over 15 trillion tokens. That is roughly 11 trillion words. A person reading eight hours a day, every day for 80 years, would get through a few billion words, so this is thousands of lifetimes of non-stop reading. Pretraining a frontier model runs on tens of thousands of specialised chips (GPUs) for months, and the largest runs are reported to cost hundreds of millions of dollars.
Because no human needs to label anything (the text itself provides the right answers), this is self-supervised learning. See Pretraining Large Language Models.
The result is a base model. It is a brilliant mimic of internet text, but not yet an assistant. Ask a base model "What is the capital of France?" and it might continue with "What is the capital of Germany? What is the capital of Italy?", because that is what lists of quiz questions online look like.
Training stage 2: post-training
Turning a base model into a helpful assistant is called post-training. It is much cheaper than pretraining but makes all the difference to how the model behaves.
- Instruction tuning. The model is trained further on tens of thousands of example conversations, many written by hired experts: a user asks something, an ideal assistant replies. It learns the format and manner of being an assistant. See Instruction Tuning and Chat Models.
- Learning from feedback. People (and increasingly other AI models, guided by written principles) compare pairs of answers and say which is better: more helpful, more honest, less harmful. The model is then trained to produce more answers like the preferred ones. This is reinforcement learning from human feedback, or RLHF. It was the key ingredient that made ChatGPT feel so different from earlier models.
- Reinforcement learning on checkable tasks. Since 2024, labs have also trained models with reinforcement learning on problems with verifiable answers, such as maths and coding. This taught them to "think" at length, writing out and checking their reasoning before answering. These are the reasoning models, such as OpenAI's o-series and DeepSeek-R1. See Reasoning Models and Test-Time Compute.
The finished product is what you talk to. When you chat, the app wraps your message in hidden instructions (a "system prompt") and sends the whole conversation to the model, which continues it with the assistant's reply.
Memory and the context window
An LLM has no memory of its own between conversations. Its knobs are fixed once training ends. Within a conversation, everything it "remembers" is simply the text it is given, which can be up to a limit called the context window. As of late 2026, typical limits run from about 128,000 to over a million tokens, enough for several long books. When a chat app seems to remember you across sessions, it is because the app saves notes and pastes them back into the context.
The model's built-in knowledge is frozen at the time its training data was collected, its knowledge cutoff. Ask about later events and it either doesn't know or guesses, unless the app gives it a web search tool and pastes the results into the context. See Retrieval-Augmented Generation and Tool Use and Function Calling.
Why they hallucinate
The model was trained to produce plausible continuations, not true ones. Most of the time, the plausible continuation is also the true one, because most training text about the capital of France says Paris. But when the model doesn't know — an obscure fact, a precise number, a citation — the most plausible-looking continuation is still something fluent and confident. It produces a realistic-sounding paper title, with realistic authors, that doesn't exist. This is a hallucination (Hallucinations).
Post-training reduces this by rewarding models for saying "I'm not sure", and web search helps by grounding answers in real sources. But as of late 2026, no LLM is free of hallucinations. Treat their output the way you would treat a very well-read colleague who speaks confidently from memory: often right, worth checking when it matters.
Watch out LLMs are most dangerous where they sound most authoritative: specific facts, numbers, quotations, references, legal and medical details. Always verify those against a primary source.
What they're good and bad at
| Usually good at | Often weak at |
|---|---|
| Explaining, summarising and rewriting text | Precise facts it rarely saw; recent events without search |
| Translation and changing tone or level | Exact counting, character-level tasks, long arithmetic without a calculator tool |
| Writing and fixing code | Knowing when it's wrong; admitting ignorance |
| Brainstorming, outlining, first drafts | Consistency across very long tasks |
| Answering questions about a document you provide | Resisting a leading question (it tends to agree with you) |
Many weaknesses can be patched by giving the model tools: a calculator, a code interpreter, a search engine. This is the idea behind AI Agents.
In code (optional)
Here is the core idea of a language model in miniature: learn from text which word tends to follow which, then generate by repeatedly sampling a likely next word. Real LLMs look at the whole context, not just the last word, and use a neural network instead of a table of counts, but the generate-one-piece-at-a-time loop is the same.
import random
from collections import Counter, defaultdict
text = """the cat sat on the mat . the dog sat on the rug .
the cat chased the dog . the dog chased the ball .
the cat slept on the mat ."""
# "Training": count which word follows which
follows = defaultdict(Counter)
words = text.split()
for current, nxt in zip(words, words[1:]):
follows[current][nxt] += 1
print("after 'the':", follows["the"].most_common())
# "Generating": repeatedly sample a likely next word
random.seed(4)
word, sentence = "the", ["the"]
while word != "." and len(sentence) < 12:
options = follows[word]
word = random.choices(list(options), weights=options.values())[0]
sentence.append(word)
print(" ".join(sentence))
# after 'the': [('cat', 3), ('dog', 3), ('mat', 2), ('rug', 1), ('ball', 1)]
# the cat sat on the cat chased the rug .
The generated sentence never appeared in the training text. It is new, locally fluent, and nonsense overall, because this toy only looks one word back. Looking back over thousands of words, with billions of knobs, is what turns this into ChatGPT.
Common misconceptions
- "It looks things up in a database." Not unless the app gives it a search tool. By default, everything comes from patterns stored in its parameters. It cannot tell you where it learned something.
- "It's just copying the internet." Models occasionally reproduce memorised passages, but mostly they generate new text that has never existed before.
- "It learns from my conversation." Not in the moment: the knobs don't change while you chat. (Companies may, depending on your settings, use conversations to train future models. Check the privacy settings.)
- "It's conscious / it's just autocomplete." Both extremes mislead. It is a next-token predictor, and predicting well at this scale required learning a remarkable amount. Judge it by what it reliably does.
Where it leads
- To use LLMs well with no code: AI Fluency: Working Well with AI and Prompt Engineering.
- To build with them: Using LLM APIs, Retrieval-Augmented Generation, Tool Use and Function Calling, AI Agents.
- To understand them properly: Tokenization → Language Modeling and Next-Token Prediction → Attention → The Transformer → GPT and Decoder-Only Models → Pretraining Large Language Models → Instruction Tuning and Chat Models → RLHF and Preference Optimization. Or build one yourself in Build a GPT from Scratch.
- To think about risks: Hallucinations, AI Alignment, Prompt Injection and LLM Security.
A bit of history
Language models are old. In 1948 Claude Shannon generated English-like text by predicting each next letter or word from statistics, much like the toy above. In 2003 Yoshua Bengio and colleagues built the first neural language model. In 2017 the The Transformer arrived, and in 2018 OpenAI's GPT showed that pretraining a Transformer on lots of text, then adapting it, worked on many tasks. GPT-2 (2019) and GPT-3 (2020) scaled this up dramatically. In 2022 OpenAI's InstructGPT paper described the instruction-tuning and RLHF recipe, and ChatGPT, released on 30 November 2022, put it in front of the public. A Short History of AI has the wider story.
Try it
- Ask a chatbot the same open question three times in new chats. How different are the answers? That is sampling at work.
- Paste a page of text into a free tokenizer viewer (such as Tiktokenizer, linked from the Tokenization chapter) and see how it splits. Which words become several tokens?
- Ask a chatbot about something that happened last week, with web search turned off and then on. Compare.
Learn more
Hand-picked courses, books, videos and tutorials for going deeper. See all resources →
Intro to Large Language Models
A one-hour talk for a general audience on what LLMs are, how they are trained and where they are going.
Large language models, explained with a minimum of math and jargon
A long, patient article on word vectors, attention and next-word prediction for readers with no technical background.
Generative AI exists because of the transformer
A beautifully animated scroll-through explainer of tokens, embeddings and attention in an LLM.
Deep Dive into LLMs like ChatGPT
A 3.5-hour walk through the full stack of how chat models are built: pretraining, tokenization, post-training, RL and reasoning.
Neural Networks (video series)
Gorgeous animated explanations of neural nets, gradient descent, backprop, Transformers and attention.
Transformer Explainer
An interactive visualisation of GPT-2 running in your browser. Type text and watch every step.
Facts checked as of 30 November 2026. Fast-moving details (products, prices, laws) change often. · Source: content/entries/start/llms-explained.md