Question Answering: Reading Comprehension and Open-Domain QA
Module: Natural Language Processing | Difficulty: Advanced
Extractive QA
Generative QA
Open-Domain QA
SQuAD Metrics
| Metric | Model | Score | |--------|-------|-------| | EM | BERT-large | 84.1 | | F1 | BERT-large | 90.9 | | EM | RoBERTa | 88.5 | | F1 | RoBERTa | 94.6 |
import torch
import torch.nn as nn
class QAModel(nn.Module):
def __init__(self, bert_model):
super().__init__()
self.bert = bert_model
self.qa_outputs = nn.Linear(768, 2)
def forward(self, input_ids, attention_mask):
outputs = self.bert(input_ids, attention_mask=attention_mask)
logits = self.qa_outputs(outputs.last_hidden_state)
start_logits, end_logits = logits.split(1, dim=-1)
return start_logits.squeeze(-1), end_logits.squeeze(-1)
Research Insight: The key challenge in open-domain QA is retrieving relevant documents. Dense retrieval (DPR) outperforms sparse retrieval (BM25) by 15-20% on recall@100, but BM25 is more robust to domain shift.