Question Answering (QA)
In the previous lessons, you learned how machines understand text, extract entities, summarize content, and capture meaning using deep learning.
Now we arrive at one of the most powerful and practical NLP applications: Question Answering (QA).
QA systems allow machines to read information and answer questions directly, instead of forcing users to search and read entire documents.
What Is Question Answering?
Question Answering is an NLP task where a system takes a natural language question and returns a precise answer.
The answer may come from:
- A given document or paragraph
- A database or knowledge source
- Multiple documents (large-scale systems)
QA goes beyond keyword matching — it requires understanding meaning.
Why Question Answering Matters
Humans communicate through questions. If machines can answer questions, they become far more useful and intelligent.
QA systems reduce:
- Time spent searching
- Information overload
- User effort
This is why QA is central to modern AI assistants.
Real-World Examples of QA
You already use QA systems daily:
- Virtual assistants answering factual questions
- Customer support chatbots
- Educational platforms
- Search engines showing instant answers
Types of Question Answering Systems
QA systems are classified based on how they produce answers.
1. Extractive Question Answering
Extractive QA finds answers by selecting an exact span of text from a given context.
The answer already exists in the document.
Example:
- Context: Python was created by Guido van Rossum.
- Question: Who created Python?
- Answer: Guido van Rossum
This is commonly used in reading comprehension tasks.
2. Abstractive Question Answering
Abstractive QA generates answers using new words, not necessarily present in the context.
The model understands meaning and forms a natural language response.
This approach is more flexible but more complex.
3. Open-Domain Question Answering
Open-domain QA does not rely on a single document.
The system must:
- Search large knowledge sources
- Retrieve relevant information
- Extract or generate an answer
This is how large AI assistants operate.
Question Answering Pipeline
Most QA systems follow this pipeline:
- Question understanding
- Context retrieval
- Answer extraction or generation
- Answer validation
Each stage impacts final accuracy.
How Neural QA Models Work
Neural QA models treat QA as a supervised learning problem.
They receive:
- Input: Question + Context
- Output: Answer text
The model learns to align question words with relevant parts of the context.
Why Attention Is Critical in QA
Attention allows the model to:
- Focus on important question terms
- Ignore irrelevant sentences
- Match question meaning with context meaning
Without attention, QA accuracy drops sharply.
Conceptual QA Flow (Understanding Only)
Below is a simplified conceptual view of a QA model.
Where to run code:
- Google Colab (recommended)
- Jupyter Notebook
context_vectors = encoder(context)
question_vectors = encoder(question)
attention_scores = attention(question_vectors, context_vectors)
focused_context = apply_attention(attention_scores, context_vectors)
answer = decoder(focused_context)
This shows how attention helps the model locate answer-relevant information.
QA vs Traditional Search
| Aspect | Traditional Search | Question Answering |
|---|---|---|
| Output | Links | Direct answers |
| Understanding | Keyword-based | Context-based |
| User effort | High | Low |
Applications of Question Answering
- Customer support automation
- Educational tutoring systems
- Healthcare assistants
- Legal document analysis
- Enterprise knowledge systems
Homework / Assignment
Theory:
- Explain extractive vs abstractive QA
- Why attention is essential for QA
Practical:
- Use a pre-trained QA model
- Ask at least 5 questions on one paragraph
- Evaluate correctness of answers
Practice Environment:
- Google Colab
- Jupyter Notebook
Practice Questions
Q1. What is extractive question answering?
Q2. Which QA type generates new text?
Quick Quiz
Q1. Does extractive QA invent new words?
Q2. Which mechanism helps models focus?
Quick Recap
- QA systems answer natural language questions
- Extractive QA selects text spans
- Abstractive QA generates responses
- Attention is crucial for QA accuracy
- QA powers modern AI assistants
Next lesson: Named Entity Recognition (NER) using Deep Learning