How LLMs are trained: from raw text to a useful assistant

Picked by

· written by AI, fact-checked ·

The short version

Matthew Berman’s video, “Anthropic Researcher explains how to train LLMs,” prompted this article. This is a separately sourced explainer, not a transcript-based account of that interview. It draws on published work from Anthropic, OpenAI, Google DeepMind, Meta and DeepSeek.

A chat assistant can write code, explain a contract and answer follow-up questions in the same window. The models covered here start with a narrower training task: predicting what comes next.

How does that task lead to a useful assistant? The answer involves several kinds of learning, each with a different goal. It also explains why a polished answer can still be wrong.

First, prepare the data

Training does not begin by pouring an unfiltered copy of the internet into a model. The Llama 3 report describes a large data pipeline with filters, duplicate removal and checks for quality.

Those choices affect what the model gets to practise. Repeated website menus are not the same as worked maths problems. Code, general prose and different languages also need different treatment.

Meta built separate pipelines for code and maths. It also tested different mixtures of data, using smaller models before starting larger runs. The report attributes much of Llama 3‘s progress to data quality, variety and training scale.

Next, a tokenizer splits text into units called tokens. A token may represent a word, part of a word or another piece of text. These units are mapped to numbers the model can process.

Tokens are not the same as words. Llama 3’s team changed its tokenizer to represent text more efficiently and better support languages beyond English. That let the model process more text within a given token budget.

The important point is that data preparation is part of the training method. A larger dataset is not automatically a better one. What it contains, repeats and leaves out all matter.

What happens in one training step?

In next-token training, the model receives a sequence and predicts the token that follows each position. The actual text supplies the targets, so people do not need to label every prediction.

For a simple example, imagine the text “Please close the door.” At one position, the model sees the earlier tokens and predicts what follows “the”. The source text supplies “door” as the target.

The prediction is not just a single word. The model assigns probabilities across its token vocabulary. A loss function measures how poorly its predictions match the training targets.

Training then changes the model’s parameters, also called weights. These are the numbers that control its maths. An optimiser uses information about the loss to adjust them.

The basic loop is:

  • Read a batch of training text and predict the next tokens.
  • Measure the prediction loss against the actual tokens.
  • Work backwards through the computation to find gradients: signals about how weights affect that loss.
  • Use an optimiser to update the weights, then repeat with more data.

This backward calculation is called backpropagation. It does not write a neat fact into a chosen slot. It helps adjust many linked values so the model does better on its training task.

The process also runs across many token positions at once. It is not a person typing a question and waiting for one answer before starting the next lesson.

Why predicting text can teach more than spelling

Text contains facts, arguments, code and descriptions of how things work. Predicting it well can require learning patterns beyond which words tend to sit together.

The Transformer architecture helps the model use context. Its attention mechanism lets it combine information from different positions in a sequence. Other layers process that information as it passes through the network.

For next-token prediction, the model must not look ahead at the answer. The original Transformer paper describes a mask that prevents its decoder from attending to later positions.

Attention is a computation over the available text, not a built-in web search. A model can only use an external search tool if a larger system provides one.

After pre-training, a model can have broad skills without being a reliable assistant. OpenAI’s InstructGPT paper makes this distinction explicit: predicting text and following a user’s intent are different goals.

A base model may continue a passage when the user wanted a direct answer. It may also produce false or harmful content that fits the text pattern. More pre-training alone does not define the behaviour a chat product needs.

Why a bigger model is not always better

Training teams have a limited budget of computing power. They must decide how much to spend on model size and how much on the amount of training data processed.

DeepMind’s Chinchilla research tested this trade-off. Its 70-billion-parameter model outperformed the 280-billion-parameter Gopher model after training on more tokens, using the same computing budget.

That result was not proof that small models always win. It showed that model size alone was a poor guide to the best use of a fixed training budget.

The study sought the lowest pre-training loss for a fixed training budget. It did not seek the lowest total cost of running a deployed model. Deployment adds another concern: the cost of answering users. A smaller model trained for longer can be useful when it will serve many requests.

That is why “how many parameters?” is only one question. The training data, amount of training and intended use belong in the answer too.

How does the model learn to act like an assistant?

One common step is supervised fine-tuning, often shortened to SFT. Trainers provide examples of prompts paired with good responses. The model learns to produce those responses rather than just continue arbitrary text.

SFT can still use next-token prediction. Llama 3 trained on the desired response tokens, while excluding prompt tokens from the loss. Many of its example responses were model-generated, rather than written by people.

Examples can teach the shape of an answer: respond to the question, follow the requested format and avoid an unwanted kind of reply. This is still training, because the model’s weights change.

OpenAI’s InstructGPT work then added human comparisons. People ranked model responses, and those rankings trained a reward model. It learned the preferences of the chosen raters, under their instructions. That is narrower than learning what everyone wants.

The language model was further trained to obtain higher reward scores. This approach is called reinforcement learning from human feedback, or RLHF. Human feedback supplied the training signal; people did not score every later chat response.

The results showed why this stage mattered. Evaluators preferred answers from the 1.3-billion-parameter InstructGPT model to those from the much larger 175-billion-parameter GPT-3.

