How a model works — study guide

The concept's fragments, read in order.

For your capstone Take your own app to production

The assistants that review your app's changes and triage its alerts run on a model whose knowledge stopped at a training cutoff and never included your code, your database or last night's incident. Whatever they should reason about, the diff, the alert, the recent logs, your tooling has to place in the call, every call.

An alert fires: checkout requests on your app are failing with 503. The triage call carries the alert text and the last 200 log lines. The reply blames the migration in release 2.12.0, and it reads exactly as sure as a correct answer would, because nothing in the generation loop compared it with your deploy history. Checking it means reading your deploy history, which the model never saw.

What happens when you call a model

Calling a language model looks like asking a question and getting an answer. Underneath, something narrower is happening. The text you send is split into tokens, the model computes a probability for every token that could come next, one of them is picked, and that token is added to the end of the input. Then the whole thing runs again, one token per pass, until the model emits a stop token or reaches a length limit. The process works like the next-word suggestions on a phone keyboard, made vastly more capable and run in a loop where each suggestion is accepted and fed back in before the next one is made.

The part that computes those probabilities is a transformer whose weights were fixed when its training finished. This concept is not about how attention works inside it. It is about the loop around it, and what that loop means for anyone sending it work.

Four consequences follow, and the rest of this concept unpacks them. The output is sampled from a distribution, not looked up, so the same input can produce different text. The model keeps nothing between calls, so whatever it should take into account has to be in the input. What it knows was settled when training ended. And nothing in the loop checks the output against the world, so fluent text and correct text are two different things.

One token at a time

generation is a loop: score, pick, append, run again input tokens The cat sat on the mat the whole sequence goes in model same fixed weights every step a probability for each candidate mat 0.67 floor 0.24 roof 0.09 illustrative: a real vocabulary has far more candidates pick one mat append the pick, then run the whole loop again one pass produces one token; a reply is many passes
Generation is a loop: the whole token sequence goes into the model, the model returns a probability for every candidate next token, one token is picked, and it is appended to the input before the model runs again.

A transformer reads its whole input sequence and, at the last position, produces one raw score for every token in its vocabulary, the fixed list of word pieces it was trained with. These scores, usually called logits, are not probabilities yet. A standard step called softmax turns them into probabilities: every score becomes a positive number, and the numbers are scaled so that they add up to one. The result is a probability distribution over what the next token could be.

A decoding rule then picks one token from that distribution, and the pick is appended to the sequence. The model runs again on the longer sequence and produces a fresh distribution for the token after that. A reply of a few hundred tokens is a few hundred of these passes, each conditioned on everything before it, including the tokens the model itself just produced. Serving systems can keep the work already done on earlier tokens in a cache so it is not repeated, but the logic is unchanged: each new token is chosen given the sequence so far.

Building text this way has a consequence that is easy to miss. The decoding loop has no step that goes back and edits a token once it has been emitted. An early token that heads the wrong way stays in the sequence, and every later token is conditioned on it, so the loop's job from then on is to continue that path plausibly, not to reconsider it.

Choosing from the distribution

same scores, three temperatures scores 2, 1, 0 for mat, floor, roof; divide by the temperature, then softmax temperature 0.5 87% 12% 2% mat floor roof low: concentrated nearly always mat temperature 1 67% 24% 9% mat floor roof unchanged: the model as is mat usually wins temperature 2 51% 31% 19% mat floor roof high: spread out roof about 1 time in 5 illustrative numbers, rounded to whole percents
The same three candidate scores give different probabilities at different temperatures: low temperature concentrates probability on the top candidate, about 87 percent, while high temperature spreads it out, leaving the top candidate about 51 percent.

Picking the next token is a separate decision from computing the distribution, and it is made by decoding settings, not by the model's weights. The simplest rule, greedy decoding, takes the single most probable token every time. The alternative is sampling: draw a token at random, with each candidate's chance equal to its probability, like rolling a die weighted by those probabilities, where the likeliest face comes up most often but not every time. Greedy choice sounds safest, but in open-ended writing it tends to produce bland, repetitive text that can get stuck in loops, which is the case for sampling there.

Temperature reshapes the distribution before the draw: the raw scores are divided by the temperature, and softmax then turns them into probabilities. Take illustrative scores of 2, 1 and 0 for three candidates, mat, floor and roof. At temperature 1 the scores are used as they are. Softmax raises the number e, about 2.718, to each score, giving about 7.39, 2.72 and 1, which total 11.11, and dividing each by that total gives about 67, 24 and 9 percent.

At temperature 0.5 the scores become 4, 2 and 0. The same arithmetic gives about 54.60, 7.39 and 1, totaling 62.99, so the probabilities are about 87, 12 and 2 percent. At temperature 2 the scores become 1, 0.5 and 0, giving about 2.72, 1.65 and 1, totaling 5.37, so about 51, 31 and 19 percent. The percentages are rounded, so a set can total 101. Low temperature concentrates the choice on the top candidate and high temperature spreads it out; the ranking stays the same, only how lopsided it is changes. Temperature 0 is usually a convention meaning greedy choice, not a literal division by zero.

