Inside an LLM

Week 2 · Wednesday 30 September 2026 · 10:00–13:00

Niccolò Salvini, PhD

AI for Business and FinTech · European School of Economics, Florence

Today

10:00 last week · your homework
10:20 the question changes: from “fraud?” to “which word next?”
10:40 open the box: the architecture of a GPT · tokens · vectors
11:05 break
11:15 attention · neurons · the knobs
12:00 where the 117 billion numbers live — and what they cost
12:15 how the numbers get their values: three stages of training
12:40 who owns it · what it cannot do · the release, decoded

Last week, in one slide

The question: is payment E (large, abroad, same device) fraud? Nobody writes the rule — the machine learns it from eight past payments.

step in words on payment E
1 · guess a neuron weighs each red flag, adds them up, and squashes the total into a probability 0.5 × large + 1 × abroad − 1 → p(fraud) = 0.62
2 · how wrong the loss: one number, small when the right answer got a high probability it was fraud; 0.62 is not sure enough
3 · blame each weight gets its share of the mistake; in a bigger network, backpropagation passes the blame back, layer by layer “large” and “abroad” were on: blamed · “device” was off: not blamed
4 · nudge new weight = old weight − learning rate × blame 0.5 → 0.88 · 1 → 1.38 → p = 0.84
repeat every payment, many rounds average loss 0.45 → 0.03

Last week, in your notebook

LAB · session.ipynb § 0

  1. Run the first cell: the four steps on payment E. Find 0.62 and 0.84.
  2. Run the second: all eight payments, 200 rounds. Watch the loss fall to 0.03.

Your homework

The question you want answered by December — in two minutes, as if to a manager. Then the three pitch sentences: which is impossible, and what did you ask the vendor?

Back to the release

“Each model is a Transformer which leverages mixture-of-experts to reduce the number of active parameters needed to process input. gpt-oss-120b activates 5.1B parameters per token … The models have 117b and 21b total parameters …

We tokenized the data using … o200k_harmony … The models were post-trained … including a supervised fine-tuning stage and a high-compute RL stage. … The weights … are freely available … and come natively quantized in MXFP4. This allows for the gpt-oss-120B model to run within 80GB of memory … Available under the flexible Apache 2.0 license.”

Spec table: context length 128k.

Last week we named every bold word. Today we build the machine they describe — a network from last week, plus one new idea — and each word will find its place in it.

Part 1 · an LLM is last week’s network The question changes

An LLM is the same machine

A real model’s knobs

Bet

After “The ECB left rates”, how sure is a real model that the next word is “unchanged”?

Writing is picking, again and again

Part 2 · “Transformer” Open the box

A sentence, through a GPT

The map for the rest of the morning

Five boxes. The neurons you know from last week; attention is the one new idea. Each box is a word of the release.

The real thing: GPT-2, every layer

① Tokens

The text is cut into pieces, and each piece becomes a number. The model never sees a word.

How a tokenizer is built

The recipe, in four lines

  1. Start from single letters.
  2. Count which pair of neighbours appears most often.
  3. Glue it into one new piece; add it to the vocabulary.
  4. Repeat — until the vocabulary has the size you want: about 200,000 pieces for gpt-oss.

Frequent words end up as one piece; rare ones stay in fragments. The text it learned from was mostly English — so Russian is cut finer: the same sentence costs 9 tokens in English, 13 in Russian. You pay per token. Your own texts: session.ipynb § 1.

② Vectors

Each token becomes a list of numbers — 768 in GPT-2. Read them as coordinates: a place on a map of meaning.

How the map is built

The recipe

  1. Every word starts at a random place.
  2. Guess which words appear near it; see how wrong; nudge its place — last week’s loop.
  3. Repeat on the whole text.

Words that keep the same company end up close. That list of numbers — its place — is the word’s embedding. Nobody draws the map; the text does.

A real map: GPT-2’s own

Each token becomes a list of numbers — 768 in GPT-2 — learned by the same nudge as every other weight.

Step ② for real

One place per word is not enough

“The bank raised rates.” · “The river flooded the bank.”

