Skip to content

Commit

Permalink
Update 2024-12-30-rag-paper.md
Browse files Browse the repository at this point in the history
  • Loading branch information
losskatsu authored Dec 30, 2024
1 parent a52a950 commit 0f4caed
Showing 1 changed file with 39 additions and 0 deletions.
39 changes: 39 additions & 0 deletions _posts/machine-learning/2024-12-30-rag-paper.md
Original file line number Diff line number Diff line change
Expand Up @@ -173,9 +173,48 @@ $p_\eta$ 및 $p_\theta$의 구성 요소와 함께 학습 및 디코딩 절차

### 2-1. Models

(1) RAG-Sequence model

RAG-Sequence model은 동일한 검색된 문서를 사용하여 전체 시퀀스를 생성한다.
기술적으로, RAG-Sequence 모델은 검색된 문서를 단일 잠재 변수로 취급하며,
이를 주변화(marginalize)하여 상위-K 근사를 통해
seq2seq 확률 $p(y\|x)$를 계산한다.
구체적으로, 검색기를 사용하여 상위 $K$개의 문서를 검색하고,
생성기는 각 문서에 대해 아웃풋 시퀀스 확률을 생성한다.
이후, 이러한 확률들을 주변화(marginalize)하여 최종 아웃풋 확률을 계산한다.

$p_{RAG-Sequence}(y\|x)\approx \sum_{z\in top-k(p(\cdot\|x))}p_{\eta}(z\|x)p_{\theta}(y\|x,z)$

위 수식에서 우변은 다시 다음 식으로 정리할 수 있다.

$\sum_{z\in top-k(p(\cdot\|x))}p_{\eta}(z\|x)p_{\theta}(y\|x,z) = \sum_{z\in top-k(p(\cdot\|x))}p_{\eta}(z\|x)\Pi_{i}^{N}p_{\theta}(y_{i}\|x,z,y_{1:i-1})$

(2) RAG-Token Model

RAG-Token 모델에서는 각 대상 토큰에 대해 서로 다른 잠재 문서를 선택할 수 있으며,
이에 따라 주변화(marginalization)을 수행한다.
이는 생성기가 답변을 생성할 때, 여러 문서에서 콘텐츠를 선택할 수 있도록 한다.
구체적으로, 검색기를 사용하여 상위 K개의 문서를 검색한 후,
생성기는 각 문서에 대해 다음 출력 토큰의 분포를 생성한다.
이후, 이 분포를 주변화(marginalize)하고,
다음 출력 토큰에 대해 동일한 과정을 반복한다.
이를 공식적으로 정의하면 다음과 같다.

$p_{RAG-Token}(y\|x) \approx \Pi_{i}^{N}\sum_{z\in top-k(p(\cdot\|x))}p_{\eta}(z\|x)p_{\theta}(y_{i}\|x,z,y_{1:i-1})$

마지막으로, RAG는 대상 클래스를 길이가 1인 타겟 시퀀스로 간주하여
시퀀스 분류 작업에도 사용할 수 있다.
이 경우, RAG-Sequence와 RAG-Token은 동등하게 동작한다.

### 2-2. Retriever: DPR

검색 구성 요소 $p_{\eta}(z\|x)$는 Dense Passage Retriever(DPR)에 가반한다. DPR은 다음과 같은 바이엔코더(bi-encoder) 아키텍처를 따른다.

$p_{\eta}(z\|x) \propto exp(\textbf{d}(z)^{T}\textbf{q}(x))$

$\textbf{d}(z) = BERT_{d}(z), \textbf{q}(z) = BERT_{q}(z)$



### 2-3. Generator: BART

Expand Down

0 comments on commit 0f4caed

Please sign in to comment.