How a language model works: watch
A language model answers smoothly and confidently even when it is wrong. To know where it can be trusted, it helps to see how it learns and how it builds an answer word by word.
Exercises and files are in the text version.
Part 1How a model learns
Twelve shots: tokens, a neuron, layers, the error, training, frozen weights, the random pick and what happens to your data. The numbers in the film are illustrative, a teaching example.
Exercises and details for this part · The film on its own page
Part 2Where the answer comes from
What the assistant hides behind the chat window: what the input consists of, how the model picks words and how the answer breaks down into statements of different origin.
Exercises and details for this part · The film on its own page
Check yourself
As text
The same as the films: every shot and its text. You can copy the text and give it to your own assistant along with your question.
How a model learns
The answers of a chat assistant are written by a language model, a program that continues text word by word. Inside it there is no reference book and no written rules of language: there are only numbers, billions of them in a large model, and not one of them was written in by a person. How the program picks these numbers by itself explains the model's main property: the answer sounds smooth and confident even when the fact in it is wrong.
A program cannot compute with letters, so the text is first turned into numbers. It is cut into tokens, that is, words or parts of words, and each token has its own number in the model's vocabulary. The vocabulary holds tens or hundreds of thousands of pieces, and any word can be built from them, even a rare one. The sentence “The defendant appealed” fell into four tokens, because the program cut “defendant” in two. The split and all the numbers in the film are illustrative.
With token numbers the model does one thing: from the start of a text it estimates which token comes next. It answers not with one word but with a probability for every token in the vocabulary. A probability is a number from zero to one: the larger it is, the more plausible the continuation, and all the options together add up to one. After “The defendant” the word “appealed” got 0.62, about six chances in ten.
The model computes the probabilities, and the smallest unit of this computation is a neuron, in its simplest form a small formula. Each input number is multiplied by its weight, the results are added, and the sum is squeezed, here into a number between zero and one: 1.28 becomes 0.78. A weight shows how strongly an input affects the result: with a weight of 0.9 it counts for a lot, with 0.2 for almost nothing. In the picture, a weight is the thickness of a wire.
One neuron can do little, so neurons are gathered into layers, and the layers are placed one after another. The output of each neuron becomes an input for every neuron of the next layer, and each such connection has its own weight. This network has three layers of five neurons and fifty weights between them. A large language model is built in a more complex way, but the principle is the same, and it has billions of weights.
At the start all these weights are random, and the network computes nonsense with them. The token numbers of “The defendant” pass layer by layer, and at the output all the options get almost the same probability: “appealed” gets 0.19, no more than any other word. Setting the right weights by hand is impossible: there are too many of them, and nobody knows what they should be. So the program finds the weights itself, and this search is called training.
Training needs only ready-made texts: in each of them the next word is already known. The model is shown the start, “The defendant”, and gives the word “appealed” a probability of 0.19. In the text the next word really is “appealed”, so the correct probability is one. The difference, 0.81, is the error here. Real training uses a different formula, but the idea is the same: the less the correct token got, the larger the error.
The error is passed back through the network, from the output to the input, and each weight is shifted slightly in the direction where the error gets smaller. One such step changes almost nothing, so millions of them are made, each time on a new passage of text. The probability of “appealed” gradually rises from 0.19 to 0.62. It will not reach one, because in other texts the same words are followed by “objected” or “paid”.
When training ends, the weights are fixed, and that makes a version of the model. Of the texts it read, only these numbers remain: patterns of language, not a database where a fact could be found and checked. A chat conversation only reads the weights to compute an answer and changes nothing in them. If an assistant remembers past chats, those are saved notes it adds to a new request, not training.
The next version is trained on a new set of texts, and the provider may add users' conversations and files to it. Whether this applies to you depends on the product, the plan and your account settings. The switch in the settings works only going forward: what has already entered the set cannot be taken back. Even when you turn training off, the provider keeps conversations on its servers for some time, and in some cases its staff read them.
For the same request a finished model computes practically the same probabilities, yet the answers differ. The next token is drawn from them at random, but so that a likelier option comes up more often: “appealed”, with a probability of 0.62, wins most of the time, but not every time. Of three runs, two gave “appealed” and one gave “objected”. The chosen token is added to the text, and everything repeats for the next one until the answer is complete.
The model was trained for one thing: to continue text the way it is usually continued. On a common phrase such a continuation is mostly correct. A rare fact, such as a case number, hardly ever appeared in the texts, yet the model produces something similar in form just the same. It has internal signals of whether a topic is familiar, but they are unreliable and invisible in the answer: the known and the merely plausible sound the same. That is why facts are checked against the source.
Where the answer comes from
A person asks an assistant to briefly summarize a memo about an office lease and within seconds gets three even sentences: the parties and the term, rent of UAH 35,000 per month, a penalty of 0.1% a day. The model took the first from the memo, the amount in the second belongs to something else, and the third is not in the memo at all. They look no different. To know what to check, trace where the model takes each statement from.
The first source of statements is the text the model receives together with the request. The model itself does not keep the conversation, so each time the product assembles this text anew: its own instructions, the attached memo, the conversation history and the latest message. All of it together is called the context. Here it holds two amounts: UAH 30,000 in the memo and UAH 35,000 in an earlier message about the office next door.
From the context the model builds the answer not whole but one word or part of a word at a time, each time continuing what is already written. For every next word it computes a probability, a number from zero to one that shows how well the word fits after the previous ones. After “from 1 February 2026 for 12” nearly all the probability goes to “months”, because that is what the memo says. The numbers in the film are illustrative.
The model picks a word by these probabilities, but with a share of randomness, so sometimes it takes not the likeliest one. After “The rent is UAH” both amounts from the context have a noticeable probability: 30,000 from the memo a larger one, 35,000 from the conversation a smaller one. This time the model picked 35,000, and the sentence is then built around it. The mechanism itself has no step at which the amount would be checked against the memo.
That is how statements from three different sources end up side by side in the finished answer. The model took the parties and the term from the attached material, the memo. The amount of UAH 35,000 came from the conversation: the person wrote it, only about another office. The penalty comes from training: before release the model was trained on a vast amount of text, and what remains of it is mainly patterns of which words usually follow which.
The third source is the least visible, and hallucinations come from it. The memo says nothing about a penalty, but in the leases the model met in training a penalty usually follows the rent, quite often exactly 0.1% a day. So that continuation has a high probability, while the words “the memo does not say” are rare in texts. A statement with the right form but no source is called a hallucination.
By tone alone a hallucination cannot be told from a checked statement. The model has internal signals of whether a statement is familiar to it, but they are unreliable and invisible in the answer. A confident tone is also assembled word by word as the most usual continuation, so it is only loosely tied to correctness. All three sentences sound equally even, although the memo confirms only one.
Since the tone gives no clue, the answer is split into separate statements, and each gets one question: where is this written in the material. This answer has three statements: who rents from whom and for how long, what the rent is, and what the penalty is. The concrete ones are checked first, that is names, dates, amounts, percentages and quotations: hallucinations are frequent there, and a mistake costs a lot.
The check itself is simple: the answer is placed next to the memo, and for each statement you look for the line that confirms it. The parties and the term match point 1. In point 2 the rent is UAH 30,000, not 35,000, so the amount is corrected. The memo has no point about a penalty, so that statement stays without a source and is removed from the summary. The memo confirms one of three.
Asking again does not replace this check. The model picks words with a share of randomness, so the same request can produce different text: here the second answer already has rent of UAH 30,000 and no penalty. If the answers had matched, that would prove nothing, because a repeat compares them with each other, not with the memo. A difference is still a useful hint: the places where answers differ are checked first.