Two other common settings cut off the tail instead of reshaping it. Top-k keeps only the k most probable tokens and samples among them. Top-p, also called nucleus sampling, keeps the smallest set of top tokens whose probabilities add up to at least p, so the shortlist is short when the model is confident and long when it is not. The upshot is that the same input can produce different outputs by design. Even greedy settings do not promise identical output from a real serving system: the arithmetic runs in finite precision, how the server batches requests together can shift the scores slightly, and when two candidates are nearly tied that can flip the pick, after which the rest of the reply diverges.

A conversation is one long input

what the application sends, and what the model receives the application's message list (structured data) role: system Answer in one sentence. role: user Summarize this report: ... role: assistant The report says ... role: user And the main risk? a template flattens the list one flat row of tokens (wrapped here to fit) system Answer in ... user Summarize this ... assistant The ... user And ... assistant the reply is generated from here marker token: just another token in the same row one input, one channel model
A list of role-tagged messages is flattened by a template into one sequence of tokens, with marker tokens between the parts, and that single sequence is the model's only input: instructions, pasted documents and replies all arrive the same way.

An application talking to a chat model typically sends a list of messages, each tagged with a role: a system message carrying standing instructions, user messages, and the model's own earlier replies tagged as the assistant. That list is structured data, the same kind of thing as any JSON array of objects, and it is how the interface presents a conversation.

The model does not see a list. A chat template, specific to each model, renders the list into one flat text: the messages in order, special marker tokens around each one naming its role, and a final marker that cues the model to begin the assistant's reply. The tokenizer turns that rendering into a single row of tokens, and that row is the input. Whatever else the application adds, a pasted document, search results, the output of a function it called, arrives the same way, as more tokens in the same row.

So instructions and data travel in one channel. The role markers are tokens in the same row as everything else, and a model's habit of giving the system message more weight than a pasted document is a tendency it learned in training, not a boundary the architecture enforces. Text inside a document that is phrased as an instruction can be read as one. Who gets to put text in front of a model is therefore a design decision, and the ways it goes wrong are a subject of their own under failure modes.

Nothing carries over between calls

the application remembers; the model does not input the application sends model output call 1 turn 1 sent in fixed weights reply 1 nothing carried over between calls the application saves the reply call 2 turn 1 reply 1 turn 2 sent in same weights reply 2 re-sent by the application each call is computed from its input alone, so every call's input must carry everything the model should take into account
The model keeps nothing between calls: the application stores the conversation and re-sends all of it on every call, so the second call's input carries the first turn and its reply as well as the new turn.

Inference does not change a model's weights. Every call runs the same fixed weights over exactly the input that call supplied, and when the call ends nothing of it is kept inside the model. A second call is computed from its own input alone; the model holds no record that the first one happened.

A chat that seems to remember is the application doing the remembering. It stores the conversation, and on each new turn it sends the earlier messages again along with the new one, so the model sees the history because the history is in the input. The model is like a worker who arrives each time with no memory of earlier visits and works only from the notes left on the table, so anything missing from the notes might as well not exist. Some services will store the conversation on their side for you; that is the service keeping text and putting it back into a later input, not the model having learned anything. Applications may trim or summarize long conversations for the same reason: everything the model should consider has to arrive in one input.

The same holds for learning within a call. Give a model a few worked examples in its input and it will often follow the pattern, which is called in-context learning, but the weights do not change. Leave the examples out of the next call and the lesson is gone. Deciding what goes into each input, and what to leave out when it will not all fit, is the territory of context windows.

Trained to continue, then to assist

A model trained only to predict the next token across a large body of text is a continuer: given the start of a document, it produces a plausible rest of it. Given a question, a plausible continuation might be an answer, or it might be more questions, the way a page of exam questions continues. The assistant-style models that applications call have had further training on top of that, called post-training, to make a helpful answer the likely continuation.

Post-training usually includes supervised instruction tuning and preference tuning, and increasingly reinforcement learning on tasks whose answers can be checked automatically. Supervised instruction tuning trains the model on examples of instructions paired with good responses, using the same next-token objective as before. Preference tuning then uses comparisons, this response preferred over that one, to shift the model toward the responses people rated better. Reinforcement learning from human feedback does this with a separately trained scoring model; other methods train directly on the preferred and rejected pairs. The effect can be large: in one well-known study, people preferred the answers of an instruction-tuned model over those of a base model with more than 100 times as many parameters.

None of this replaces the loop. The assistant still computes a distribution over the next token and picks from it; post-training changed which tokens are likely, not what the model is doing. That is why its habits, the format it favors, its tone, the requests it declines, are learned tendencies that usually hold rather than rules it is checked against. Preference tuning can also reward answers that sound good to the people rating them without being true, so sounding helpful and being right remain separate achievements.

