> For the complete documentation index, see [llms.txt](https://lswkim322.gitbook.io/til/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://lswkim322.gitbook.io/til/til-ml/boostcamp/p-stage-mrc/7-linking-mrc-and-retrieval.md).

# (7강) Linking MRC and Retrieval

> * retriever와 reader로 ODQA(Open Domain Question and Answering) 문제 풀기
> * ODQA란?
> * retriever-reader approach
>
> \[Reference and Further reading]
>
> * [Reading Wikipedia to Answer Open-domain Questions](https://arxiv.org/abs/1704.00051)
> * [A survey on Machine Reading Comprehension](https://arxiv.org/abs/2006.11880)
> * [ACL 2020 ODQA tutorial](https://slideslive.com/38931668/t8-opendomain-question-answering)

## 1. Introduction to Open-Domain Question Answering(ODQA)

### 1.1. ODQA

MRC는 지문이 주어진 상황에서 질의응답을 하는 것이다. 반면 ODQA의 경우 지문이 따로 주어지지 않고 방대한 World Knowledge (가령 위키피디아 데이터)에 기반해서 질의 응답을 하게 된다

### 1.2. History

#### Text retrieval conference(TREC) - QA Tracks(1999-2007)

* 연관문서만 반환하는 information retrieval(IR)에서 더 나아가서, short answer with support형태가 목표
* Question processiong + Passage retrieval + Answer processing

![](https://3944465397-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MjcKlzGhHYe2bvmxTwS%2Fuploads%2FT4l7OLdzyZfc07LgxzFN%2Fimage.png?alt=media\&token=53dedc4b-e4d0-4d22-a030-7300e50d60ed)

* Question processing: 질문을 어떻게하면 가장 잘 이해할 수 있을까?
  * Query formulation: 질문으로부터 키워드를 선택 / Answer type selection
* Passage retrieval: 기존의 IR방법을 활용해서 연관된 document를 뽑고, passage단위로 자른 후 선별(Named entity / Passage 내 question 단어의 개수 등과 같은 hand-crafted features 활용)
* Answer processing
  * Hand-crafted features와 heuristic을 활용한 classifier
  * 주어진 question과 선별된 passage들 내에서 답을 선

#### IBM Watson(2011)

* The DeepQA Project
* Jeopardy(TV quiz show) 우승

#### 그 후

![](https://3944465397-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MjcKlzGhHYe2bvmxTwS%2Fuploads%2Fu9TtlHG7AVuS64iidy5y%2Fimage.png?alt=media\&token=dbc22d07-43dd-4c9b-a15b-f36bfbafac03)

## 2. Retriever-Reader Approach

그동안 배운 1\~3 + 4\~6 강을 활용한 모델

* Retriever: 데이터 베이스에서 관련있는 문서를 검색
  * Input: document corpus + query
  * output: document with heigh similarity
  * TF-IDF, BM25 -> no train
  * Dense -> train with qa-dataset
* Reader: 문서내에서 질문에 대한 답을 찾음
  * Input: Retrieved document + query
  * output: answer
  * SQuAD와 같은 MRC 데이터 셋으로 학습
  * 학습 데이터를 추가하기 위해 Distant supervision을 활용

**Distant supervision**: 질문-답변만 있는 데이터셋에서 MRC 학습 데이터 만들기, Supporting document가 필요함.

* 위키피디아에서 Retriever를 이용해 관련성 높은 문서를 검색
* 짤거나 긴, 고유명사를 포함하지 않는등 부적합한 문서를 제거
* answer가 exact match로 들어있지 않은 문서 제거
* 남은 문서중에 질문과 연관성이 가장 높은 단락을 supporting evidence로 사용

💭 문서를 만들어 주는 기법.

#### Inference

* Retriever가 질문과 가장 관련성 높은 5개의 문서를 출력
* Reader는 5개 문서를 읽고 답변 예측
* Reader가 예측한 답변 중 가장 score가 높은 것을 최종 답으로 사용함

> **💭반복되는 내용인것 같다. MRC Task의 경우 크게 Retriever와 Reader로 나뉘게 되고**
>
> 1. Retriever를 통해 관련된 문서를 탐색
> 2. Reader를 통해 탐색된 문서 안에서 질문에 대한 정답을 찾기

## 3. Issues & Recent Approaches

### 3.1. Different granularities of text at indexong time

* 위키피디아나 웹 문서에는 Passage의 단위를 구분짓기가 명확하지 않다. 이를 어떻게 단위를 잡을지 정해야한다.
  * Article(5.08 m), Paragraph(29.5m), Sentence(75.9m)
* Retriever단계에서 몇개 (top-k)의 문서를 넘길지 정해야함. Passage를 나누는 기준에 따라 잡기 마련이다.
  * article(5), paragraph(29), sentence(75)
  * ![](https://3944465397-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MjcKlzGhHYe2bvmxTwS%2Fuploads%2F4C2ThCkDBpjnMHhTlpE0%2Fimage.png?alt=media\&token=189cbf90-e6df-46d4-b1ed-ac7a7b8a2019)

### 3.2. Single-passage vs Multi-passage training

기존 single passage인 경우 retrieved 된 k개들의 passage에 대해 각각 reader로 확인하고 answer의 예측점수를 나타내게 된다. 이 방법은 각 passages들에 대한 비교는 아니라고 할 수 있어 이 passage들을 하나로 취급해서 answer를 찾는 방식이 Multi-passage 학습니다.

문제점으로는 문서가 너무 길어져서 GPU의 메모리 할당량과 연산량이 많아진다는 것이 있다.

### 3.3. Importance of each passage

Retriever 모델에서 추출된 top-k passage들의 retrieval score를 reader 모델에 전달한다.

reader 모델이 최종 모델의 점수를 고를때, retriever모델의 점수를 가중치를 부여하는 것이 더 좋은 성능을 나타내곤 한다.

## 실습코드 Link

지금까지 배운 Retriever와 Reader 모델을 붙이는 과정을 실습한다.

<https://drive.google.com/file/d/1paHmsxLIVSVUgH3fRX6TQo-iDrvaIdY5/view?usp=sharing>
