SOPHIA XT
Course 1 of 5 · Introduction to language models

How a model turns your words into an answer

By the end of this you will know what a language model receives, what it hands back, and why that one shape explains nearly everything people find strange about these systems.

7 lessons about 16 minutes read it or have it read to you
How to read this

Twenty figures carry most of the argument, so let one finish a cycle before moving on. Each says on its own face whether its numbers were chosen to show a shape or calculated in front of you. The main thread needs no mathematics; the folds marked Deeper are optional.

Lesson 01

A model only ever answers one question

Everything a language model does is a single operation, run over and over.

Put any text in front of a language model and it does one thing. It reads the text and produces a guess at what comes next. Not a sentence, not a paragraph, not an answer. One piece of text, usually shorter than a word.

That guess is stuck onto the end of the text, and the whole thing goes back in. The model reads the longer text and guesses again. A few hundred of those in a row is the reply you see appear.

Figure 1.1
One token per pass, then the whole text is read againPASS 1 OF 6THE TEXT SO FARThecapitalofFranceisamber: what you typedmint: what the model has added so farall of it, on every passthe modelone pass over the whole text, one prediction outParisexactly one token comes out, and it is appended to the row above
Watch what goes into the box on each pass. Not the newest word, all of it, from the beginning, every time. The model has no notes from the previous pass to work from, which is why the growing text has to carry everything.

Drawn as a line it looks like a sequence of events. It is closer to a wheel, and the wheel is why one model can write code, summarise a contract and translate Portuguese without anyone having built three systems. Those are not three features. They are the same turn of the same wheel, on text that happens to look like code, a contract, or Portuguese.

Figure 1.2
The whole of it is one wheel, turning once per tokenONE TURN OF THE WHEEL IS ONE TOKENyour textcut intotokensthe model,one passa score forevery tokenone tokendrawnadded tothe textnothing elsehappens in herea paragraph is this wheel turning a few hundred times
Six positions, one marker, and no exit. Everything in the remaining six lessons is a closer look at one of these six positions, which is worth holding on to when a later lesson gets detailed.
What people usually think

The model works out its answer, then writes it down.

There is no plan sitting anywhere. At the moment a model produces the word "three" in "there are three reasons", nothing in it has committed to what those three reasons will be. They get worked out on later passes, from the text, because the text is all there is.

That cuts both ways, and usefully. It is why asking a model to work through something on the page changes its answers rather than just their length. The working becomes text, and the text is read on the next pass. Writing is the only scratchpad it has.

Deeper: the models that think before they answer

Some models now produce a long stretch of working before showing you anything. That is not a different mechanism. The working is tokens, generated by the same loop, and the product simply does not display them. The scratchpad is still text; it is text you were not shown.

There is real machinery that stops the model recomputing the entire sequence on every pass, usually called a key value cache. It is an optimisation over the same arithmetic and it does not give the model a plan that survives outside the text.

A language model predicts one token at a time, and every prediction is made by reading the whole text again from the start.

Lesson 02

Text arrives in pieces, and the pieces are not words

Before anything else happens, your sentence is cut up and turned into numbers.

A model cannot receive letters. Your sentence has to become numbers first, and the step that does it is called tokenisation. It cuts the text into pieces somewhere between a letter and a word, drawn from a fixed list built once before training and never changed afterwards.

Figure 2.1 Illustrative
How three strings are split into tokensEXAMPLE 1 OF 3The cat sat on the mat.WHAT THE MODEL RECEIVESTheid 1000·catid 1313·satid 1626·onid 1939·theid 2252·matid 2565.id 28787 tokensCommon words arrive whole, with the space in front of them attached.a middle dot stands for the leading space, which is part of the token
Common words arrive whole, rarer ones get assembled out of fragments, and the space in front of a word belongs to it. These are the splits one widely used byte pair vocabulary produces; another model would cut the same three strings differently, so the pattern is the lesson and the pieces are one example of it.

This is where a whole family of failures comes from, the ones that look like stupidity and are not.

