4.4.6 · AI-ML › Alignment, Prompting & RAG
Intuition Ek-line intuition
Ek large language model ek next-token predictor hai jo bahut saari text pe train hua hai. Jab aap ise prompt karte ho, tum ise naye weights "sikhaa" nahi rahe — tum apne diye hue words pe iske probability distribution ko condition kar rahe ho . Zero-shot = "bas poochho." Few-shot = "pehle kuch examples dikhaao taaki model context se pattern infer kar sake." Examples model ko nahi badlaate; woh badlaate hain ki model ko kya most likely continuation lagti hai.
Definition Zero-shot prompting
Model ko ek task dena sirf natural language mein describe karke, bina kisi worked example ke , aur sahi jawab ki ummeed rakhna.
Example prompt: "Is review ka sentiment positive ya negative classify karo: 'The plot dragged.'"
Definition Few-shot prompting
Real query se pehle k input→output demonstrations (the "shots") prompt mein prepend karna, taaki model in-context learning kare — examples ke pattern se task infer kare.
k = 1 hai "one-shot", k > 1 hai "few-shot", k = 0 hai "zero-shot".
Definition In-context learning (ICL)
Model ki woh ability ki woh prompt mein diye examples se task perform kare inference time pe, bina kisi gradient update / weight change ke . Learning forward pass ke andar simulate hoti hai.
Ek autoregressive LM saare pehle tokens diye jaane par next token ka distribution define karta hai:
P θ ( x t ∣ x 1 , x 2 , … , x t − 1 )
Full sequence probability, chain rule of probability se factorize hoti hai:
P θ ( x 1 : T ) = ∏ t = 1 T P θ ( x t ∣ x < t )
Yeh kyun matter karta hai: jo bhi aap type karte ho woh x < t ka hissa ban jaata hai. Toh model jo answer generate karta hai woh hai:
answer = arg max y P θ ( y ∣ tumhare shots demos , tumhara sawaal query )
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 D = {( x i , y i ) } i = 1 k conditional ko sharpen karte hain . Woh model ko batate hain (a) output format , (b) label space , (c) style/granularity . Toh P θ ( y ∣ D , x ) sahi tarah ke answer pe concentrate ho jaati hai.
Intuition Examples "task select" kyun karte hain, "task teach" kyun nahi
Ek giant pretrained model waise hai jaise koi aisa insaan jo sab kuch padh chuka ho lekin abhi nahi jaanta tu kaunsa game khel raha hai . Zero-shot unhe rules words mein batana hai. Few-shot do demo rounds khelna hai taaki woh game pe lock ho jayein. Woh player pehle se hi kar sakta tha — tum bas disambiguate kar rahe ho.
<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.
Worked example Example 1 — Sentiment (zero-shot vs few-shot)
Zero-shot:
"Sentiment (positive/negative): 'The battery dies fast.' →"
Risk: model reply kar sakta hai "The battery life is poor." (galat format , sahi idea).
Few-shot fix:
Review: "Amazing camera!" Sentiment: positive
Review: "Screen cracked day one." Sentiment: negative
Review: "The battery dies fast." Sentiment:
Model output karta hai negative.
Yeh step kyun? Do demos exact label set {positive, negative} aur ek-word output shape define karte hain, toh distribution ek single token class pe collapse ho jaati hai.
Worked example Example 2 — Format control (structured extraction)
Task: name + age ko JSON ke roop mein extract karo.
Text: "Ravi is 30." -> {"name":"Ravi","age":30}
Text: "Meera is 22." -> {"name":"Meera","age":22}
Text: "Sam is 45." ->
Yeh step kyun? Zero-shot prose return kar sakta hai. Demos schema sikhate hain (age ek int hai, "30 years" nahi), jo sirf instruction se reliably enforce nahi hota.
Worked example Example 3 — Few-shot, zero-shot se zyaada kab jeetta hai
Ek niche label jaise neutral-but-sarcastic. Zero-shot mein model ko pata hi nahi hota ki yeh label exist karta hai. Ek demo jo isse dikhata hai turant ambiguity hata deta hai.
Yeh step kyun? Demo ek novel label define karta hai jo pretraining ne kabhi name nahi kiya — pure disambiguation.
Intuition Woh 20% jo 80% value deta hai
Examples tab hi add karo jab zero-shot fail ho (format galat, rare label, ambiguous task).
Demos representative aur balanced banao labels ke across.
Output format identical rakho sabhi shots mein.
Baaki sab (fancy phrasing, bada k ) diminishing returns deta hai aur tokens ki cost badhata hai.
Zyaada shots ⇒ zyaada tokens ⇒ zyaada cost + context window limit hit hone ka risk.
Chhote k se aage, accuracy usually plateau kar jaati hai (diminishing returns).
Common mistake "Few-shot model ko fine-tune / train karta hai."
Kyun sahi lagta hai: ise in-context learning kehte hain, aur model improve bhi karta hai. Fix: koi weights nahi badalte; request ke baad kuch persist nahi hota. Naya chat shuru karo aur "learning" chali gayi. Yeh conditioning hai, training nahi.
Common mistake "Zyaada examples hamesha = better."
Kyun sahi lagta hai: ML mein zyaada data usually help karta hai. Fix: irrelevant, redundant, ya label-imbalanced demos model ko bias kar sakte hain (woh majority label copy karta hai). Quality, coverage, aur balance quantity se zyaada important hain.
Common mistake "Example labels sloppy ho sakte hain; model sirf inputs padhta hai."
Kyun sahi lagta hai: instruction task carry karti lagti hai. Fix: demos ka format aur label distribution output ko strongly steer karta hai; galat ya inconsistent labels results degrade karte hain chahe inputs theek hon.
Common mistake "Zero-shot sirf ek kamzor few-shot hai."
Kyun sahi lagta hai: few-shot often zyaada score karta hai. Fix: common tasks ke liye clear instructions ke saath, zero-shot sasta hai, demo-bias se bachata hai, aur often equally achha hota hai — wahaan se shuru karo.
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 P ( x 1 : T ) = ∏ t P ( x t ∣ x < t ) .
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.
"SHOW, don't RETRAIN."
S hots H int karte hain O utput ka W anted-format. Aur 0-shot = T ell, few-shot = S how (T→S jaise tasks tricky hoti jaati hain).
Demos specify format and label space
Instruction plus consistent delimiters