How Large Language Models Work, Explained Without the Math
ChatGPT, Claude and Gemini all run on large language models. Here is what happens between your question and their answer, in plain English.
Mubarak Ali · · 4 min read
Every popular AI chatbot runs on a large language model, or LLM. The name describes the thing fairly well. It is large, with billions of internal settings. It works with language. And it is a model in the scientific sense: a mathematical stand-in for something real, in this case the patterns in human writing.
It predicts the next piece of text
An LLM's basic job is guessing what comes next. Give it "The capital of France is" and it calculates how likely each possible continuation is. "Paris" scores very high. It picks a continuation, adds it to the text, and repeats the process one piece at a time until the answer is finished.
Those pieces are called tokens. A token is often a short word, sometimes part of a longer word, sometimes a punctuation mark. A word like "unbelievable" might be split into three tokens. For English, 100 tokens works out to roughly 75 words.
That sounds far too simple to produce essays and working code. What makes it work is how good the guessing gets once a model has learned from an enormous amount of text.
Training happens in stages
The first stage is called pretraining. The model is shown trillions of tokens of text: web pages, books, articles, research papers and code. For each passage it guesses the next token, checks the real one, and nudges its internal numbers so it would guess slightly better next time. Repeated trillions of times, this teaches it grammar, facts, writing styles, common reasoning patterns and how code fits together, because all of those help predict the next word.
The internal numbers are called parameters, or weights. Large models have tens or hundreds of billions of them, and nobody sets them by hand. Pretraining a large model takes thousands of specialized chips running for weeks or months, which is why only a handful of companies build the biggest ones.
A freshly pretrained model is good at continuing text but bad at being helpful. Ask it a question and it may reply with three more questions, because on the internet a question is often followed by more questions.
The second stage fixes that. The model is fine-tuned on examples of good conversations, where a question is followed by a useful answer. Then people, and increasingly other AI systems, compare and rate the model's answers, and it is adjusted toward the kind that rate higher. This is usually called reinforcement learning from human feedback, or RLHF, and it is where the model learns to follow instructions, decline some requests and sound like an assistant.
Newer "reasoning" models get another round of training on problems with checkable answers, mostly math and code. They learn to work through intermediate steps before giving a final answer, which is why some chatbots now show a "thinking" stage.
What happens when you send a message
- Your message is combined with the earlier conversation and some instructions from the company that you don't see, and the whole thing is turned into tokens.
- The model processes all of those tokens together. A mechanism called attention lets each token draw information from the others. It is how the model works out what "it" refers to three sentences back.
- The model produces a probability for every possible next token, picks one, adds it to the text and runs again.
- This repeats until the model produces a token that means "stop."
Answers appear on your screen word by word because they really are produced word by word.
A setting called temperature controls how adventurous the picking is. At a low temperature the model almost always takes the most likely token, which gives predictable answers. At a higher temperature it sometimes takes less likely ones, which gives more varied writing that is sometimes more creative and sometimes sloppier. That is why asking the same question twice can get you two different answers.
What it doesn't have
An LLM doesn't look facts up in a database unless the app connects it to a search tool. What it knows is spread loosely across its parameters, so it can state a wrong fact in exactly the same confident tone as a right one. We wrote a separate guide on why AI makes things up.
It has a training cutoff. A model finished in spring knows nothing about the summer unless the app gives it web access.
It doesn't remember you between chats by default either. Each conversation starts fresh, unless the app has a memory feature that saves notes about you and quietly adds them to future conversations.
Why it works as well as it does
Researchers still argue about this. To predict the next sentence of a physics textbook accurately, a model has to capture something that looks a lot like the physics. Whether that counts as understanding, or as a very detailed imitation of it, is an open question.
For everyday use, it helps more to know where LLMs are strong and where they slip. They are good at drafting, summarizing, explaining, translating and writing code. They are weaker at exact facts, recent events, arithmetic done without a calculator tool and anything they have no way to check. Once you know that a chatbot is predicting likely text, both lists make sense: it does best when a likely answer and a correct answer are the same thing.
- LLM
- how AI works
- ChatGPT
- beginners
- machine learning