Figure 2.2 Illustrative
Why counting letters goes wrong, and what fixes itHOW MANY TIMES DOES R APPEAR IN THIS WORDasked straightstrawberrythree tokens, and not one of them is a letterasked to spell it out firststrawberrynow each letter is its own tokenthe model is working around its own input here, not reading
The top half is the question as it actually arrives. The bottom half is why asking a model to spell a word out before counting anything works, which is a trick worth knowing and a strange one until you have seen this.

The other consequence is money. Tokens are the unit everything is priced and rate limited in, and the same meaning does not cost everybody the same number of them.

Figure 2.3 Illustrative
The same sentence is not the same length to a tokenizerONE SENTENCE, SAME MEANING, FIVE LANGUAGESEnglish12Spanish15German17Russian27Hindi34more tokens is more money, more of the window, and a slower replythe direction is the point; the exact counts depend on the tokenizer
A document in a language the vocabulary was not built around can cost two or three times as many tokens for identical content. That is the same text taking two or three times as much of the window, and two or three times the money.
Deeper: why a fixed vocabulary, and why it cannot be changed later

Byte pair encoding starts from single bytes and repeatedly merges the most frequent adjacent pair until the list reaches its target size. Frequency buys brevity, and that is the whole of the cost difference above: the merges were learned from a corpus, so text resembling that corpus compresses better.

It is also why the vocabulary cannot be swapped after training. Every entry is bound to a row of learned weights, so changing the list means training the model again.

The model receives numbered pieces of text, never letters, and which pieces exist was decided before training began.

Lesson 03

Each piece starts as a point, and the sentence moves it

Where meaning actually lives, and where it does not.

Every entry in the vocabulary owns a list of numbers learned during training. A few thousand of them, in most models, and not one of them means anything on its own.

Figure 3.1 Computed live
A vector is a row of numbers, and near is a calculationTWENTY SIX CELLS STANDING IN FOR A FEW THOUSANDcatdogbicyclecat against dog: 0.94one is closeness in use, the other is not, and no single cell decides itthe cell values are invented; the similarity between them is really calculated
Nothing in a row like this is readable. What is real is the comparison: two tokens used in similar ways end up with similar rows, and the closeness is a calculation rather than an impression. That is the whole content of a word embedding.

But the row for "bank" is one row. It is identical whether you are talking about a river or a mortgage, because it was fixed long before your sentence existed. What changes with your sentence is what the model builds on top of it as the text passes up through the layers.

Figure 3.2 Illustrative
The same token, moved by the sentence around itONE TOKEN, TWO SENTENCESloandeposittellerinterestrivershoremuddycurrentthe token, always herebankI paid it into the bankthe layers pull it toward the company it is keeping in this sentence
The hollow circle is the token's own row and it never moves. The filled point is what the layers have made of it in this particular sentence. Two dimensions are standing in for a few thousand, so read the direction and not the distance.

What does the pulling is the rest of the sentence, and not evenly. Most words barely matter and one or two decide the whole reading.

Figure 3.3 Illustrative
Which words pull on this one, and how hardREADING LEFT TO RIGHT, PULLING ON THE LAST WORDIpaiditintothebankI paid it into the bankthe heavy line comes from paid, so the last word reads as moneyweights chosen to show the shape; a real model spreads them over every word at once
One heavy line and four thin ones, and changing a single word moves the heavy one. This is the shape of the mechanism the second course is about, which is why it gets no name here. A name learned before the thing is a name learned wrong.
Deeper: cosine similarity, and the arithmetic people quote

The closeness in figure 3.1 is cosine similarity, the angle between two rows rather than the gap between them, which is why a rare word and a common one can still come out close.

The famous trick where king minus man plus woman lands near queen came out of older word vector work and holds only loosely, on carefully chosen examples. Take it as a sign that the space has structure, not as an operation you can build on.

A token's starting vector is fixed. Its meaning in your sentence is built above it, out of the tokens around it.

Lesson 04

The output is a whole distribution, not a word

