> 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/3-generation-based-mrc.md).

# (3강) Generation-based MRC

> * 생성기반 기계독해
> * 생성기반 기계 독해를 풀수 있는지 알아본다.
> * 전처리 -> 학습 -> 답을 얻어내는 단계
>
> **\[Reference]**
>
> * [Introducing BART](https://sshleifer.github.io/blog_v2/jupyter/2020/03/12/bart.html)
> * [BART: Denoising Sequence-to-Sequence Pre-training for Natural Language Generation, Translation, and Comprehension](https://arxiv.org/abs/1910.13461)
> * [Exploring the Limits of Transfer Learning with a Unified Text-to-Text Transformer (T5) ](https://arxiv.org/abs/1910.10683)

## 1. Generation-based MRC

### 1.1. 문제 정의

주어진 지문과 질의를 보고, 답변을 생성 -> 생성 문제

![](/files/6sYyBZsoVwUf5YdbTklr)

### 1.2. 평가방법

Extraction based MRC와 동일한 방법으로 평가도 가능 하지만 ROUGE나 BLEU를 활용하여 평가함

### 1.3. Overview

![](/files/ckVEzf0yZGyJccJPSK19)

### 1.4. Generation-Based vs Extraction-Based

* MRC 모델 구조
  * Seq2Seq PLM 구조 vs PLM + Classifier 구조
* Loss계산을 위한 답의 형태 / Prediction의 형태
  * Free-form text 형태 vs 지문 내 답의 위치

![](/files/taiPQu0B2GCmA35ybpz4)

## 2. Pre-processing

### 2.1. 입력 표현 - 데이터 예시

![](/files/eJV5pItUDltivO4YTnkV)

### 2.2. 토큰화

WordPiece Tokenizer를 사용

* 인덱스로 바뀐 질문을 보통 `input_ids` (or `input_token_ids`)로 부름
* 모델의 기본 입력은 `input_ids` 만 필요하나, 그 외 추가적인 정보가 필요함
  * special token, attention mask

### 2.3. Special Token

학습 시에만 사용되며 단어 자체의 의미는 가지지 않는 특별한 토큰

* SOS(Start of Sentence), EOS(End of Sentence), CLS, SEP, PAD, UNK...
* Extraction-based MRD: CLS, SEP, PAD
* Generation-based MRC: PAD, 자연어를 통해 정해진 텍스트 포맷으로 데이터를 생성

![](/files/Si0SjLybbJ0JjRyU40np)

### 2.4. additional information

* Attention mask
  * 어텐션 연산을 수행할지 결정
* Token type ids
  * BERT와 달리 BART에서는 입력 시퀸스에 대한 구분이 없어 `token_type_ids` 가 존재하지않음 따라서 입력에 `token_type_ids` 가 들어가지 않음.

![](/files/hOHT5HNHs29q9zrEzsuP)

### 2.5. 출력표현

Extraction은 단지 토큰의 위치를 출력하는 것이 목표인 반면 Generation의 경우 실제 텍스트를 생성하는 과제를 수행하게 된다.

![](/files/FsAgyBvrpoqal2SAbCkL)

## 3. Model

### 3.1. BART

기계독해, 기계 번역, 요약, 대화 등 seq2seq 문제의 pre-training을 위한 denoising autoencoder

![](/files/NMWZvin0kdTKjyJyZzXE)

* noise를 추가하고 그 부분을 맞추는 방법

### 3.2. BART Encoder & Decoder

* Encoder: BERT 처럼 Bi-directional
* Decoder: GPT 처럼 uni-directional(auto-regressive)

### 3.3. Pre-training BART

![](/files/HQGdO7rCJF8vkqeprHG4)

* 텍스트에 노이즈를 주고 원래 텍스트를 복구하는 문제를 푸는 방식으로 Pre-Training을 진행하게 된다.

## 4. Post-processing

### 4.1. Searching

![](/files/cvP7iG8ot35UBtYSNgul)

* 일반적으로 Beam Search와 유사한 방식을 사용한다.

## 실습코드 Link

{% embed url="<https://drive.google.com/file/d/13S2jy6cyV3Q6IDbNh-7W9_Rnx1IZlIoh/view?usp=sharing>" %}


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://lswkim322.gitbook.io/til/til-ml/boostcamp/p-stage-mrc/3-generation-based-mrc.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
