How LLM Training Really Works, From Raw Text to a Chatbot That Answers

Rows of server racks with blue status lights in a data centre

How LLM Training Really Works, From Raw Text to a Chatbot That Answers

Rows of server racks with blue status lights in a data centre

Ask a chatbot a question and the answer arrives in seconds, written in fluent sentences that sound like they came from a person who knows the subject. Nothing in the reply was written by a human in advance. No programmer typed out the grammar rules, the facts, or the jokes. The model learned all of it from training, a process that turns enormous piles of text into billions of tiny numbers that, together, can predict what word should come next. Forbes recently took up the question of how that training actually works, and the answer is less mysterious than it sounds, even if the scale of it is hard to picture.

Training a large language model, or LLM, is not one single step. It is a pipeline with distinct stages, each with a different job. The first stage teaches the model the patterns of language itself. The later stages teach it to follow instructions, to be useful, and to behave the way its makers want it to behave. The whole pipeline runs on specialised hardware and costs sums that only large companies and well-funded labs can afford for the biggest models.

Understanding the pipeline matters even if you never train a model yourself. It explains why chatbots sometimes state false things with total confidence, why they cannot tell you about events after their training ended, and why two models given the same question can give very different answers. Training is where all of that is decided.

What training actually means

At its core, a language model is a huge collection of numbers called parameters, or weights. GPT-3, the model that made this technology famous, had 175 billion of them. Meta’s Llama 3.1 8B, a much smaller open model, has just over 8 billion, counted on its own model card. Nobody chooses these numbers one by one. They start out essentially random, and training adjusts them, over and over, until the model’s guesses improve.

The training loop is the same at every scale. The model is fed a chunk of text and asked to predict the next token, the small unit of text a model works with, which can be a whole word, part of a word, or a single character. The model makes its guess. The guess is compared with the token that actually came next, and the difference is scored as a number called the loss. A lower loss means a better prediction. Then the error is traced backwards through the model’s layers to work out how much each weight contributed to the mistake, a method called backpropagation, and every weight is nudged slightly in the direction that would have made the right answer more likely. An optimiser, almost always a variant called AdamW, controls the size of those nudges.

That loop runs millions of times, over billions of examples. One full pass over a batch of text is one update, and training a frontier model involves a staggering number of them. The teacher, notably, is the text itself. Nobody labels the examples, because the next token in real text is the label. That is why the method is called self-supervised learning, and it is why training can scale: the internet is the answer key.

Stage one: pre-training on trillions of words

Graphics processing units mounted in a server rack with status lights and cabling, the kind of hardware used to train large language models
Training a frontier model takes thousands of graphics processors running in lockstep for weeks or months.

Pre-training is the first and by far the most expensive stage. The model reads a huge corpus of text drawn from the web, digitised books, academic papers, and code repositories, and learns to predict the next token. GPT-3 was trained on roughly 300 billion tokens. Later models went much further: Meta’s Llama 3 was trained on 15 trillion tokens, fifty times as much. The data is cleaned and filtered before training begins, because the quality of the corpus shapes the quality of the model. Duplicates are removed, low-quality pages are dropped, and personal information is filtered out where it can be found.

The architecture that makes all of this possible is the transformer, introduced in a 2017 paper. Its self-attention mechanism lets the model weigh every word in a passage against every other word at once, which is what allows it to learn long-range patterns in text, like the way the start of a paragraph shapes the end of it. Modern LLMs are almost always decoder-only transformers, a design that predicts each token from the ones before it.

Pre-training does not teach the model facts in the way a textbook teaches a student. It teaches the statistics of language: which words follow which, how arguments are structured, how code is written, how a recipe differs from a legal contract. Knowledge emerges as a side effect. A model that has read millions of pages about the solar system can answer questions about planets, not because anyone taught it astronomy, but because the patterns of text about planets became part of its weights.

Pre-training runs on clusters of thousands of graphics processing units, or GPUs, working in lockstep. The work is spread across the cluster with data, tensor, and pipeline parallelism, so that different GPUs handle different slices of the data and different layers of the model. The GPUs must stay in sync, so a single hardware failure can stall the whole job, and training runs are engineered to checkpoint their progress regularly so they can resume after a crash.

Stage two: supervised fine-tuning

A pre-trained model can complete text, but it does not naturally answer questions. Ask it something and it may respond with another question, or continue your sentence as if it were a paragraph in a novel. That is where supervised fine-tuning, usually shortened to SFT, comes in. In this stage the model trains on curated pairs of instructions and good answers, written or reviewed by people, and learns to imitate them.