The most useful thing about a model's answer is something you are never shown.

When a pass finishes, what comes out is not a word. It is a score for every single entry in the vocabulary, all of them, every time, squeezed into probabilities that add up to one.

Figure 4.1 Illustrative
Two prompts, two very different distributionsTHE NEXT TOKEN, AS A DISTRIBUTIONThe capital of France isthe top eight of a vocabulary of tens of thousandsParis92%the2%a1.4%located1.1%home0.9%one0.8%now0.6%still0.5%every other token in the vocabulary is in here too, at a number too small to drawnumbers illustrative, shapes representative
Two prompts, drawn on the same scale. The reply you would read looks equally assured in both cases, because what you read is a token drawn from the list rather than the list itself.

Eight bars is how this always gets drawn, and it is quietly misleading. The list is the whole vocabulary, and the part nobody draws is the part that decides what happens when there is no obvious answer.

Figure 4.2 Illustrative
One spike, and tens of thousands of almost nothingEVERY TOKEN GETS A NUMBER, EVERY TIMEParisthe eight bars in the figure above are eight of these, magnifiedwhen the spike is missing, the answer comes out of that flat fieldheights chosen to show the shape; the field stands for far more tokens than are drawn
A spike this sharp is a model that has met the answer many times. Take the spike away and the flat field is still there, still adds to one, and something still has to be picked out of it. Lesson seven is that sentence in detail.

And this happens again for every token, not once per answer.

Figure 4.3 Illustrative
The same distribution, five times in a rowTOKEN 1 OF 5TherecipecallsforWHAT THE MODEL OFFERED FOR THIS ONEtwo31%a22%one14%three9%drawn: twothe list is rebuilt from scratch for every single tokennumbers chosen to show how much the shape changes from token to token
Watch the shape change between tokens. Some positions in a sentence are nearly settled by the grammar and some are wide open, and the same model produces both inside one short sentence.
Deeper: logits, softmax, and what a probability is not

The raw scores are called logits and they are unbounded, positive or negative. Softmax exponentiates each one and divides by the total, which turns any set of scores into a distribution that sums to one while keeping their order.

A high probability means the model found that continuation likely given its training. It is not a claim that the statement is true. Most APIs will return these numbers if you ask, and for classification work, reading the probability of each label directly is usually better than parsing a sentence the model wrote about its choice.

Every pass produces a probability for every token the model knows. A peaked distribution and a flat one are indistinguishable in the reply you actually read.

Lesson 05

Choosing from the list is a separate decision, and it is yours

The setting that most people never touch and most often need.

The model produces the distribution. Something else picks a token out of it, and that something else is not the model. It is a short piece of code with settings on it, and the settings are usually yours to change.

Take the highest number every time and the same prompt returns the same answer forever. Draw at random instead, weighted by the probabilities, and you get variety. Temperature is the dial deciding how faithfully that draw follows the numbers.

Figure 5.1 Computed live
Temperature reshapes a distribution without changing the scoresSAME SCORES, DIFFERENT TEMPERATUREThe weather today istemperature0.20nice97%cold3%warm0%going0%supposed0%perfect0%grim0%glorious0%cold: one option takes nearly all of it, and the model repeats itselfthe eight scores never change; only the division by temperature does
Eight fixed scores, and the bars are a real calculation rather than a drawing. Watch the bottom four vanish as the dial comes down and reappear as it goes up. That is the whole of what temperature does, and it never touches the scores themselves.

The second dial is usually called top-p, and it does something different enough that confusing the two will cost you an afternoon.

Figure 5.2 Computed live
Top-p throws the tail away before the drawKEEP FROM THE TOP UNTIL THEY ADD UP TO Pp0.30nice42%cold21%warm14%going9%supposed6%perfect4%grim3%glorious1%cutkeeping 1 of 8, 42 percent of the weightthe eight scores are invented; the cut is really calculated from them
Temperature reshapes the whole list. This throws part of it away and then draws normally from what is left, which is what lets a warm temperature stay interesting without occasionally reaching into nonsense.

