The shape it is shown
Fresh shapes it gets right

Deep dive

AI Training and Alignment

The main guide shows what happens when you use a model. This page shows how the model got there: how raw text becomes a base model, how a base model becomes an assistant, and how labs try to make that assistant honest, useful, and safe. Two of the steps you will not just read about — you will run them, on a real model, in this tab.

01The whole lifecycle

The Core Pipeline

Every modern AI assistant goes through roughly the same six stages. Watch one model travel down the line and see what it is called at each point, or pick a stage to read about it.

Pick a stage
Key idea"The model" is not made in one step. Raw text makes a base model; curated examples make it an assistant; feedback shapes its judgement; tests decide whether it ships; a product wrapper decides how it behaves for you.
The stages and their order are how the large labs describe their own process. In practice they overlap and repeat — a model can go round the fine-tune, feedback, and eval loop many times before release.
02What it reads

Training Data

A model can only learn patterns that exist in what it reads. Large models are trained on trillions of tokens: web pages, books, code, reference works, licensed datasets, and increasingly images, audio, and video. The quality of that mixture matters as much as its size — a model trained on sloppy text learns sloppy habits.

Always running
Cleaning and filteringRaw web data is full of duplicates, spam, boilerplate, and junk. Labs deduplicate aggressively and filter for quality, because repeated or low-value text wastes training and skews behaviour.
Mixture choicesHow much code versus prose versus maths versus other languages is a deliberate recipe. More code in the mix is part of why modern models are decent programmers.
Hard problemsCopyright disputes, privacy of scraped personal data, bias baked into source text, and uneven language coverage are all live, unresolved issues.
Synthetic dataLabs now also train on data generated or curated by other models — useful for filling gaps, risky if errors compound.

The data behind the model on this page

The tiny model you are about to train has a training set too. It is small enough to count exactly.

Sentences0
Tokens to predict0
Vocabulary0
Weights to tune0

A frontier model sees roughly a billion times more tokens and has roughly ten million times more weights. The procedure in the next chapter is the same.

Key ideaTraining data is not a database the model looks things up in. After training the data is gone; what remains is a web of statistical patterns squeezed into the weights. That is why a model can "know" something approximately but misremember the details.
The funnel animation uses made-up proportions to show the idea; real rejection rates vary by source and are mostly unpublished. The four counts underneath are exact and read from this page's own training set.
03One game, played at scale

Pretraining

Pretraining is one deceptively simple game: guess the next token. The model reads some text with the ending hidden, predicts what comes next, and is scored on how wrong it was — a number called the loss. An algorithm called backpropagation works out how to adjust every weight to be slightly less wrong next time. Repeat that enough and the model is forced to absorb grammar, facts, and patterns, because all of them help it guess better.

Real model

One training example, in slow motion

A real sentence from the training set. The model sees the tokens on the left and has to bet on the hidden one.

The model's odds for the next token
Token being predicted1
Surprise for this token?
Average so far (the loss)–

Now train it yourself

This is the same model the main guide runs on. Wipe its weights to random numbers and the slow-motion example above turns to noise. Then press Train and watch the loss fall, the sentences it writes turn from babble into grammar, and its word map sort itself into groups — all from the single instruction "be less surprised".

Why it worksPredicting the next token well in arbitrary text quietly requires understanding the text. You cannot reliably finish "the capital of France is" without knowing the answer.
ScaleLarge training runs use trillions of tokens, hundreds of billions of weights or more, and months of compute. Bigger runs have historically produced predictably better predictions — the "scaling laws".
The catchThe result is a base model: a brilliant text continuer, not an assistant. Ask it a question and it may continue with three more questions, because that is what the pattern looked like online.
Key ideaNobody tells the model what a cat is or how grammar works. It is only ever told how surprised it was. Everything it appears to know is whatever turned out to reduce that surprise.
Everything in this chapter is real. The odds, the surprise values, and the training are computed in your browser by a complete two-layer transformer with hand-written backpropagation. What is not real is the scale: this run takes seconds; a production run takes months on thousands of chips.
04Keep training, on purpose

Fine-Tuning

Fine-tuning takes a trained model and keeps training it — on a much smaller, hand-picked dataset showing the behaviour you actually want. Same game, same maths, new examples. It is how a base model becomes an assistant, and how a general model becomes a specialist.

Real model

Teach the model a word it has never seen

