4.4.6 · HinglishAlignment, Prompting & RAG

Zero-shot and few-shot prompting

1,561 words7 min readRead in English

4.4.6 · AI-ML › Alignment, Prompting & RAG


YEH CHEEZEIN HAIN KYA?


FEW-SHOT EXAMPLES PE CONDITIONING KYUN HELP KARTA HAI? (first principles se)

Ek autoregressive LM saare pehle tokens diye jaane par next token ka distribution define karta hai:

Full sequence probability, chain rule of probability se factorize hoti hai:

Yeh kyun matter karta hai: jo bhi aap type karte ho woh ka hissa ban jaata hai. Toh model jo answer generate karta hai woh hai:

  • Zero-shot: "demos" empty hote hain. Model ko puri tarah pretraining mein dekhe gaye task-descriptions pe rely karna padta hai. Tab kaam karta hai jab task training data mein common ho.
  • Few-shot: demos conditional ko sharpen karte hain. Woh model ko batate hain (a) output format, (b) label space, (c) style/granularity. Toh sahi tarah ke answer pe concentrate ho jaati hai.

FEW-SHOT PROMPT KAISE BANAYEIN (recipe)

<Task instruction>

Input: <example 1 input>
Output: <example 1 label>

Input: <example 2 input>
Output: <example 2 label>

Input: <REAL query>
Output:

Har part kyun?

  • Instruction: examples se pehle hi task ko pin karta hai (generalization mein help karta hai).
  • Consistent delimiters ("Input:/Output:"): model format copy karta hai → predictable, parseable outputs.
  • Trailing "Output:": model ke agale tokens ko answer banata hai, chit-chat nahi.
Figure — Zero-shot and few-shot prompting

Worked examples


Trade-offs (the 80/20 core)

  • Zyaada shots ⇒ zyaada tokens ⇒ zyaada cost + context window limit hit hone ka risk.
  • Chhote se aage, accuracy usually plateau kar jaati hai (diminishing returns).

Common mistakes (steel-manned)


Flashcards

Zero-shot prompting kya hai
sirf instruction se task dena, bina kisi worked example ke.
Few-shot prompting kya hai
k input→output demonstrations prepend karna taaki model context se task infer kare.
Prompt examples se weight updates ke bina seekhne ka naam
in-context learning (ICL).
Kya few-shot examples model ke weights change karte hain?
Nahi — woh sirf forward-pass probability distribution ko condition karte hain.
LM jo chain-rule factorization use karta hai
.
Few-shot content se aage kyun help karta hai
yeh output format, label space, aur style fix karta hai.
One-shot ka matlab
exactly k=1 demonstration.
Bahut saare shots add karne ki sabse badi cost
zyaada tokens → zyaada cost aur context-window pressure.
Demo formats identical kyun rakhen
model pattern copy karta hai, parseable, consistent outputs deta hai.
Imbalance se ek demo-set failure mode
model majority label ki taraf bias ho jaata hai.
Zero-shot kab preferable hai
common task + clear instruction; sasta, koi demo bias nahi.
Prompt mein trailing "Output:" kya karta hai
agale tokens ko answer banata hai, commentary nahi.

Recall Feynman: 12-saal ke bachche ko samjhao

Socho ek bahut smart dost hai jisne har book padhi hai lekin thoda absent-minded hai. Agar tum bas chillaao "sort karo!" toh woh size ki jagah color se sort kar sakta hai. Yeh hai zero-shot — tumne sirf words mein bataya. Agar tum pehle dikhao: "🍎 small, 🍉 big" ek do baar, toh woh turant samajh jaata hai ki kaunsi tarah ki sorting tum chahte ho. Yeh hai few-shot — examples dikhana. Dost ka dimaag zyaada smart nahi hua; tumne bas unhe figure out karne mein help ki ki kaunsa game abhi chal raha hai. Jab chat khatam ho, woh game bhool jaate hain — kuch permanently nahi seekha.


Connections

Concept Map

is a

factorizes via

becomes part of

conditions

argmax gives

empty demos

k demos prepended

enables

no weight change

sharpens conditional

disambiguate task

builds

Autoregressive LM

Next-token predictor

Chain rule product

Prompt

Prior context x_less_t

Probability distribution

Answer

Zero-shot

Few-shot

In-context learning

Demos specify format and label space

Instruction plus consistent delimiters