Course Content
Mastering Zero-Shot & Few-Shot Prompting in LLMs

📘 In-context Learning – Core Mechanism


🔰 परिचय

Traditional machine learning में किसी नए टास्क को सीखने के लिए मॉडल को फिर से फाइन-ट्यून करना पड़ता था।
लेकिन Large Language Models (LLMs), विशेषतः GPT जैसे transformer-based मॉडल्स, यह काम कर सकते हैं In-context Learning (ICL) के माध्यम से — यानी बिना weights बदले, केवल contextual उदाहरणों से।

इस अध्याय में हम समझेंगे:

  • In-context learning क्या है?

  • यह कैसे काम करता है?

  • इसके real-world उपयोग

  • Zero-shot और Few-shot prompting से इसका संबंध


💡 In-context Learning क्या है?

In-context Learning (ICL) वह प्रक्रिया है जिसमें एक LLM बिना दोबारा training किए, केवल दिए गए prompt (context) से नया कार्य करना सीखता है।

उदाहरण:

Prompt:
Translate English to Hindi:
1. Hello → नमस्ते
2. Water → पानी
3. Book → ?

Output:
किताब

👉 मॉडल ने पिछले उदाहरणों से पैटर्न समझा और नया आउटपुट दिया — बिना training weights बदले!


🔁 Traditional Learning vs In-context Learning

विशेषता Traditional Learning In-context Learning
Model Parameters Re-trained होते हैं स्थिर रहते हैं
Data का उपयोग Training Set Prompt Context
Flexibility एक टास्क पर सीमित बहु-टास्क सक्षम
Learning Style Gradient Descent Pattern Matching via Attention

🧪 यह काम कैसे करता है?

LLMs, विशेषकर Transformers, Input Sequence में मौजूद पैटर्न्स पर आधारित predictions करते हैं।
ICL में हम उन्हें उदाहरणों के रूप में वो पैटर्न “प्रदर्शित” करते हैं।

🧠 Core Mechanism:

  • Context (Prompt) = Demonstrations + Instruction

  • Self-Attention → Patterns को पहचानता है

  • Next-token prediction → नए उदाहरण का उत्तर अनुमान करता है


🔍 Key Components of In-context Learning

Component विवरण
Demonstrations उदाहरण जिनसे मॉडल पैटर्न सीखता है
Instructions मॉडल से अपेक्षित कार्य का संकेत
Input Format सही फॉर्मेट बहुत ज़रूरी (e.g., Labelled examples)
Token Limit Context window की सीमा (e.g., 4096 tokens, 8k, 32k+)

📌 Zero-shot, One-shot, Few-shot: ICL के प्रकार

प्रकार उदाहरणों की संख्या विशेषता
Zero-shot 0 सिर्फ निर्देश
One-shot 1 एक उदाहरण
Few-shot 2–5 या अधिक कई उदाहरणों के आधार पर

🎯 उदाहरण:

Zero-shot:
Summarize: The sun rises in the east and sets in the west.
→ "The sun's movement direction."

Few-shot:
1. The dog barked. → Passive: The dog was barked at.
2. She painted the wall. → Passive: The wall was painted by her.
3. He kicked the ball. → Passive: ?
→ The ball was kicked by him.

🧠 क्या मॉडल सचमुच “सीखता” है?

नहीं, ICL में मॉडल parameters नहीं बदलता
यह केवल दिए गए context से पैटर्न पहचानता है और उसी अनुरूप आगे का अनुमान लगाता है।

इसे “Meta-learning via context” भी कहा जाता है।


🛠 In-context Learning के उपयोग

क्षेत्र उपयोग का उदाहरण
Translation Live multi-language conversion
Sentiment Analysis Examples देकर custom classifier बनाना
Math Reasoning Step-by-step solutions generate करना
Information Extraction Structured data निकालना बिना coding
Text-to-SQL Natural language से database queries बनाना

🔎 In-context Learning vs Fine-tuning

पहलू Fine-tuning In-context Learning
Data Size बहुत अधिक कम (Prompt में)
Time & Resources GPU-intensive Instant
Flexibility Task-specific Multi-task
Cost High Low

📉 सीमाएँ (Limitations)

  • Context Window की सीमा (Token Limit)

  • उदाहरणों की गुणवत्ता पर निर्भरता

  • Generalization नहीं सीखता (Overfitting prompt context)

  • हर Task के लिए Reliable नहीं (e.g., Complex reasoning)


🧠 Key Takeaways

  • In-context learning, LLMs की powerful ability है जो उन्हें बिना fine-tuning के भी टास्क करने में सक्षम बनाती है।

  • यह सिर्फ “Attention-based Pattern Matching” है, Learning नहीं।

  • Zero-shot, Few-shot prompting इसी principle पर आधारित हैं।

  • Complex tasks के लिए उच्च-गुणवत्ता वाले उदाहरण आवश्यक हैं।

0% Complete