1. What is question answering?
question answering의 목적은 자연 언어로 인간의 질문에 대해 자동적으로 답을 하는 시스템을 구축하는 것이다.
정보 소스 | 질문 유형 | 답변 유형 |
text message, Web contents, knowledge based, tables, images | factoid vs non-factoid, open-domain vs close-domain, simple vs complex | short segment of text, paragraph, list |
우리가 배울 question answering은 unstructured text에 기반한다.
2. Reading Comprehension
reading comprehension은 텍스트를 종합하여 이해하고 그에 대한 답을 하는 것이다. reading comprehension은 다음과 같은 이유로 중요하다. (P, Q) -> A의 구조를 갖는다. passage와 question으로 answer을 예측한다.
- 많은 실용적 응용에 유용하다.
- reading comprehension은 기계가 인간 언어를 잘 이해했는지 평가하는 중요한 잣대가 된다.
- 다른 NLP 테스크가 reading comprehension 테스크로 단순화되어 나타날 수 있다.
- ex) information extraction(정보 추출), semantic role labeling(누가, 어디서, 무엇을 등을 question answering으로 형태를 바꾸어 알아낸다)
SQuAD(Stanford Question Answering Dataset)
- dataset for reading comprehension
- 100k annotated (passage, question, answer) triples
- each answer is a short segment of text in the passsage -> limitation: not every question can be answered in this way
- evaluation은 f1 score를 통해 이루어진다.
- dev와 test 과정에서 한 문제에 대해 3개의 gold answer을 수집하고, 각각의 gold answer와 predicted answer을 비교한 뒤 max score를 뽑는다. 이 과정을 모든 문제에 대해 반복한 뒤 평균을 내면, 그 모델의 f1 score를 구할 수 있다.
- SQuAD 데이터셋을 해결하기 위한 모델의 구축
- input: C = (c1, c2...cn), Q = (q1, q2...qm) (문맥과 질문)
- output: 1<=start<end<=end (답변)
- LSTM-based
- BERT-like models
1. BiDAF(the Bidirectional Attention Flow Model) - LSTM based model
question answering에는 source와 target sequence 대신에 passage와 question sequence가 있다. 모델의 목적은 passage의 어떤 부분이 question과 연관되어 있는지 찾는 것이다. 이때 question이 passage의 어떤 부분에 집중해야 하는지를 알아내는 attention이 중요하게 쓰인다. target sequence를 알아내는 decoder는 필요 없지만, 대신에 passage의 어떤 부분에서 answer이 시작되고 끝나는지를 알아내기 위해 두 개의 classifiers를 학습시킨다.
- encoding(embedding layers: character embed layer + word embed layer + phrase embed layer)
- context와 query에 대한 word embedding(GloVe)와 character embedding을 각각 concatenate하여 context와 query에 대한 embedding을 구한다.
- bidirectional LSTM(원래 LSTM은 unidirectional하지만 question answering에서는 양방향의 정보를 모두 이용해도 되므로)을 사용하여 왼쪽과 오른쪽의 정보가 모두 반영된 context와 query 임베딩 벡터를 구한다.
- attention flow layer
- context-to-query attention: 각각의 context 단어에 대해 query의 어떤 부분과 관련이 있는지 구한다.
- query-to-context attention: 각각의 query 단어에 대해 context 단어 중 가장 relevant한 것을 고른다.
- modeling and output layers
- output layer에서는 최종적으로 context의 어떤 부분에 answer이 있는지를 찾아야 하므로 answer의 start단어와 end단어를 찾는다.
- attention visualization of BiDAF respect to SQuDA
2. BERT for reading comprehension
question과 passage를 input으로 주어주고 passage의 시작과 끝 부분을 예측하여 answer을 맞추는 것이 목적이다.
BERT-based model은 SQuAD에 대해 매우 뛰어난 성능을 보이고, BERT 외에 다른 pretrained 모델 역시 그렇다.
BiDAF vs BERT
- BERT는 110M or 330M으로 매우 많은 파라미터를 갖고 있지만 BiDAF는 2.5M의 파라미터밖에 갖고 있지 않다.
- BERT는 transformer 기반이기 때문에 순차적이지 않고 병렬화가 가능하지만 BiDAF는 여러 개의 bidirectional LSTMs 기반이다.
- BERT는 pretrained model이지만 BiDAF는 GloVe(fixed word embedding)기반이다.
=> pretraining이 BERT의 성능이 뛰어난 것의 명백한 이유이지만(parameter initialization), 비싸다는 단점이 있다.
그렇다고 BERT와 BiDAF가 근본적으로 다른 것은 아니다. BERT는 self-attention까지 이용해서 attention(P, Q) + attention(P, P) + attention(Q, P) + attention(Q, Q)를 이용하고 BiDAF는 query와 passage 사이의 관계에 주목한다. 따라서 BiDAF도 self-attention을 이용하면 성능을 개선할 수 있다.
그렇다면 pretraining을 더 개선하여 디자인할 수 있을까? 두 개의 아이디어를 활용할 수 있다. 먼저 여러 개의 랜덤 토큰이 아니라 연속된 span을 masking한 뒤, span의 end point인 'was'와 'to'에 masked span의 정보를 압축해서 masked span을 예측할 수 있다. 이를 SpanBERT라고 한다. 이때 MLM(Masked Language Model)로 masking된 토큰이 'football'일 확률을 최대화하고 SBO(Span Boundary Objective)로 span의 boundary를 사용하여 'football'일 확률을 최대화한다. \(p_{i-s+1}\)은 span의 양 끝 점(x4, x9)에 대한 토큰의 상대적인 위치에 대한 정보이다.
비록 모델의 SQuAD에 대한 성능은 인간을 능가했지만, 이것이 reading comprehension 문제가 완벽히 해결되었다는 뜻은 아니다. 현재의 시스템은 여전히 적대적인 예제나 훈련된 도메인 이외의 예제에 대해서는 낮은 성능을 보인다.
3. Open-domain question answering
reading comprehension과 다르게 주어진 passage를 가정하지 않는다. 대신에, 오직 대량의 문서에만 접근하고 정확한 정답은 어딨는지 모른 채 답을 도출해야 하므로 훨씬 어렵지만 실용적인 문제다. closed-domain과 다르게 open-domain에는 정답이 존재하지 않는다.
Retriever-reader framework
retriever는 documents와 question이 주어지면 passage를 검색하고, reader는 검색된 passage에서 question에 대한 answer를 출력한다.
reader는 위의 reading comprehension 모델인 BERT나 BiDAF을 사용해 훈련할 수 있고, retriever 역시 훈련이 가능하다.
- joint training of retriever and reader: BERT를 이용해 각 passage가 벡터로 encoding되고 retriever score는 question representation과 passage representation의 내적으로 구할 수 있다. 그러나, passage의 수가 매우매우 많아 계산량이 많다는 한계가 있다.
- dense passage retrieval(DPR): retriever을 question-answer 쌍을 사용해서 훈련시킨다.
- 만약 LLM이라면 이미 매우 많은 데이터로 pretrained되었기 때문에 retriever 과정이 필요 없다.
- BERT 모델 없이 phrase encoding과 question encoding 간에 nearest neighbor search를 할 수 있다.
이 포스팅은 Stanford CS 강의 12단원에 기반하여 작성되었습니다.
'NLP > cs224n' 카테고리의 다른 글
[cs224n] Coreference Resolution (0) | 2024.07.08 |
---|---|
[cs224n] NLG(Natural Language Generation) (0) | 2024.07.06 |
[cs224n] Prompting, RLHF (0) | 2024.07.05 |
[cs224n] Pretraining (0) | 2024.07.03 |
[cs224n] Self-Attention, Transformer (1) | 2024.07.03 |