Large Programs

Home / How LLMs Work

How LLMs Work

How Do Large Language Models Learn?

LLMs learn by reading huge piles of text and practising next-word guesses over and over. A step-by-step explanation without jargon.

26 November 2026 · 2 min read

Imagine a student who never goes to class. Instead, they read a giant library and play one game over and over: cover the next word and guess it.

The learning loop: read, guess, check, nudge, repeat.

The learning loop: read, guess, check, nudge, repeat.

Step 1: Collect text

Engineers gather a very large collection of writing. This is called training data.

Step 2: Break it into tokens

The computer cannot read letters like we do. Text is cut into small pieces called tokens and turned into numbers.

Step 3: Play the guessing game

The model sees the start of a sentence and guesses the next token. At first its guesses are poor.

Step 4: Check and adjust

After each guess, the computer checks the real answer. If the guess was bad, it nudges the model's parameters a tiny bit so next time it does better. This happens over and over, a very large number of times.

Step 5: Fine-tuning

After the first stage, the model is often trained further with examples of good answers and with feedback from people. In a 2022 OpenAI paper on a model called InstructGPT, the team first fine-tuned GPT-3 on demonstrations of desired answers written by people. They then collected rankings that people gave to different answers and trained the model further with reinforcement learning from that human feedback. They report that people preferred the answers of a 1.3 billion parameter InstructGPT model to those of the 175 billion parameter GPT-3, and that the new model was more truthful and less toxic. The authors also say it still makes simple mistakes.

An everyday comparison

Think of learning to ride a bike. Nobody hands you a rulebook. You wobble, correct, wobble less, and slowly get better. An LLM learns patterns in a similar way, only with numbers instead of muscles.

What this means

The model is not built to copy a book like a photocopier. It learns patterns, which is why it can write new sentences. But it can sometimes repeat text it was trained on. In a 2021 study of GPT-2, researchers were able to pull out hundreds of word-for-word pieces of its training data, including names, phone numbers and email addresses, and they found that larger models were more open to this. That is one reason people care about what goes into training data. A model can also pick up mistakes and unfair ideas that were in the text it read.

A tiny pretend training run

Suppose the whole library contains only these three sentences:

  1. The cat sat on the mat.
  2. The cat sat on the sofa.
  3. The dog sat on the mat.

After "sat on the", the word "mat" appeared twice and "sofa" once. A very simple model would learn: after "sat on the", say "mat" about two times out of three, "sofa" about one time out of three. Real models are much more complex, and they handle a huge number of different contexts, but the heart of it is the same: learn how likely each next word is, given the words before.

What this tiny example teaches

  • The model repeats patterns it saw. If the library had a mistake, the model would learn the mistake.
  • It can only say what fits the patterns. It has no way to know the real cat unless the text told it.
  • More text gives more patterns, which is why training sets are so large.

Questions to ask

If our little library had never contained the word "sofa", could the model ever say it? What if we added a hundred more sentences about sofas?

Sources