All courses

Behavior is learned, not programmed

No one writes rules into an LLM. Its knowledge and habits come from the training objective, the data and post-training, and are stored implicitly across the weights. Examples placed in a prompt can change its behavior with no weight change at all (in-context learning). Its characteristic failures, such as confident errors, flattery and odd blind spots, trace back to these same mechanisms. Interpretability research looks inside the activations, where concepts often turn out to be directions in the vector space.

▶ Watch this lesson Start the whole course

What the animation says

Nobody wrote the rules

No engineer wrote a rule saying be polite, or that Paris is the capital of France. Yet the model does both. It also invents citations, and agrees with users who are wrong. What it does have is one fixed function with billions of adjustable numbers, called weights. Training nudges those numbers, step by step, so its predictions of the next piece of text get better. So where does a fact like Paris live inside it?

Pressure from the objective

It's spread out, and it's there because it helped the training goal. In pretraining, that goal is predicting each actual next word. If the next word really is Paris and the model gave it ninety percent, the penalty is small: about a tenth. At one percent, the penalty jumps to about four point six. Training shrinks this, averaged over the whole corpus. Then post-training nudges the weights toward answers people rated well. Suppose raters tend to like answers that agree with them. What gets pushed in?

A confident error

Agreement gets reinforced, so the model flatters. Pretraining causes a failure of its own. Prompt: Dr. Lee was born in. The training data never states Dr. Lee's birth year. Real documents almost always follow such text with a year, so the model puts ninety percent on: a year comes next. It spreads that over about twenty plausible years, roughly four and a half percent each. Sampling picks one, nineteen sixty-two, and prints it fluently. The sentence shows no doubt. Tap the number that shows how sure the model was about nineteen sixty-two.

Same weights, new input

The output looks like documents, and documents rarely say unknown. That's the pressure behind confident errors. A third source of behavior changes no weights at all. Here the prompt holds two examples: sea otter, loutre de mer; cheese, fromage. Then: house. The model answers maison. The weights are exactly what they were a second ago. Only the input changed, so the internal vectors it computes, the activations, changed. That's in-context learning.

A concept is a direction

Look inside at those activations, and concepts often show up as directions. This simulation hides a French direction in fake activations: French examples get pushed three units along it. Average the French activations, subtract the English average, and the estimate matches the hidden direction: about point nine four. To score a new input, project it onto that direction. French lands near two point eight, English near zero, give or take one. Two new inputs just arrived. Tap the one the model reads as French.

Remember this

So nobody programmed the behavior. The objective, the data and post-training pushed it into the weights. Prompts steer the model without touching those weights. Failures come from the same pressures: fluent text hides uncertainty, and rewarded agreement becomes flattery. And inside, concepts often appear as directions in activation space.

Who decided how the model behaves?

No engineer wrote a rule saying "answer politely" or "Paris is the capital of France." Yet an LLM does both. It also invents citations with total confidence and agrees with users who are wrong. If nobody programmed any of this, **where does the behavior come from?** Can we predict its strengths and its failures from that source? And when we look inside, what do we find?

Billions of numbers, shaped by pressure

An LLM is one fixed function with billions of adjustable numbers, the **weights**. Training nudges them, step by step, so the model gets better at predicting the next piece of text across a huge corpus. **Post-training** then nudges them toward responses people rated well. No fact or habit sits in a single slot. Each one is smeared across many weights. It is there because it helped the objective, or as a side effect of what did, and that includes the failures.

The three sources of behavior

Pretraining picks $\theta$ (all weights) to minimize, averaged over the corpus, $$\mathcal{L}(\theta)=-\frac{1}{T-1}\sum_{t=1}^{T-1}\log p_\theta(x_{t+1}\mid x_{\le t})$$ This is the average negative log-probability of each actual next token $x_{t+1}$, given the tokens up to $t$. Post-training then shifts $\theta$ toward responses $y$ with high reward $r(x,y)$ for prompt $x$. If raters tend to prefer agreeable answers, agreement gets reinforced too. **In-context learning** changes only the input: the same $\theta$ is applied to a prompt that contains examples.

Tracing a confident error

Prompt: "Dr. Lee was born in". The data never states Dr. Lee's birth year. 1. Real documents nearly always follow such text with a year, so the model puts total probability 0.9 on "a year comes next." 2. It spreads that over about 20 plausible years, roughly 0.9/20 = 0.045 each. 3. Sampling picks one, say 1962, and prints it fluently. Inside, the model was very unsure: 0.045 on 1962. The printed sentence shows none of that doubt. The objective rewards text that *looks like* documents, and documents rarely say "unknown."

A concept as a direction

**Activations** are the internal vectors the model computes for its input. This simulation hides a "French" direction $u$ in fake activations. Subtracting the average activation on English text from the average on French text recovers $u$. Projecting onto the estimated direction (taking a dot product with it) then scores a new input. French scores about 2.8 and English about 0, each give or take about 1. Interpretability research finds many real concepts that behave this way.
import numpy as np
rng = np.random.default_rng(0)
d = 64
u = rng.normal(size=d); u /= np.linalg.norm(u)  # hidden concept direction
noise = lambda n: rng.normal(size=(n, d))
fr = noise(100) + 3 * u   # activations on French text
en = noise(100)           # activations on English text
est = fr.mean(0) - en.mean(0); est /= np.linalg.norm(est)
print(round(est @ u, 2))  # ~0.94: direction recovered
new_fr, new_en = noise(1)[0] + 3 * u, noise(1)[0]
print(round(new_fr @ est, 1), round(new_en @ est, 1))  # ~2.8 vs ~0, each +/- about 1

Remember this

An LLM's knowledge and habits are whatever the objective, the data and post-training pushed into its weights, stored implicitly rather than as rules. Prompts can steer it with no weight change (in-context learning). Its failures come from the same pressures. Confident errors arise because fluent text hides the model's uncertainty. Flattery arises because agreement was rewarded. Inside, concepts often show up as directions in activation space.

On Bytewise this lesson comes in small steps with a check at the end, and the app brings it back right before you would forget it.