The model's vocabulary contains a token for dragon, but no training sentence ever used it. Look at the first two lines in the panel below: it still writes something grammatical, because it knows how sentences go, but it is guessing — it has learned nothing about what dragons do. Here are ten new sentences:

    Watch two things. First, the dragon lines: after a few dozen steps the model writes about dragons using everything it already knew about sitting, eating, and pronouns. Second, the "the cat sat on the" line: fine-tuning only rewards the new sentences, so nothing protects what was learned before. If that line changes for the worse, you have just watched catastrophic forgetting — the reason real fine-tuning mixes in old data and uses small steps. It may hold up, or it may drift; both happen.

    The fine-tune that makes an assistant

    For chat models the hand-picked examples are conversations: a user asks, the assistant answers helpfully. This is supervised fine-tuning, and it teaches the model that a question deserves an answer rather than a continuation.

    Base model continues the text

    Tuned assistant answers

    Instruction tuningA broad diet of many task types teaches the general skill of following instructions, not just answering trivia.
    Domain adaptationThe same technique can specialise a model for code, medicine, law, or support — at some cost to general flexibility.
    Same engine underneathFine-tuning does not add knowledge so much as reshape behaviour. The base model already "knew" how to answer; tuning made answering the default.
    Key ideaThere is no separate mechanism for "teaching a model to behave". It is the same next-token training, pointed at a small set of examples chosen to change what the model does by default.
    The dragon fine-tune is real: it updates the live weights in this tab, so every demo on this page uses them until you press Restore or reload. The base-versus-assistant replies are written examples of the typical gap, not live model output — this page's model is far too small to hold a conversation.
    05Learning from preferences

    RLHF and Alignment

    Fine-tuning shows the model what good answers look like. But "good" is fuzzy — helpful, honest, harmless, appropriately confident — and nobody can write enough perfect examples to pin it down. So labs use reinforcement learning from human feedback (RLHF): show people two candidate answers, ask which is better, train a reward model to predict those preferences, then nudge the assistant toward answers the reward model scores highly. You are about to generate that signal yourself.

    Scripted illustration

    2 · The assistant, before and after

    Before feedback, assume the assistant is as likely to do each of these as not. Finish the three rounds, then apply.

    The chainHuman rankings → reward model → reinforcement learning. No single person writes the assistant's personality; it emerges from millions of comparisons.
    VariantsRLAIF replaces some human raters with AI raters; Constitutional AI has the model critique itself against written principles; DPO trains directly on preference pairs and skips the separate reward model.
    The balance problemReward caution too much and the model becomes uselessly over-cautious; reward confidence too much and it becomes a smooth-talking guesser. Alignment is steering between those ditches, and it is never finished.
    Key ideaAlignment shapes behaviour; it does not install guarantees. A well-aligned model is more likely to be honest and to refuse harm — it is not incapable of error. And it becomes whatever the raters actually reward.
    This chapter is a scripted illustration. The questions, answers, trait labels, and the arithmetic that moves the bars are written by hand to show the shape of the method; no model is being trained here. Real RLHF uses a neural reward model and millions of comparisons.
    06Does it ship?

    Evals and Red Teaming

    Before a new model ships it gets examined: benchmark suites for reasoning, coding, and maths; human evaluations of usefulness and style; safety testing for jailbreaks, dangerous capabilities, and privacy leaks; and red teams whose whole job is to make the model misbehave. The most important rule is the least glamorous: a new model must not quietly get worse at things the old one did well.

    Scripted illustration
    Benchmarks saturateOnce models near 100% on a test, it stops measuring anything. Eval suites are constantly rebuilt, and scores on old benchmarks mean less every year.
    ContaminationIf a benchmark's questions leaked into training data, the score is memorisation, not skill. Labs work to detect and exclude this.
    Red teamingAdversarial testers probe for jailbreaks, harmful instructions, persuasion, and misuse before — and after — release.
    Key ideaBetter on average is not good enough. Users feel a regression immediately and take improvements for granted, so one thing getting worse can block a release that improved five others.
    The eval names and scores are invented to show how a release gate works. Real gates run thousands of checks, plus human review and red-team sign-off, and their thresholds are specific to each lab.
    07What you actually talk to

    The Deployment Layer

    The trained model is not what you talk to. Products wrap it in a system prompt that sets role and rules, tool access, retrieval, memory, moderation filters, and rate limits. That wrapper is why the same underlying model can feel like a different product in different apps.

    Scripted illustration
    What comes back

    Key ideaSame weights, same question, two different answers. A great deal of what feels like a model's "personality" is the product wrapped around it.
    The system prompts and replies are written examples. The layers themselves — system prompt, tool permissions, moderation, monitoring — are standard in deployed assistants, though each product arranges them differently.
    08Facts without retraining

    RAG and Embeddings

    Retraining a model to teach it your documents is slow and expensive. Retrieval-augmented generation (RAG) skips that: store your documents, search them when a question arrives, and place the best matches into the model's context so it can answer from evidence.

    Pick a question
    search wordspick a question above
    The document library
    What gets placed in the model's context
    empty — nothing retrieved yet
    Pick a question. The retriever will score every document, pull the best two into the context, and the answer will be written only from what was retrieved.

    Real retrievers search by meaning, not by matching words

    The demo above counts shared words, which is easy to follow but brittle. Production systems convert every text into an embedding — a list of numbers where similar meanings land near each other — so "watering schedule" can find "irrigation notes" without sharing a word. Here are real embeddings from this page's model: pick a word and see which tokens sit closest to it.

    Why it beats retraining for factsDocuments update instantly, answers can cite sources, and nothing is baked irreversibly into weights.
    Why it is not magicRetrieval can miss the right document or pull an irrelevant one — then the model confidently answers from the wrong evidence.
    When fine-tuning still winsStyle, format, and skills are behaviours, not facts. You cannot retrieve your way into being better at code review.
    Key ideaRAG does not make the model know more. It puts the right page in front of it at the right moment — and the answer is only as good as what was fetched.
    The retriever is real but deliberately simple: it scores each document by how many of the listed search words it contains and takes the top two. The grounded answers are written by hand. The nearest-neighbour list is real, read from the live weights; train or fine-tune the model above and it will change.
    09What nobody fully knows yet

    Limits and Open Questions

    An honest explainer ends with what is still unsettled.

    HallucinationReduced, not solved. Fluent text without enough grounding remains the signature failure.
    InterpretabilityYoung. Researchers can map some internal features and circuits, but nobody can fully explain a large model's reasoning weight by weight.
    BiasBias from training data persists despite filtering and tuning.
    Emergence and saturationWhich abilities appear at which scale is still debated, and benchmarks keep getting outgrown.
    What alignment can guaranteeVersus merely make likely: the central open question of the field.

    See the trained model at work

    The main guide follows one prompt through this same model: tokens, embeddings, attention, layers, and the dice roll at the end. (It loads the shipped weights; training done here stays on this page.)

    Open How AI Works