How large language models actually work
Tokens, embeddings, attention and a lot of next-word guessing. A plain-language tour of what happens between your prompt and the model’s reply, with no math required.
Maya Okafor
3 min read

When you type a question into an AI assistant and an answer appears a moment later, it can feel like the system understood you, thought about it and replied. What is actually happening is both more mechanical and, in its own way, more impressive. Here is the whole journey, from your prompt to its reply, in plain language.
Step one: text becomes tokens
Language models do not read letters or words. They read tokens: chunks of text that might be a whole word, part of a word or a punctuation mark. “Unbelievable” might become “un”, “believ” and “able”. In English, a token averages about four characters, or roughly three quarters of a word.
Each token is mapped to a number, and each number to a long list of values called an embedding. You can think of an embedding as a coordinate in a space with thousands of dimensions, where tokens with related meanings sit near each other. “King” and “queen” are neighbors. “King” and “carburetor” are not.
Step two: attention connects the pieces
The breakthrough behind modern AI is an architecture called the transformer, introduced by Google researchers in 2017. Its key idea is attention: a way for every token to look at the other tokens around it and decide which ones matter for understanding it.
Take the sentence “The trophy didn’t fit in the suitcase because it was too big.” To know what “it” refers to, you need to connect it to “trophy” and to “big”. Attention lets the model make those connections, and it does so across dozens of stacked layers, each building a richer picture than the last. Early layers pick up grammar and word relationships. Later layers capture something closer to meaning, tone and intent.
Step three: predict the next token, again and again
After all that processing, the model produces a single output: a probability for every token in its vocabulary, representing how likely each one is to come next. It picks one, adds it to the text, and runs the whole process again to choose the token after that. A 500-word answer is roughly 650 of these predictions in a row.
A setting called temperature controls how adventurous those choices are. At low temperatures the model almost always picks the most likely token, which makes it predictable. At higher temperatures it samples more freely, which makes it more varied and occasionally more creative, and also more likely to wander.
Everything a language model says, from a poem to a line of code, is built one predicted token at a time.
How a model learns to do this
Training happens in stages.
- Pretraining. The model reads a vast amount of text, from books and websites to code, and repeatedly tries to predict the next token. Each wrong guess nudges billions of internal weights slightly in a better direction. Over trillions of tokens, the model absorbs grammar, facts, reasoning patterns and styles of writing. This stage is enormously expensive, requiring thousands of specialized chips running for weeks or months.
- Fine-tuning. A pretrained model is a powerful autocomplete, not a helpful assistant. It is then trained on examples of good conversations: questions paired with clear, accurate, useful answers.
- Learning from feedback. Finally, people, and increasingly other AI systems, compare pairs of responses and indicate which is better. The model is tuned to produce more of what people prefer, a technique known as reinforcement learning from human feedback. Newer reasoning models also train on problems with checkable answers, like math and code, and are rewarded for getting them right.
What this explains about AI behavior
Once you see a language model as a very sophisticated next-token predictor, a lot of its quirks make sense.
- It sounds confident even when it is wrong, because fluency and accuracy are learned separately.
- It can be inconsistent, because each answer is sampled fresh, so asking twice can produce different results.
- It is sensitive to wording, because your prompt is the context everything else is predicted from.
- It does not remember you between conversations unless a product deliberately stores that information and feeds it back in.
None of this makes the technology less remarkable. Predicting the next word well, it turns out, requires modeling a great deal about the world and the people writing about it. But understanding the mechanism is the best defense against both hype and dismissal, and the best starting point for using these tools well.