On the map, “bank” has one place — in between money and rivers, right for neither sentence. A word’s meaning depends on its neighbours: the places must be allowed to move once the model sees the sentence. That is the next box.

Break — ten minutes.

③ Attention

Every vector looks at the others and moves towards the ones that matter to it. The one new idea since last week.

The context moves the word

Step ③ for real

The clip’s three steps, with GPT-2’s own numbers: a score for each earlier token, shares of 100%, add the mix to the vector.

Your turn: where does “it” go?

Bet

“The bank raised rates because it …” — “it” has no meaning of its own. Which neighbour will it move towards, and with what share?

“It”, slowly

The same three steps: bank 70%, rates 16%. The numbers by hand: session.ipynb § 2.

And inside a real model

Vaswani et al., Attention Is All You Need, 2017 — the paper behind every model since.

④ Neurons

After attention, each token goes through an ordinary network — last week’s, on its own. Most of the 117 billion numbers live here.

What the neurons add: questions nobody wrote

In an LLM the neurons invent questions too — about grammar, meaning, facts.

One block, stacked

Attention moves information between tokens; the neurons transform it, token by token — and hold much of what the model knows. Stack the block 36 times: that is a Transformer.

Step ④ for real

What the stack adds

Block by block the guess sharpens: “rate”, then “fluct” (the start of fluctuate), then “unchanged” at 92% after block 9. The last blocks spread it back to 37%.

⑤ The knobs

The last token’s vector becomes a score for every possible next piece. Pick one, append it, run the whole stack again.

Step ⑤ for real

How boldly it picks: temperature

Temperature divides every score before the softmax. On GPT-2’s real knobs, after “The ECB left rates”:

next token T = 0.5 T = 1 T = 2
unchanged 83.9% 37.1% 2.4%
at 10.2% 13.0% 1.4%
low 2.7% 6.7% 1.0%
in 1.0% 4.1% 0.8%
on 0.8% 3.5% 0.7%

At T = 2 the 50,257 tokens are spread so flat that “unchanged” drops to 2%. T = 0 always picks the top token. APIs add one more dial, top-p: draw only among the top tokens that together make p (say 90%) — the long tail is cut off.

One token at a time

T = 0 (always the top knob): The ECB left rates unchanged at 0.5 percent in June, but the ECB

T = 1, three runs:

  • The ECB left rates up to 32 per cent in London unchanged at 20 basis points
  • The ECB left rates unchanged last week down between 8 and 12 basis points. This
  • The ECB left rates at its previous entry level in 2005. Close to a three

Each word is picked, appended, and the whole machine runs again. Nothing is looked up: “0.5 percent in June” is a number that fits, not a fact.

Look inside a real one

LAB · session.ipynb § 2–4

  1. Attention by hand, in numpy — the table you just saw.
  2. Load GPT-2 in Colab. Your own prompt: read its top eight knobs.
  3. Generate at T = 0, then three times at T = 1. Which sentences are facts?

Part 3 · “117b”, “MoE”, “5.1B active”, “quantized” Where the 117 billion numbers live

From GPT-2 to gpt-oss: what changed

From 4 numbers to 117 billion

Big, but cheap to run

Fitting it on one machine

each of 117 billion weights stored in memory needed
16 bits (2 bytes) ≈ 234 GB — several GPUs
~4 bits (MXFP4) ≈ 62 GB — one 80 GB GPU

Quantization: store each number with less precision. How, and what it costs — for real, on GPT-2.

Quantization, by hand

Does it still work?

Part 4 · “post-trained”, “SFT”, “RL” How the numbers get their values

How every network learns

The learning rate

Add payment I — a customer on holiday: large, abroad, genuine — and no rule is perfect. Too small a step crawls; too large jumps over the best answer.

Training turns counts into knobs

Five sentences in the training text, all ending “… left rates”, then:

next word times in the text share the knob, after 40 passes
unchanged 3 of 5 60% 61%
at 1 of 5 20% 21%
steady 1 of 5 20% 17%
higher, lower never 0% 1%

Nobody set the knobs: the loop nudged them until they matched how often each word follows this context. On trillions of tokens, that is pre-training.

Pre-training is compressing the internet

Stage 1 · Pre-training: read, guess, nudge

