4.4.9 · HinglishAlignment, Prompting & RAG

In-context learning mechanisms

1,754 words8 min readRead in English

4.4.9 · AI-ML › Alignment, Prompting & RAG


In-context learning KIYA hai?

YEH EXIST KYUN KARTA HAI? Pretraining ke dauran model itna zyada text dekhta hai jahan document mein pehle establish hua pattern baad ke tokens ko predict karta hai (lists, tables, translations, Q&A threads). Next-token loss minimize karne ke liye usse majburan "context mein pattern dhundho, phir use continue karo" mein achha banna padta hai. ICL wahi skill hai jo inference time pe reuse hoti hai.


YEH KAAM KAISE KARTA HAI? Do mechanistic stories

Dono stories compatible hain: model ke andar already algorithm hai; context use select aur steer karta hai.

Figure — In-context learning mechanisms

Derivation: zyada demos kyun madad karte hain (Bayesian task inference)


Toy mechanism: attention as one gradient step


Worked examples


Common mistakes


Recall Feynman: ek 12-saal ke bachhe ko explain karo

Socho ek bahut smart tota hai jisne poora internet padha hai. Tum usse dobara train nahi karte. Bas pehle kuch examples dikhate ho: "cat→animal, rose→plant, dog→?" Kyunki usne pehle lakho chhote lists aise dekhe hain, woh samajh jaata hai ki tum konsa game khel rahe ho aur pattern complete karta hai: "animal". Usne koi test ke liye padhaa nahi — usne bas woh rule notice kiya jo tum usके saamne hint kar rahe the. Yahi noticing-and-continuing in-context learning hai.


Active recall

In-context learning kya hai?
Ek frozen LLM jo prompt mein demonstrations pe condition karke ek naya task perform karta hai, bina kisi weight update ke; "learning" forward pass mein hoti hai.
ICL mein model ke parameters mein kya badlta hai?
Kuch nahi — fixed rehta hai; sirf transient activations context pe depend karti hain.
k-shot ICL objective state karo.
.
Bayesian view: demonstrations kya karte hain?
Woh latent tasks ke upar posterior shift karte hain, use true task pe concentrate karte hue.
Zyada shots ke saath accuracy saturate kyun hoti hai?
Log-posterior-ratio badhta hai, isliye exponentially; extra demos diminishing returns dete hain.
Ek GD step linear attention ke barabar kyun hai?
se GD deta hai , same form jaise attention with keys , values , query .
Flipped labels ke baad bhi ICL accuracy achhi kyun ho sakti hai?
Demos mainly input distribution, label space, aur format convey karte hain (task location); pretraining priors mapping supply karti hai — jab tak task novel/hard na ho.
Zero-shot vs one-shot vs few-shot?
k=0,1,kai demonstrations respectively.
Do biases jo batate hain ki ICL conditioning hai clean learning nahi?
Recency bias (baad ke demos zyada weighted) aur majority-label bias.
ICL vs fine-tuning ek line mein?
Fine-tuning permanently weights edit karta hai; ICL per-prompt, reversible conditioning hai.

Connections

  • Transformers and Attention — attention woh substrate hai jo ICL implement karta hai.
  • Prompt Engineering — demo count, order, aur format ICL ke levers hain.
  • Chain-of-Thought Prompting — ICL extended with reasoning steps in the demos.
  • Retrieval-Augmented Generation (RAG) — retrieved passages context ki tarah act karte hain jo same conditioning mechanism ko steer karta hai.
  • Bayesian Inference — task-posterior derivation.
  • Gradient Descent — implicit-optimization interpretation.
  • Fine-tuning vs Prompting — kab weights change karein vs context se steer karein.

Concept Map

forces skill

requires

conditions on

defines

explained by

explained by

demos shift

update evidence

forward pass runs

concentrates with k

steers task

Pretraining on pattern-rich text

In-context learning ICL

Frozen weights theta fixed

k demonstrations plus query

k-shot zero one shot

Story 1 task location Bayesian

Story 2 implicit optimization

Posterior over latent task

Attention as gradient descent

Better predictions