AI learns by making predictions on example data, measuring how wrong they are with a number called loss, and adjusting its internal parameters a little to reduce that loss. It repeats this many times, and the process is called training.
That is the whole loop, and it is the same idea whether the model has two parameters or billions. This article walks through it with real numbers, then shows how chatbots add extra stages on top. For the wider picture of what counts as AI, see artificial intelligence basics explained.
How does AI learn, step by step?
Google's Machine Learning Crash Course describes the training loop in terms of a technique called gradient descent, which it defines as "a mathematical technique that iteratively finds the weights and bias that produce the model with the lowest loss." The four steps it lists are:
- "Calculate the loss with the current weight and bias."
- "Determine the direction to move the weights and bias that reduce loss."
- "Move the weight and bias values a small amount in the direction that reduces loss."
- "Return to step one and repeat the process until the model can't reduce the loss any further."
Weights and bias are the model's parameters. They start with arbitrary values, so the first predictions are poor. Each pass through the loop nudges them toward values that fit the examples better.
What is loss?
The same course defines loss as "a numerical metric that describes how wrong a model's predictions are." A common choice for predicting numbers is mean squared error (MSE), "the average of L2 losses across a set of N examples." In plain terms: take each prediction, subtract the true answer, square the difference, and average the results. Squaring makes every error positive and punishes big misses more than small ones.
Loss is the only thing the model "sees" about its own performance. It never gets a feeling of being right or wrong, only a number to push down.
A worked example you can check by hand
This example is my own arithmetic, not taken from a source. It uses the simplest possible model, one weight w and a prediction of w * x, trained on three examples where the true answer is always twice the input:
| Input x | True answer y |
|---|---|
| 1 | 2 |
| 2 | 4 |
| 3 | 6 |
The model does not know the answer is 2 * x. It starts with w = 0. For MSE, the direction and size of the adjustment comes from the gradient, which for this model is (2/3) * sum((w*x - y) * x) over the three examples. Each update subtracts the gradient multiplied by a step size. Here the step size is 0.1 (a value I chose; the crash course uses 0.01 in its own example).
| Step | w | Loss (MSE) | Gradient |
|---|---|---|---|
| 0 | 0.0000 | 18.667 | -18.667 |
| 1 | 1.8667 | 0.0830 | -1.2444 |
| 2 | 1.9911 | 0.00037 | -0.0830 |
Check step 0 by hand: the predictions are 0, 0 and 0, so the squared errors are 4, 16 and 36, which average to 18.667. The gradient is negative, which says that increasing w reduces loss. The update is 0 - 0.1 * (-18.667) = 1.8667. Two steps later the weight is within 0.01 of the true value of 2 and the loss has dropped by a factor of about 50,000. Real training stops when the loss no longer falls meaningfully.
The step size matters. With 0.1 here the weight lands close to 2 within two steps. A much larger step would overshoot the target and could make the loss grow instead of shrink; a tiny one would need many more repeats. Choosing it is part of training a real model.
How does a chatbot learn language?
Large language models use the same loop on a different task. Google's course says the key ingredient is "a phenomenal amount of training data (text), typically somewhat filtered." In the masked-prediction approach it describes, "certain tokens in the training data are intentionally hidden," and the model "trains by trying to predict those missing tokens." The text supplies its own correct answers, so no one has to label it by hand.
The course also says LLMs are "essentially autocomplete mechanisms" that predict a token or a sequence of tokens. Many chat models are trained to predict the next token rather than a masked one in the middle; the loop is the same, only the hidden word changes. How the network decides which earlier words matter for each prediction is covered in the attention mechanism explained. The parameter counts you see in model names, such as 7B, are the number of values adjusted during this process; see what "7B" means in an LLM.
How do people teach AI to follow instructions?
A model trained only to continue text is not yet a good assistant. The 2022 OpenAI paper on InstructGPT describes adding two more stages:
- Collect "a dataset of labeler demonstrations of the desired model behavior" and use it "to fine-tune GPT-3 using supervised learning."
- Collect "a dataset of rankings of model outputs" and use it to "further fine-tune this supervised model using reinforcement learning from human feedback."
In that paper, outputs "from the 1.3B parameter InstructGPT model are preferred to outputs from the 175B GPT-3, despite having 100x fewer parameters." The result shows that how a model is trained can matter as much as how big it is. Exact recipes for current commercial models are not fully public, so treat this paper as a documented example of the method, not a description of any particular product.
How do we know the AI learned something useful?
A model can score well by memorizing. Google's course defines overfitting as "creating a model that matches (memorizes) the training set so closely that the model fails to make correct predictions on new data," and says generalization, "a model that generalizes well makes good predictions on new data," is the opposite.
The standard defence is to split the data. The course describes a training set "that the model trains on," a validation set that "performs the initial testing on the model as it is being trained," and a test set "for evaluation of the trained model." Its example partition is 70% training, 15% validation and 15% test. The test set "serves as a proxy for real-world data," so it must stay unseen until the end.
Does AI keep learning after release?
Usually not. The parameters are fixed once training ends, and using the model only reads them. A chatbot remembers your earlier messages by receiving them again as input, not by changing its parameters. Some systems do adapt after deployment, such as recommenders that tailor themselves to a user, but that is a design choice for each system. If a model gives a wrong answer with confidence, that comes from what it learned, not from a live lookup; why AI hallucinates explains the consequence.
Frequently asked questions
- Does AI keep learning while I chat with it?
- Not in the usual case. Training happens before release, and the model's parameters stay fixed while you use it. A chatbot can use what you typed earlier in the same conversation, but that is context it reads, not training. Whether a provider later uses conversations to train new versions is a policy set by that provider, so check its privacy settings.
- Who tells the AI whether it is right?
- It depends on the method. In supervised learning, the labels in the training data are the correct answers. In language model pretraining, the text itself supplies the answer, because the hidden or next word is known. In reinforcement learning from human feedback, people rank model outputs and a reward signal is built from those rankings.
- How much data does an AI need to learn?
- There is no single number. Google's course describes large language models as needing a very large amount of text, typically somewhat filtered. A small model such as a two-parameter line fit can learn from a handful of examples. The needed amount grows with the number of parameters and the difficulty of the task.
- Can AI learn the wrong thing?
- Yes. Overfitting is the best-known case: the model memorizes its training set so closely that it fails on new data. A model can also learn gaps or skew in its examples. This is why a separate test set, which the model never trained on, is used to check the finished model.
Sources
- Google Machine Learning Crash Course: Gradient descent
- Google Machine Learning Crash Course: Loss
- Google Machine Learning Crash Course: Overfitting
- Google Machine Learning Crash Course: Dividing the original dataset
- Google Machine Learning Crash Course: Transformers (large language models)
- Ouyang et al., Training language models to follow instructions with human feedback (arXiv:2203.02155)