The datasets used here are far smaller than the pre-training corpus, often tens of thousands of examples rather than trillions of tokens, but they are much higher quality. Each example shows the model what a good response looks like: a clear explanation, a polite refusal, a summary in the requested format. The model is trained on these examples with the same predict-the-next-token objective, but now the text it is predicting is the answer a person would give.

Fine-tuning is also the stage where a general model can be specialised. A company that wants a model fluent in its own products, terminology, and procedures can fine-tune a base model on its own examples. The technique is explained in more detail in our guide to what fine-tuning a language model means in plain terms, including the lighter-weight adapter methods that let small teams adapt a model without retraining all of it. For most organisations, fine-tuning a strong existing model is far cheaper and faster than training one from scratch, and it is the route most of them take.

Stage three: learning from human feedback

Even after fine-tuning, a model can be unhelpful, evasive, or wrong in ways that are hard to fix with examples alone. Writing a perfect answer is difficult, but saying which of two answers is better is easy, and the third stage exploits that. In reinforcement learning from human feedback, or RLHF, the model writes several answers to the same prompt, people rank them, and a second model, the reward model, learns to predict those rankings. The main model is then trained to score well with the reward model.

The method was set out in OpenAI’s InstructGPT paper in 2022, and it is what turned raw text predictors into the helpful assistants people now use every day. The classical way to optimise against the reward model is an algorithm called PPO, although simpler approaches such as direct preference optimisation, which skips the separate reward model, have become popular since. The goal in all cases is the same: push the model towards answers that are helpful, honest, and harmless, as judged by the people doing the ranking.

A newer addition to the pipeline is reasoning training, the shift that defined the 2024 to 2026 period. Here the model learns to think before it answers, producing a long chain of reasoning and then a final answer. The reasoning is rewarded when it leads to correct outcomes, particularly on maths, coding, and logic problems, and the result is a model that can work through harder problems step by step rather than guessing the answer in one shot.

Alignment is not a single fix. It is an ongoing process of testing, and it is imperfect. A model can learn to give answers that sound good to raters without actually being right, a problem called reward hacking, and preferences baked in by one group of raters may not match what another group wants. That is why labs also run evaluations, testing models against benchmarks before release to check what they can and cannot do, a process covered in our explainer on how AI models are evaluated against benchmarks.

The hardware, the cost, and the energy bill

Pre-training a frontier model can cost tens of millions of dollars in compute alone, and the bill keeps growing. The cost comes from three places: the hardware, the electricity, and the people. The hardware is thousands of high-end GPUs, each costing tens of thousands of dollars. The electricity is the power to run them at full tilt for weeks or months, plus the cooling to keep them from overheating. The people are the researchers and engineers who design the run, watch it, and fix it when it breaks.

That cost is also why the economics of AI are so lopsided. A handful of companies can afford to train frontier models from scratch. Everyone else builds on their work, either by using the models through an API, by fine-tuning an open model, or by using techniques that avoid training altogether. Retrieval, where a model is given the relevant documents at question time instead of memorising them during training, is one such shortcut, and it is often enough. Synthetic data, text generated by one model and used to train another, is another way teams stretch their budgets, as explained in our piece on how AI models are trained on synthetic data.

What training does not do

Training ends. Once a model is released, its weights are frozen, and chatting with it does not teach it anything new. That has several consequences that are easy to miss. First, the model has a knowledge cutoff: it knows nothing about events after its training data ends, except what it is given in the conversation itself. Second, it cannot learn from its mistakes in real time. If it gives you a wrong answer and you correct it, the correction helps you, not the model. Third, it can memorise parts of its training data, including text it was supposed to forget, which is one reason labs filter their corpora and why copyrighted and private material in training data has become a legal battleground.

Training also does not guarantee truth. A model trained to predict likely text will sometimes produce confident, fluent statements that are simply wrong, the behaviour known as hallucination. Knowing that the model is a prediction machine, not a database, is the single most useful thing to remember when judging its answers.

The bottom line

LLM training is a pipeline, not a magic trick. Pre-training teaches a model the patterns of language by predicting the next token across trillions of words. Supervised fine-tuning teaches it to follow instructions by imitating good examples. Human feedback and reasoning training shape it into something helpful and careful. The hardware is vast, the cost is enormous, and the result is still a machine that predicts text, not one that understands the world the way a person does. Forbes asked how it works, and the honest answer is that it works by scale: a simple loop, repeated billions of times, until the statistics of language become something that can hold a conversation.

on this page