রোডম্যাপ
PHASE 6 · অধ্যায় 30

প্রশ্নোত্তর সিস্টেম

Question Answering Systems

Document থেকে answer extract করা।

ভূমিকা

Google এ 'capital of Bangladesh' search করলে শুধু link না — সরাসরি 'Dhaka' answer আসে। কীভাবে? Question Answering (QA) — যেখানে model একটা context (passage) থেকে exact answer extract করে অথবা generate করে। SQuAD benchmark, RAG, ChatGPT — সবার heart এ QA।

ধারণা

QA সিস্টেম দুই ধরনের: (1) Extractive — passage থেকে exact text span extract (BERT-based, SQuAD style), (2) Generative — context থেকে নতুন answer generate (T5, GPT)। Architecture: extractive এ model প্রতিটা token এর জন্য start/end logit দেয় — সবচেয়ে probable span ই answer। Open-domain QA: প্রথমে retriever passage খুঁজে আনে, তারপর reader answer বের করে।

সহজ ব্যাখ্যা

ভাবুন একটা book exam — passage দেওয়া আছে, question দেওয়া আছে, আপনি passage এ একটা phrase underline করে answer। Extractive QA ঠিক তাই। Open-book exam যেখানে আপনি library থেকে relevant book খুঁজে এনে answer লিখছেন — সেটা open-domain QA (retrieval + reading) — modern RAG এর precursor।

বাস্তব ব্যবহার

  • Google Search — featured snippet।
  • Customer support — knowledge base থেকে answer।
  • Voice assistant — Siri, Alexa, Google Assistant।
  • Legal/Medical document Q&A।
  • ChatGPT এর internal QA + context reasoning।

ধাপে ধাপে বিশ্লেষণ

1
Step 1 — Context + Question
একটা passage, একটা question — input pair।
2
Step 2 — Tokenize together
[CLS] question [SEP] context [SEP] — BERT input।
3
Step 3 — Model forward
Each token এর start_logit, end_logit।
4
Step 4 — Best span বের
argmax(start), argmax(end) — answer span।
5
Step 5 — Decode
Span token গুলো decode করে answer string।

Python কোড

from transformers import pipeline

qa = pipeline("question-answering", model="distilbert-base-cased-distilled-squad")

context = (
    "Bangladesh is a country in South Asia. Its capital and largest city is Dhaka. "
    "The official language is Bangla and the currency is the Taka. "
    "Bangladesh gained independence from Pakistan in 1971 after a nine month liberation war."
)

questions = [
    "What is the capital of Bangladesh?",
    "When did Bangladesh gain independence?",
    "What is the official language?",
    "What is the currency of Bangladesh?",
]

for q in questions:
    result = qa(question=q, context=context)
    print(f"Q: {q}")
    print(f"A: {result['answer']} (score: {result['score']:.3f})\n")
ব্যাখ্যা

pipeline('question-answering') extractive QA model load করে। প্রতিটা question + context pair কে tokenize করে model এ pass করে, best start/end span বের করে answer string return করে। score দিয়ে model এর confidence বোঝা যায়।

সাধারণ ভুল

  • Context এ answer না থাকলেও model কিছু একটা দেয় — confidence check করতে হবে।
  • Context length 512 token এর বেশি — sliding window দরকার।
  • Generative QA তে hallucination — 'I don't know' শেখানো হয়নি।
  • Bangla context এ english QA model — mBERT/XLM-R দরকার।

অনুশীলন

  1. নিজের article থেকে 5টা Q-A pair বানিয়ে test করুন।
  2. Long document (>512 token) এ sliding window apply।
  3. Confidence threshold বসান — কম হলে 'I don't know'।
  4. T5 দিয়ে generative QA compare করুন extractive এর সাথে।

ছোট প্রজেক্ট

Document QA Bot

একটা CLI tool: user একটা text file (article/report) দেয়, তারপর question জিজ্ঞেস করতে পারে loop এ। distilbert-squad দিয়ে answer + confidence। Confidence < 0.3 হলে 'উত্তর পাওয়া যায়নি' message।

সারাংশ

  • QA = context থেকে answer extract/generate।
  • Extractive (BERT) vs Generative (T5/GPT)।
  • Open-domain = Retriever + Reader (RAG এর precursor)।
  • Start/end logit দিয়ে span prediction।
  • Search engine, voice assistant, customer support — সবার core।