AI and Technology

How Large Language Models Work

A plain explanation of how text-generating language models learn patterns from huge amounts of writing, then produce text one piece at a time.

On this page
  1. The core idea: predicting what comes next
  2. Step one: turning text into tokens
  3. Step two: representing meaning as numbers
  4. Step three: the network and attention
  5. How training works
  6. Generating a reply
  7. What these systems are good at
  8. Limits worth knowing
  9. Using them sensibly

The core idea: predicting what comes next

A large language model is a program trained to predict text. Given some words, it estimates which piece of text is likely to come next. Repeat that step, adding each new piece to the input, and the model can write a sentence, a paragraph or a long answer.

That description sounds too simple to produce coherent essays, but scale changes things. To predict text well across a huge range of subjects, a model has to absorb a great deal about grammar, facts, style and the way ideas are usually connected. Whether that amounts to “understanding” is debated; what is clear is that it captures many useful patterns.

Step one: turning text into tokens

Computers work with numbers, so text is first split into pieces called tokens. A token may be a whole common word, part of a longer word, or a punctuation mark. Each token is assigned a number from a fixed vocabulary. Because of this, models handle text slightly differently from how people see it, which helps explain some odd failures, such as trouble counting letters in a word.

Step two: representing meaning as numbers

Each token is then mapped to a long list of numbers called an embedding. During training, tokens that appear in similar contexts end up with similar embeddings. The word “doctor” ends up numerically closer to “nurse” than to “banana,” not because anyone defined it that way but because of how the words are used in text.

Step three: the network and attention

The embeddings are passed through a neural network made of many layers. Most modern models use an architecture called the transformer, introduced in 2017. Its key mechanism, called attention, lets the model weigh how relevant each earlier token is when interpreting the current one. In the sentence “The trophy did not fit in the suitcase because it was too big,” attention helps link “it” with the right noun.

Stacking many layers lets the model build up from simple relationships to subtler ones. The model’s learned settings, called parameters, number in the billions for the largest systems. These parameters are numbers adjusted during training, and they are where the model’s “knowledge” is stored in a diffuse, hard-to-inspect form.

How training works

Pretraining. The model is shown enormous amounts of text and repeatedly asked to predict the next token. When its guess is poor, an algorithm nudges the parameters so the right answer becomes slightly more likely. After many repetitions across vast amounts of text, the model becomes good at continuing almost any passage. This stage requires large amounts of computing power and energy.

Fine-tuning. A pretrained model is a text-continuer, not necessarily a helpful assistant. Further training on examples of good question-and-answer behavior, and often on human feedback about which responses people prefer, shapes it to follow instructions, stay on topic and avoid some kinds of harmful output. Companies differ in how they do this, and the details are not always public.

Generating a reply

When you type a prompt, the model converts it to tokens and computes a probability for every possible next token. It then picks one, usually with some controlled randomness so responses are not identical each time, appends it, and repeats. A setting often called temperature adjusts how adventurous that choice is: low values give more predictable text, higher values more varied text.

The model does not look up an answer in a database. It generates text from learned patterns, though some systems are connected to search or document tools to supply additional information.

What these systems are good at

  • Drafting, summarizing and rewriting text
  • Translating between languages
  • Explaining concepts at different levels
  • Writing and explaining code
  • Answering questions on well-covered topics

Many of these abilities fall under generative AI, the broader family of tools that produce new content.

Limits worth knowing

Confident mistakes. Because the model generates plausible text rather than verifying facts, it can state false things fluently. This behavior is discussed under AI hallucinations.

Knowledge cutoffs. Training data stops at some point, so a model may lack recent information unless it is given tools or documents.

Inherited bias. Models learn from human writing, which contains stereotypes and gaps, and these can show up in outputs.

Sensitivity to wording. Rephrasing a question can change the answer.

No guaranteed reasoning. Models can solve many logic and math problems, but they can also make elementary errors, particularly on long multi-step problems.

Privacy and copyright questions. Training on large collections of text raises unresolved legal and ethical debates about data sources.

Using them sensibly

Treat output as a draft to be checked, particularly for health, legal, financial or factual claims. Give clear context in your prompt. Avoid pasting sensitive personal or confidential information into tools unless you understand how that data is handled. And remember that fluent writing is not evidence of accuracy, a point that applies when judging any source.

The complete guide to ai and technology

A Guide to Understanding Artificial Intelligence
Read the guide

Keep exploring

Guides from other topics

All topics →