4.4.9 · D1Alignment, Prompting & RAG

Foundations — In-context learning mechanisms

3,046 words14 min readBack to topic

This page assumes you have seen nothing. We define every letter, arrow, and squiggle the parent note (In-context learning mechanisms) throws at you, in an order where each one only uses things already built.


1. What is a "probability" ?

Figure — In-context learning mechanisms
Figure s01 — a length-1 bar cut into coloured slices (Negative 0.55, Positive 0.30, Neutral 0.15); the width of each slice is its probability and the slices exactly fill the bar. Refer to this bar every time the word "probability" appears below.

Why the topic needs it. An LLM never says "the answer IS Negative." It says "Negative fills 0.8 of the bar, Positive fills 0.2." Every formula in the parent note is really about widths of that bar.


2. Conditional probability — the bar

The vertical stroke is read "given". It is the single most important symbol on the parent page.

Figure — In-context learning mechanisms
Figure s02 — left: the full bar over four outcomes A,B,C,D; right: after we are "given ", only the lit outcomes B and C survive and their widths are re-measured so they again fill length 1 (each becomes 0.5). This is the picture behind the division in the formula below.

Why the topic needs it. The whole model is a conditional-probability machine: = "how likely is the next chunk , given everything typed so far." The demonstrations just make the "given" part longer. (The capital here is explained in the very next section.)


3. The subscript — "the model's settings", and why is capital


4. , , and pairs — inputs, outputs, demonstrations

Why the topic needs it. These pairs are the raw material. In §7 we will count how many of them we have, and in §8 use the "widest bar" idea to pick an answer — but first we need those two ideas as their own symbols. For now just remember: a prompt is some demonstrations, then one query with a missing back.


5. and "-shot"


6. — "which choice wins?"

The hat in means "the model's guess for ", to distinguish it from the true answer.


7. Sum and product


8. Latent task / concept


9. Prior , posterior , and Bayes' rule

Why the topic needs it. The parent's key claim — "accuracy climbs then saturates" — is literally "the posterior bar collapses onto one rulebook and can't get any narrower." See Retrieval-Augmented Generation (RAG) for a different way of feeding evidence — by fetching text instead of squeezing a prior.


10. KL divergence


11. Vectors, dot products , and

The "attention ≈ one gradient step" section needs three tiny linear-algebra pieces. To avoid a clash with the discrete label from §6, this section writes the vector output of a linear map as ("output vector").

Figure — In-context learning mechanisms
Figure s03 — an amber "query" arrow and three "key" arrows: one aligned (dot product > 0), one perpendicular (dot ≈ 0), one opposite (dot < 0). The dot product number beside each key is the "similarity meter" reading attention uses to weight that key.


12. Gradient and step size


Prerequisite map

Probability p

Conditional p of y given x

Model P subscript theta

Bayes rule for task c

Inputs x and outputs y

Demonstrations x i y i

k-shot count

In-context learning

arg max picks widest bar

Sum and Product

Latent task c

Marginalize over tasks

KL divergence

Vectors and dot product

Attention as one GD step

Gradient and step size eta

Also connects to the deeper mechanisms in Prompt Engineering and Chain-of-Thought Prompting, which extend the same conditioning idea.


Equipment checklist

I can say in words what the vertical bar in means.
"The probability of given that is already known"; we restrict to outcomes agreeing with and re-measure widths to sum to .
I can write the formal relation for conditional probability.
— joint over marginal; dividing by re-normalises the lit region to length .
I can explain the difference between lowercase and capital .
is the true/idealised probability in the world; is the model's own estimate computed from its weights — same kind of object, but an approximation.
I know what is and whether ICL changes it.
is the full list of the model's weights (the sliders); ICL leaves it frozen — only the input text changes.
I can read out loud.
"The choice of that makes biggest" — it returns the argument (widest bar), not the value.
I can expand and .
(add) and (multiply).
I can write the likelihood of the whole demo bag under a task .
under the assumption demos are independent given .
I can state Bayes' rule for the task posterior.
with .
I can write the marginalization used to answer the query.
— average each task's answer by its posterior weight.
I can write the KL formula and say why it is .
; requires wherever ; non-negative by concavity of (Jensen), zero iff .
I can explain what a dot product measures.
How aligned two vectors are: large positive = same direction, = perpendicular.
I know what a gradient and step size do.
Gradient points uphill on the loss landscape; step walks downhill by amount .