From Raw Text to Chat Assistant: The Five Stages of Building an LLM
Data and tokenization, next-token pretraining, fine-tuning, preference alignment, then inference. What each stage changes in the model and what it cannot fix.
On this page
People talk about “the model” as one thing. It is the output of a pipeline, and the pipeline explains its behaviour. Why does a base model ramble instead of answering? Why does a chat model refuse some requests? Why can it not learn from your chat? Different stages, different answers.
Stage 1: Data collection and tokenization
Training starts with massive text: books, web pages, code. It is cleaned, filtered and deduplicated, then split into tokens, the units the model actually reads. Quality here caps everything later. A model cannot learn facts or styles that the data never contained, and it inherits the data’s biases and mistakes.
Stage 2: Pretraining
The core objective is simple: given the tokens so far, predict the next one. The architecture is a transformer, whose self-attention lets every token weigh every earlier token, and which trains efficiently in parallel. Trained on trillions of tokens, billions of parameters get adjusted until next-token prediction is good.
To predict well, the model has to pick up grammar, facts, writing styles and patterns of reasoning. That is why one objective yields such broad ability. It is also expensive, and it produces a base model: it continues text brilliantly but does not follow instructions.
Ask a base model “What is the capital of France?” and it may continue with more quiz questions, because that is a likely continuation of a list of questions. Answering is a behaviour, not something next-token prediction teaches by itself.
Stage 3: Supervised fine-tuning
Now the model learns the assistant format from examples: a prompt paired with a good response. Training on thousands to millions of such pairs shifts it from “continue the text” to “respond to the user”.
Fine-tuning every weight is costly, so many teams use parameter-efficient methods. LoRA freezes the original weights and trains small low-rank matrices added to certain layers, cutting memory and cost sharply while adapting behaviour. The same approach lets you specialise a model for a domain without retraining it from scratch.
Stage 4: Preference alignment
Fine-tuning teaches format. Alignment teaches judgement: which of two plausible answers do people prefer? In RLHF, humans rank candidate responses, a reward model learns to predict those rankings, and the language model is optimized to produce answers the reward model scores highly. Newer methods reach similar goals more directly from preference pairs.
This stage is where much of the “helpful, honest, harmless” behaviour comes from, including refusals. It shapes tone and caution, and it can introduce trade-offs such as over-refusal or flattery.
Stage 5: Inference
Serving the model is autoregressive: it reads the prompt, produces a probability distribution over the next token, picks one (sampling settings like temperature control randomness), appends it, and repeats. Weights are frozen. Nothing in your chat updates the model.
Production adds optimisation: quantization to shrink memory, batching to serve many users, caching of already-computed attention state, and safety filtering. Retrieval and tool calls extend what the model can answer by adding text to its context, not by changing it.
Which stage explains which behaviour
| Behaviour | Where it comes from |
|---|---|
| Knows facts, writes fluent text | Pretraining |
| Does not know last week’s news | Pretraining cutoff (data stops) |
| Follows instructions and formats | Supervised fine-tuning |
| Declines some requests, polite tone | Alignment |
| Makes things up confidently | Next-token prediction rewards plausible text, not verified truth |
| Cannot learn from your chat | Inference uses frozen weights |
Do
Diagnose problems by stage: missing knowledge needs retrieval or new data, wrong style needs fine-tuning, wrong risk behaviour needs alignment or system rules.
Don't
Expect prompting alone to teach a model new durable facts. Prompts change the context, not the weights.
Takeaway
An LLM is a stack of decisions: what data it saw, what objective it trained on, how it was taught to respond and what people rewarded. Know the five stages and you can tell which lever fixes which problem, and which problems no lever on the same stage can fix.
Frequently asked questions
What does pretraining actually teach a language model?
To predict the next token given the previous ones, across an enormous corpus. By doing that at scale, the model absorbs grammar, facts, style and some reasoning patterns. A pretrained base model continues text well but is not yet good at following instructions or declining harmful requests.
Why is fine-tuning needed after pretraining?
A base model completes text, it does not obey instructions. Supervised fine-tuning on examples of prompts paired with good responses teaches it the assistant format and task behaviour. Parameter-efficient methods such as LoRA adapt a model by training small added matrices instead of all weights.
What is RLHF and what problem does it solve?
Reinforcement learning from human feedback trains the model using human preference judgments: people rank candidate responses, a reward model learns those preferences, and the language model is optimized against it. It aligns outputs with what people find helpful, honest and safe, which next-token prediction alone does not capture.
Does the model learn anything new during inference?
No. At inference time the weights are frozen. The model generates one token at a time, each conditioned on the prompt and previous tokens, sampling from a probability distribution. Retrieval and tool use can add information to the context, but the model itself is not updated by your conversation.



/* Comments */
Comments are offline right now — we reconnect automatically, nothing is lost.