Between them, these two settings account for most of what gets attributed to a model having a personality, or to having had a bad day.

Figure 5.3 Illustrative
Four runs of one prompt, two ways of choosingRUN 1 OF 4, SAME PROMPT EACH TIMEalways the top tokenDearMsPatel,thankyouidentical on every run, which is what you want from an extractordrawn from the distributionDearMsPatel,thanksagainamber marks where this run left the greedy path
Same prompt, same model, four runs. If a question with one right answer keeps coming back differently, this is the layer to reach for, and it is a great deal cheaper than rewriting the prompt.
Deeper: why identical settings can still give different answers

Temperature zero is not a guarantee of identical output in practice. Floating point addition is not associative, so the way a server batches your request alongside other people's can shift the last digits of a score, and two options that were nearly tied can swap places.

Models that route each token to a subset of their own components can be sensitive to what else is in the batch for the same reason. If you need reproducibility, you need it stated by the provider rather than inferred from a setting.

The model hands you a distribution. Temperature and top-p decide how that becomes a word, and they are settings rather than personality.

Lesson 06

It only knows what is in front of it

There is no memory. There is a window, and it is re-sent in full every turn.

A model has no memory of you between requests. None at all. Every conversation that appears to remember what you said ten minutes ago works by sending all of it again, invisibly, as part of the text.

Figure 6.1 Illustrative
The frame is fixed and the conversation slides through itTHE CONVERSATION MOVES, THE ROOM DOES NOTalready droppedwhat is actually sentnot written yetthe context windownothing is retrieved from the left of that frame, evera memory feature is software copying something back in before it leavesblock widths stand for turns of different lengths
The frame does not move. The conversation does. Most diagrams of this draw it the other way round and quietly teach that the model reaches back through history, which is the misunderstanding rather than the mechanism.

The frame has a size, called the context window and measured in tokens, and you are not the only claimant on it.

Figure 6.2 Illustrative
Everything competes for one bar, and the reply losesONE WINDOW, FOUR CLAIMS ON ITinstructions you never saw10%documents you attached22%the conversation so far6%room left for the reply62%plenty of room, and the answers can be as long as they need to beproportions chosen to show the squeeze; every product divides this differently
The instructions a product wrote before you arrived are in there, and so is every document you attached. The part that gets squeezed as a conversation grows is the reply, which is why long sessions start producing shorter answers.

When a conversation outgrows the window something has to go, and different products choose very differently: drop the oldest turns, replace them with a summary, or keep a running set of extracted facts.

Figure 6.3 Illustrative
A conversation outgrowing the room the model hasTURN 5 OF THE CONVERSATIONyoumodelyoumodelyou20 of 24 units of room used, 5 of 5 turns still sentthe faded turns are still on your screen; they stopped being in the requestwhich ones to drop is the application's decision, not the model's
The faded turns are still on the reader's screen, which is what makes this so confusing in practice. They stopped being in the request, and nothing visible changed at the moment they fell out.
What people usually think

It remembers our earlier conversations.

Unless a product has explicitly built a memory feature, which stores things somewhere and pastes them back into later conversations on your behalf, a new chat starts with a model that has never encountered you. The sense of continuity is a file being sent again.

Talking to it does not change its weights. Nothing you say is learned by the model during your conversation, whatever else a provider may or may not do with the transcript afterwards.

Deeper: why a long window is not free

In the standard arrangement, every token is compared against every other token, so that part of the work grows with the square of the length. Doubling the text roughly quadruples it. A great deal of engineering now softens this, but the shape of the cost is why a very long window is an achievement rather than a number somebody chose.

Recall across a long window is also uneven. Published work has repeatedly found that material at the very start and the very end of a long context is used more reliably than material buried in the middle, so filling a window is not the same as being understood.

There is no memory. There is a window, it is re-sent in full every turn, and what falls out of it is your application's decision.

Lesson 07

Why it invents things, stated precisely

The behaviour people complain about most is the behaviour the first six lessons predict.