The loop: take a piece of text, hide the next token, guess, nudge every weight. Repeat.

The data: “a text-only dataset with trillions of tokens, with a focus on STEM, coding, and general knowledge. Knowledge cutoff: June 2024.”

The bill: 2.1 million H100-hours — about a thousand top GPUs for three months.

Bet

What comes out is a base model. Ask it “Should I buy Bitcoin today?” What does it write?

Quotes and numbers: the gpt-oss model card, OpenAI, August 2025.

Same model, before and after post-training

Try it yourself, both models: session.ipynb § 4.

Stage 2 · Supervised fine-tuning: imitate good conversations

People write tens of thousands of example conversations:

User: Summarise this contract in three points. Assistant: 1. … 2. … 3. …

The same loop again — now the “next token” to guess is the ideal assistant’s reply.

What it learns: the format, the tone, when to refuse. A persona.

What it does not learn: new facts. The knowledge is still the compressed internet from stage 1.

When you talk to an assistant, you talk to a statistical imitation of the people who wrote those examples.

Stage 3 · Reinforcement learning: try, score, reinforce

Problems with a checkable answer — maths, code, logic. The model tries each one many times; the attempts that reach the right answer are nudged up.

Nobody writes the steps. The model discovers that writing its reasoning out first gets more answers right.

Where no answer can be checked — tone, helpfulness — a second model, trained on human preferences (“A or B?”), gives the score.

“A high-compute RL stage” = they spent heavily here. That is what “reasoning model” means.

For you: the “thinking” is tokens. You wait for them, and you pay for them.

Three stages, the same loop

stage the “right answer” in the loop what comes out
pre-training the next token of internet text a base model: it continues documents
supervised fine-tuning the next token of good example conversations an assistant
reinforcement learning whatever earns a higher reward score an assistant that works problems through — “reasoning”

The formula never changes: w \leftarrow w - \eta \cdot blame. Only what counts as right does.

Part 5 · “128k”, “Apache 2.0” Running it, and owning it

The box has a size, and a price

Every token attends to every other: twice the context, four times the attention work. That is why long prompts cost more than they look.

Reading is fast, writing is slow

Open weights, Apache 2.0: who owns it

a closed model, through an API an open-weight model (gpt-oss)
you get an answer per call the 117 billion numbers themselves
you pay per token, forever the hardware to run it
your data goes to the vendor stays on your machine
it changes when the vendor decides never, unless you change it

Apache 2.0: you may use it commercially, modify it, sell what you build. Open weights is not open source: the training data and code stay private.

Part 6 What it cannot do

Four limits that follow from the machine

what you see why, from what we built
a confident, invented number there is always a top knob — even when the fact was never in the data
no knowledge after a date the weights are frozen at the end of training
knows A → B, not B → A it learned to continue text in one direction
bad at spelling and arithmetic it sees tokens, not letters or digits

Every one of these is why, from week 4, we give it documents to read and tools to call.

Two piles

LAB · session.ipynb § 5

Ask your assistant about a real company. Split every sentence:

Verifiable — a number, a date, a name, a source you can open

Plausible — fluent, confident, and nothing to check it against

Then check two from the left pile against the company’s own report.

The release, decoded

“Each model is a Transformer which leverages mixture-of-experts to reduce the number of active parameters needed to process input. gpt-oss-120b activates 5.1B parameters per token … The models have 117b and 21b total parameters …

We tokenized the data using … o200k_harmony … The models were post-trained … including a supervised fine-tuning stage and a high-compute RL stage. … The weights … are freely available … and come natively quantized in MXFP4. This allows for the gpt-oss-120B model to run within 80GB of memory … Available under the flexible Apache 2.0 license.”

Spec table: context length 128k.

Circle again. Which words are still dark?

Close

Homework 2, due Tue 6 Oct, in your Drive folder week-02/:

  • GPT-2 on three prompts of yours: the knobs, and four generations
  • your tokenizer on English and Russian
  • another model release, decoded word by word
  • a first look at next week’s data: 284,807 real card payments

Before you leave: three lines at the bottom of the notebook, in your words.

Next week: real fraud data, from the raw file to a model — and whether the model is any good.