What Is a Large Language Model (LLM)? A Clear Guide
What is an LLM? A clear guide to large language models: how they learn from text, what they can and can't do, and how they power chatbots and AI agents.
How do LLMs work? A plain explanation of tokens, training, attention and next-token prediction, with no math, plus what it means for using AI tools well.
LLMs work by predicting the next piece of text. They split your prompt into small chunks called tokens, use patterns learned from huge amounts of training text to estimate which token should come next, add it, and repeat until the answer is complete. Everything an LLM does, from chatting to coding, is built on that loop.
That sounds almost too simple, so this guide walks through each step in plain language. No equations, just the ideas you need to understand why these models behave the way they do.
An LLM is a giant pattern-matcher that has read so much text it can continue almost any passage in a way that makes sense.
If you are new to the topic, start with what is an LLM for the basics, then come back here for the inner workings.
Computers do not read words the way you do. Before a model sees your prompt, the text is broken into tokens: short chunks that might be a whole word, part of a word, a space, or a punctuation mark.
For example, a common word like “the” is usually one token, while a rare or long word might be split into several pieces. Code, numbers, and non-English languages often use more tokens per word.
Each token is then turned into a list of numbers that the model can work with. Tokens matter in practice too: they decide how much text fits in the model’s memory and how usage is measured. We cover this in detail in tokens and context windows.
A number for each token is not enough. The model needs to know that “cat” and “kitten” are related, and that “bank” means something different next to “river” than next to “loan.”
So each token is mapped to an embedding: a long list of numbers that places it in a kind of meaning space, where related ideas sit closer together. If you want to go deeper on this idea, see our guide to embeddings.
This is the heart of modern LLMs, which are built on an architecture called the transformer. Its key ingredient is attention.
Attention lets each token look at the other tokens in the text and decide which ones matter for understanding it. Take this sentence:
The trophy did not fit in the suitcase because it was too big.
To figure out what “it” refers to, the model needs to connect “it” with “trophy” and “big.” Attention is the mechanism that lets the model weigh those relationships.
The model does this in many layers, stacked on top of each other. A helpful (but simplified) way to picture it:
In reality, researchers are still studying exactly what each part of a model does. The layered picture is a useful mental model, not a precise map.
After all those layers, the model produces a score for every possible next token in its vocabulary. These scores are turned into probabilities. For the prompt “The capital of France is,” the token “Paris” gets a very high probability and most other tokens get almost none.
The model then picks a token. It does not always pick the single most likely one. Settings like temperature control how adventurous that choice is, which is why the same prompt can produce different answers. Our guide to LLM temperature and other settings explains these controls.
The chosen token is added to the text, and the whole process runs again to pick the next one. And again. A long answer is simply hundreds or thousands of these predictions in a row.
The model stops when it produces a special “end” token, hits a length limit, or reaches a stop condition set by the app. This is also why you see answers appear word by word in many chat apps: they are literally being generated one token at a time.
None of the patterns above were written by hand. They come from training.
During pretraining, the model reads an enormous amount of text. For each passage, it tries to predict the next token, checks how wrong it was, and nudges its internal numbers (called parameters) slightly to do better next time. This happens an astronomical number of times on powerful hardware.
Through this process, the model absorbs grammar, facts, writing styles, coding conventions, and patterns of reasoning, because all of those help it predict text better.
A model that only predicts text is not yet a good assistant. Developers continue training it on example conversations and on feedback about which responses are better. This teaches it to follow instructions, answer clearly, decline harmful requests, and use a consistent assistant style.
| Stage | What the model sees | What it learns |
|---|---|---|
| Pretraining | Huge amounts of general text and code | Language, facts, patterns, reasoning habits |
| Instruction tuning | Example requests with good answers | How to follow instructions and be helpful |
| Feedback training | Ratings or comparisons of answers | Which responses people and policies prefer |
Once you see an LLM as a next-token predictor, a lot of its quirks make sense.
Here is the surprising part: the same next-token machinery can drive actions. If a model is given tools and told it can call them by writing a specific format, then “the next tokens” might be a request like “run the tests” or “open this file.” The app runs that action and feeds the result back as more text.
Loop that over and over and you have an AI agent. The model plans, acts, reads the result, and continues. That is how coding agents edit real projects and fix failing tests. Read what is an AI agent to see how that loop works in practice.
An LLM breaks your text into tokens, uses patterns it learned from huge amounts of training text to predict the most fitting next token, adds it, and repeats. Long answers are just many of these predictions in a row.
That is an open debate. LLMs clearly build useful internal representations of meaning that let them reason, translate, and write code. But they work very differently from human minds, and they can produce fluent text that is wrong, so it is best not to assume humanlike understanding.
A transformer is the neural network design behind most modern LLMs. Its key feature is attention, which lets each part of the text consider every other part when building meaning, so the model can track context across long passages.
Most apps let the model sample from several likely next tokens instead of always picking the top one. That randomness makes writing more natural and varied, but it also means two runs of the same prompt can differ. Lowering the temperature makes answers more consistent.
What is an LLM? A clear guide to large language models: how they learn from text, what they can and can't do, and how they power chatbots and AI agents.
What is an AI hallucination? Learn why language models invent facts, how to spot it, and practical ways to reduce hallucinations in chats and AI agents.
Open source LLM or closed model? Learn what open-weight really means, why licenses vary, and the trade-offs in privacy, cost, quality and control.