The model produces a distribution and something draws from it. For a fact it met thousands of times in training, the distribution is a spike and the draw lands on the right token. For a fact it met twice, or never, the distribution is flat across a handful of plausible looking options, and the draw lands on one of them anyway. There is no branch in the code that checks whether it knows.

Figure 7.1 Illustrative
A fact it holds, and a sentence it assemblesFIVE DRAWS, SHOWING DRAW 1MET MANY TIMES IN TRAININGThe Eiffel Tower was finished in188918871888MarchtheThe Eiffel Tower was finished in 1889reads perfectly, and the year is rightBARELY MET AT ALLThe Brayford Mill was finished in1889184619021871theThe Brayford Mill was finished in 1846reads perfectly, and no fact sits under any of them
Same model, same settings, five draws each. On the left the draw lands on the same token nearly every time. On the right it moves, and every sentence it produces is just as well formed as the one beside it. One of these two buildings does not exist.

The obvious next question is whether the model can tell. Partly, and less than you would want.

Figure 7.2 Illustrative
More confident is more often right, and never only rightFORTY ANSWERS, BY HOW SURE THE MODEL WASless suremore surerightwrong0.40keep only what is above the line and you hold 22 right answersand still let 8 wrong ones through, having thrown away 3 good onespoints drawn to show the shape of a real and widely reported relationship, not an experiment
The relationship is real, which is why the probability is worth reading if you can get at it. No vertical line on this chart separates the two colours, which is why it is not a solution. Move the line and watch what you give up to buy what you gain.

So the dependable fix is not a better instruction, because an instruction cannot create knowledge that was never there. It is putting the material into the request.

Figure 7.3 Illustrative
The same question, with and without the page attachedWHEN DOES THE WARRANTY ON A MODEL 400 ENDASKED COLD2 years1 year5 years90 days"The Model 400 carries a two year warranty."fluent, specific, and assembled from nothingASKED WITH THE PAGE IN THE REQUEST"...cover on the Model 400 runs for thirty six months fromthe date of installation, excluding the compressor..."36 months2 years3 years1 year"Thirty six months from installation, minus the compressor."same machinery, and now there is a sentence you can go and check
Nothing about the model changed between these two. The distribution went from flat to peaked because the answer was in the request, and the second reply can be checked against a sentence you can go and read. That is the fifth course in this track.
Deeper: what confidence is actually worth

The probability on the chosen token carries real information, and low probability answers are wrong more often, so a system that can read those numbers can act on them. There is also published work showing that a model's internal activations separate true statements from false ones better than its own stated confidence does.

But a model asked how sure it is produces that reply the same way it produces everything else, by predicting likely text, and training on human feedback rewards answers that sound confident. So its stated confidence is worth considerably less than its measured confidence, and neither is a guarantee.

A confident sentence about something the model never learned looks exactly like a confident sentence about something it did. The difference lives in a distribution you were never shown.

End of course

Test yourself

10 questions, and 70 percent passes. The score stays in this browser and goes nowhere else, so there is no account to make and nothing at stake in getting one wrong.

  1. 01What comes out of the model on a single pass?
  2. 02Why do models struggle to count the letters in a word?
  3. 03A token's embedding vector is best described as:
  4. 04Turning temperature down changes:
  5. 05A model keeps giving different answers to a question with one right answer. What is worth reaching for first?
  6. 06Between two separate conversations, a plain model:
  7. 07A long conversation stops fitting in the context window. Who decides what gets dropped?
  8. 08The model gives its chosen token a high probability. That tells you:
  9. 09Two answers, one about a famous building and one about an obscure one, both read fluently. Why?
  10. 10The most reliable way to get an answer you can check is:
0 of 10 answered
Next in this track

Attention, and how a model decides what matters

Course one treated the model as a box that turns text into a distribution. This one opens the box. What a layer does, why every token gets to look at every other token, and how a pronoun four hundred words later still lands on the right name. It is also where the costs come from, so it explains why context windows are expensive rather than just large.

In production. The track page has the full plan.