Hook — সঠিক প্রশ্ন = সঠিক উত্তর
একই model — একজন পায় ১/১০ answer, আরেকজন পায় ৯/১০। পার্থক্য prompt এ। Prompt Engineering হলো LLM থেকে সর্বোচ্চ output আদায়ের কৌশল।
Anatomy of a Good Prompt
- Role — ‘You are a senior ML engineer’।
- Task — কী চাইছ, স্পষ্ট করে।
- Context — relevant background।
- Format — JSON/Markdown/bullet।
- Constraint — length, tone, audience।
- Examples — কেমন output চাই।
Core Techniques
- Zero-shot — শুধু instruction।
- Few-shot — কয়েকটা example দিয়ে।
- Chain-of-Thought (CoT) — ‘step by step ভাবো’।
- Self-consistency — একাধিক CoT, majority vote।
- ReAct — Reasoning + Action (tool use)।
- Tree-of-Thought — branching reasoning।
- Reflexion — নিজের answer critique করে retry।
Example — Zero vs Few vs CoT
zero-shot
Classify sentiment: "ফোনটা দ্রুত charge হয় কিন্তু battery quick শেষ।"few-shot
Review: "Service ছিল চমৎকার" → Positive
Review: "ডেলিভারি দেরি, packaging ভাঙা" → Negative
Review: "ফোনটা দ্রুত charge হয় কিন্তু battery quick শেষ।" →chain-of-thought
Q: একটা trainer ১২ km/h গতিতে ৪০ মিনিট দৌড়ালে কত km হবে?
A: চলো step by step ভাবি।
- 40 min = 40/60 hour = 2/3 hour
- distance = speed × time = 12 × 2/3 = 8 km
উত্তর: 8 km।Structured Output
json output
নিচের review থেকে JSON বের করো (key: sentiment, aspects, score 1-5):
"ফোনটা দ্রুত charge হয় কিন্তু battery quick শেষ।"
শুধু valid JSON output দাও, কোনো extra text না।Production টিপ
OpenAI/Anthropic এর structured output বা function calling ব্যবহার করো — regex parsing এর চেয়ে অনেক reliable।
Advanced Patterns
- System message এ persistent persona।
- Delimiter (### , <xml>) দিয়ে section আলাদা।
- ‘Think first, then answer’ — internal reasoning।
- Negative instruction (‘do not invent facts’)।
- Multi-turn refinement।
Anti-Patterns
এড়াও
Vague instruction, contradictory rule, অনেক বড় context dump, output format না বলে দেওয়া।
Code — OpenAI SDK
prompt_api.py
from openai import OpenAI
client = OpenAI()
resp = client.chat.completions.create(
model="gpt-4o-mini",
messages=[
{"role":"system","content":"You are a concise ML tutor. Answer in Bangla."},
{"role":"user","content":"Bias-Variance tradeoff ২ লাইনে।"},
],
temperature=0.3,
)
print(resp.choices[0].message.content)Summary
এক নজরে
Prompt = Role + Task + Context + Format + Example। CoT/ReAct/Few-shot দিয়ে reasoning ও reliability বাড়ে।