The comparison concerned human preferences on the prompts studied. It did not show that the smaller model was better at every task. The authors also reported remaining problems, including false statements and harmful answers.

Not all preference training needs a reinforcement learning loop. Llama 3 also used direct preference optimisation, or DPO. This trains the model using preferred and rejected responses. Meta still used a reward model elsewhere, to help select training examples.

Post-training changes which responses get rewarded. It does not turn every fluent response into verified knowledge.

What does Anthropic's Constitutional AI add?

Anthropic explored a way to use AI feedback as part of this process. Its Constitutional AI research used a written set of principles to guide model critiques and comparisons.

In one stage, the model generated a response, critiqued it against a principle and revised it. The revised answers then became examples for supervised training.

In another stage, AI-generated comparisons supplied rankings for a reward model. Reinforcement learning then used that reward signal to shape responses. Anthropic called this reinforcement learning from AI feedback, or RLAIF.

This reduced the need for human labels of harmful outputs in that research setup. It did not remove human choices. People still chose the principles and designed the process.

Nor was the constitution a promise that the model would always obey. The paper described a method and test results, not a proof of harmlessness.

These are published examples of training methods. They should not be read as a complete recipe for every current Claude model, or every other commercial assistant.

How reasoning training changes the reward

Some tasks have answers that are easier to check than open-ended writing. A maths result can be compared with a target. Code can be run against tests. Those checks can supply rewards.

DeepSeek-R1-Zero explored this route by applying reinforcement learning to an already pre-trained base model. It skipped supervised fine-tuning before that stage, not pre-training itself.

The researchers reported that the model developed longer solution attempts, checks and alternative approaches. Its rewards included answer correctness and required formatting. This was not simply a prompt telling an unchanged model to try harder.

The limits matter. R1-Zero had poor readability and mixed languages. DeepSeek’s later R1 system used a broader training process, including supervised examples, to address those problems.

This shows why there is no single fixed sequence of stages. Teams can combine examples and rewards in different ways. The choice depends on the skills and behaviour they want to improve.

It also exposes a hard problem: the reward is only a proxy for the goal. DeepSeek avoided learned reward models for its reasoning tasks because they could be tricked into giving high scores.

Passing the chosen check is useful evidence. It is not proof that an answer will be right in every setting. Open-ended advice remains harder to score than a task with a clear target.

Training, prompting and retrieval are different tools

A prompt supplies information for the model to use during a response. Fine-tuning changes the model’s weights through a training process. These are different ways to affect an answer.

Generating a response is called inference. A normal forward pass uses the existing weights; it does not perform the training update described earlier.

Retrieval adds another option. A system finds relevant documents and makes their contents available to the generator. The original retrieval-augmented generation research combined a language model with an external document index.

That paper also trained parts of its system. So it would be wrong to say that retrieval systems never involve training. The useful distinction is between looking up information and changing model weights.

Consider a support assistant that needs today’s refund policy. It can retrieve the current policy for its answer, instead of relying only on what a model learned earlier. That is a design example, not a guarantee of accuracy.

The system still needs to retrieve the right document and use it correctly. Retrieval research found gains on the tasks studied, not a way to eliminate every factual error.

For a practical project, separate the questions. Does the assistant need new information, a different response pattern, or better problem-solving? Retrieval, fine-tuning and reward-based training address different parts of that problem.

How can anyone tell whether training worked?

A lower training loss shows progress on the training objective. It is not a complete test of a useful assistant. The papers above also assess held-out tasks, human preferences and safety behaviour.

Testing needs separation from training. If benchmark answers leak into training data, the score may partly reflect prior exposure. Meta’s Llama 3 report describes contamination checks for this reason. These checks can miss leaks or flag harmless overlap. They cannot prove that a benchmark is clean.

Improvements can also come with losses elsewhere. InstructGPT reported worse scores on some public datasets after reinforcement learning. Mixing in pre-training updates reduced those losses.

Comparisons also need clear conditions. Human preference is not the same as factual accuracy. A benchmark with one sampled answer is not the same as one that combines several attempts.

For a deployed assistant, a useful evaluation should therefore ask:

  • Can it complete the actual task, rather than just produce a convincing answer?
  • Does it use the right source when facts can change?
  • What happens when information is missing or the request is unclear?
  • Do improvements on the target task cause failures elsewhere?
  • Does the quality justify the response time and cost?

These are practical evaluation questions, not claims that any single training method has solved them.

The clearest way to understand an LLM is to keep its stages separate. Pre-training builds broad abilities. Post-training shapes responses. Prompts and retrieved documents supply context when it runs. Each helps, and each leaves something that still needs testing.

Sources

Matthew Berman's video (topic source; no transcript available)

Anthropic: Constitutional AI — Harmlessness from AI Feedback

OpenAI: Training language models to follow instructions with human feedback

DeepMind: Training Compute-Optimal Large Language Models

Attention Is All You Need: the original Transformer paper

DeepSeek-R1: Incentivizing Reasoning Capability in LLMs via Reinforcement Learning

Retrieval-Augmented Generation for Knowledge-Intensive NLP Tasks

Meta: The Llama 3 Herd of Models