Chapter 40
প্রম্পট ইঞ্জিনিয়ারিং
Prompt Engineering
🎬 মডেলের সাথে কথা বলার শিল্প
Prompt Engineering = LLM-কে সঠিক context, format ও instruction দিয়ে এমনভাবে গাইড করা যাতে সে আপনার চাওয়া ফল দেয়। সঠিক prompt = ২x ভালো model-এর সমান।
একটি ভালো Prompt-এর ৬ অংশ
- Role: "তুমি একজন senior data scientist..."
- Task: পরিষ্কার করে কী করতে হবে।
- Context: প্রয়োজনীয় background।
- Examples: few-shot demonstration।
- Constraints: length, tone, format।
- Output format: JSON, markdown, bullet...
Zero-shot / Few-shot
# Zero-shot
"Translate to Bengali: 'Deep learning is fascinating.'"
# Few-shot
"""
English: hello → বাংলা: হ্যালো
English: book → বাংলা: বই
English: river → বাংলা:
"""Chain-of-Thought (CoT)
"Let's think step by step" — reasoning task-এ accuracy অনেক বাড়ায়।
Q: একটি দোকানে ১২টি আপেল ছিল, ৫টি বিক্রি, ৭টি যোগ। বাকি কত?
A: চলো ধাপে ধাপে ভাবি।
শুরু = 12
বিক্রি = -5 → 7
যোগ = +7 → 14
উত্তর: 14Self-Consistency
একই prompt কয়েকবার চালিয়ে majority vote — CoT-কে আরও শক্তিশালী করে।
ReAct (Reason + Act)
Thought: আমার current weather দরকার।
Action: search("weather in Dhaka today")
Observation: 32°C, sunny
Thought: এখন উত্তর গঠন করতে পারি।
Answer: ঢাকায় আজ ৩২°C, রৌদ্রোজ্জ্বল।Structured Output
# JSON mode দিয়ে নিশ্চিত structured output
"""
নিচের রিভিউ থেকে JSON বের করো:
{ "sentiment": "positive|neutral|negative",
"topics": [str],
"rating": 1-5 }
Review: "ফোনটার ক্যামেরা চমৎকার কিন্তু battery খারাপ।"
"""Advanced Patterns
- Role + Persona: "তুমি একজন কঠোর কোড reviewer..."
- Delimiters: ###, """ দিয়ে section আলাদা।
- Decomposition: বড় task ছোট subtask-এ ভাগ।
- Self-criticism: "এই উত্তর review করে উন্নত কর।"
- Tree-of-Thoughts: একাধিক reasoning branch explore।
Anti-patterns — যা এড়াবেন
⚠️ এড়িয়ে চলবেন
- "Don't make mistakes" — vague।
- একই prompt-এ ১০টি task — split করুন।
- উদাহরণ ছাড়া বিরল format চাওয়া।
- Length control না দেওয়া।
Production টিপ
- System prompt fix, user prompt variable।
- Temperature 0 deterministic task-এ; 0.7+ creative-এ।
- Prompt versioning + eval suite (LangSmith, Promptfoo)।
- JSON output validate, retry on parse error।
- Token usage log → cost analytics।
🔑 Eval সবচেয়ে গুরুত্বপূর্ণ
ভালো prompt vs খারাপ prompt বলা সহজ নয় — ২০–৫০টি test case দিয়ে regression test বানান। Prompt change করলেই eval চালান।
অনুশীলন
১. একটি classifier prompt — zero-shot vs few-shot — accuracy তুলনা।
২. CoT on/off দিয়ে math problem-এর accuracy।
৩. JSON-output validator + retry loop লিখুন।
সারসংক্ষেপ
✨ এই অধ্যায়ে যা শিখলাম
- Prompt = role + task + context + examples + format।
- CoT, ReAct, few-shot — গুরুত্বপূর্ণ pattern।
- Eval suite ছাড়া prompt engineering অসম্পূর্ণ।