Knowledge stops where training stopped

Everything a model knows on its own comes from its training data, and that data stops at some date, the training cutoff. Events after it are absent. So is anything that was never in the data at all: a company's internal documents, your codebase, yesterday's incident, the rows of a database the model has never been shown. The model's knowledge is like a printed reference book, thorough up to the day it went to press and silent about everything since. Even the cutoff is approximate, since coverage is uneven, and some providers publish a separate, earlier date up to which they consider the knowledge more reliable.

That knowledge is not stored as a table of facts the model consults. It is spread through the weights as the patterns that made the training text predictable, and recalling it means generating likely text, not retrieving a record. One consequence is that a model cannot reliably tell you its own cutoff: asked, it produces a plausible answer rather than reading a date from anywhere, and research finds such self-reports do not reliably match what the model can actually recall. The provider's documentation is the place to look.

Asked about something after its cutoff or outside its data, a model may say it does not know, give an answer that was true at training time and is not now, or produce a confident guess. The fix is not a cleverer question but a different input: current or private information has to be supplied in the call itself, by the application, when it is needed. Retrieval and tools, which later concepts build on, do exactly this, and they change what the model reads, not what it has learned.

Fluent is not the same as checked

The loop has no step where the output is compared with the world. At each pass the model scores which token is likely given the text so far, and likely is a statement about text, not about truth. Often the likely continuation is also the correct one. When it is not, the model produces the wrong answer in exactly the same fluent, well-formed way.

That is the mechanical root of what gets called hallucination: confident output that is false, delivered in the same voice as output that is true. It does not need bad training data to happen. Facts that appeared rarely in training are harder to learn reliably than patterns repeated many times, and evaluations that score an honest "I don't know" the same as a wrong answer reward a model for guessing. Both pressures push toward a confident answer whether or not one is warranted.

The tone of the text is not a reliable signal either. Wording such as "certainly" or "the answer is" is itself generated text, and a model's expressed confidence does not dependably track whether it is right. So model output is a claim, and checking it takes something outside the model: a test that runs, a source that can be read, a person who knows. Which failures to expect, and how to measure them, belong to failure modes and evaluation harnesses.

What is settled and what is argued

Some statements about language models are mechanical facts. A model computes a probability distribution over the next token from the input it was given. Its weights do not change while it is being used, and it keeps nothing between calls. Nothing in the generation loop checks its output against the world. Those hold for any model run this way, and none of them is in dispute.

Whether such a model understands, reasons or knows is a different kind of question, and the evidence points both ways. In one well-known experiment, a model trained only to predict legal moves in the board game Othello turned out to hold an internal representation of the board, and altering that representation changed the moves it predicted, which suggests more than surface pattern matching. On the other side, in a 2024 study, changing only the numbers in grade-school math problems lowered accuracy for most models, usually by a few points. Adding one sentence that seemed relevant but did not affect the answer cut accuracy by more than 65 percentage points for one small model (from about 84 to 18 percent), and by 17.5 points for the strongest model tested, which looks like reliance on familiar problem patterns. Both findings come from particular models and tasks, and neither settles the general question.

Models that write out intermediate steps before answering add a wrinkle. Writing steps out can help, but the written reasoning is more generated text, not a readout of the computation. Studies have found explanations that leave out the cue that actually swayed the answer, and models whose answers barely changed when their written steps were altered, with the degree varying by task. Read a model's explanation as a claim about its reasoning, not a record of it.

The practical stance does not require settling the debate. Words like understands and knows describe behavior in human terms, and they are useful shorthand as long as nobody mistakes them for guarantees. What matters for anything built on a model is how it behaves on the actual task, measured, including on inputs that differ slightly from the ones it was tried on.

What follows for anything you build on it

Whatever is built on a model, an agent pipeline handing it the steps of a task, a robot that asks it for a plan, an application that calls it on a user's behalf, inherits the loop's properties, and each property becomes a piece of engineering. Because the model keeps nothing between calls, every call has to carry everything it needs, and choosing what goes in is the subject of context windows. Because the model continues whatever text it is given, how that text is written shapes what comes back, which is the subject of prompt structure.

Because the output is sampled and unchecked, the application has to treat it as a claim: constrain its shape, verify it, and judge it across many runs rather than one, which is where failure modes and evaluation harnesses come in. And because a reply is produced one token per pass, the length of the input and of the output is what the work and the waiting are measured in, the starting point for cost and latency.

The picture to keep is short. Text in, a distribution over the next token out, one token picked and appended, repeat. Nothing remembered between calls, nothing learned along the way, nothing checked. Many of the surprises a model produces in practice make sense once that picture is in hand, and much of the design work around a model is supplying what the loop lacks.

Next on your path to Take your own app to production: