논문 및 개념 정리

[2020] Poly-encoders: architectures and pre-training strategies for fast and accurate multi-sentence scoring

2022. 4. 4. 19:43
목차
  1. 1. Introduction
  2. 2. Model
  3. 1) Bi-Encoder
  4. 2) Cross-encoder
  5. 3) Poly-encoder(★)
  6. 3. 실험결과
  7. 1) Performance
  8. 2) Speed

Information retrieval이나 question answering 모델을 구성할 때 매우 큰 search space에서 속도와 성능이 둘다 중요한데 이를 위해 Retrieval & Rerank 구조가 많이 쓰인다(SBERT 설명글).

retrieval & rerank 구조

 

Retireval 엔진으로는 Bi-encoder, Reranker 엔진으로는 Cross-encoder가 많이 쓰인다. Microsoft에서 발표한 Poly-encoder는 Bi-encoder, Cross-encoder의 장점을 취해 Bi-encoder의 성능을 향상시킨 모델이며 효과가 좋은 것으로 알려져있다(원문). 참고로 이 Github에 깔끔하게 구현되어 있다.

 

1. Introduction

두 입력 sequence에 대한 비교나, 입력 sequence에 대한 label을 얻는 태스크는 다양하다. 대화에서 다음 턴에 적절한 응답이 무엇인지 등에 사용할 수 있다. 이때 encoder를 잘 구성하면 좋은 성능을 낼 수 있는 모델을 만들 수 있는데 자주 쓰이는 encoder는 Bi-encoder, Cross-encoder, Poly-encoder가 있다.

  • Bi-encoder: 두개의 입력 sequence에 대해 각각 full self-attention을 수행하고(encoding) aggregate하여 두개의 vector representaion을 얻음(encoder 두개 사용)
  • Cross-encoder: 두개의 입력 sequence를 하나의 sequnce로 합쳐 full self-attention을 수행하고(encoding) aggregate하여 하나의 vector representaion을 얻음(encoder 하나 사용)
  • Poly-encoder: Bi-encoder처럼 두 개의 encoder를 사용하되 Cross-encoder와 비슷한 full self-attention 효과를 누리기 위한 구조

 

2. Model

논문에서 Encoder으로는 BERT를 사용하였다. BERT-base 모델을 추가 pre-train하기 위해 Wiki, Toronto Books등의 데이터 문장을 [sent, next sent(or utter)]로 구성하여 MLM, NSP으로 학습하였다고 한다.

Retrieval & Rerank 모델 구조에서 context & candidate set이 존재하는데 context는 입력 query, candidate set은 입력에 대해 적절한 응답을 찾기 위한 search space라고 이해하면 된다. 대부분의 상황에서 candidate set은 매우 크며(N) 고정되어 있다.

 

1) Bi-Encoder

i. Model

두 개의 입력이 있을 때 각각의 sequnce에 대해 독립적으로 encoding하여 두개의 vector representation Yctxt=red(T1(ctxt)),Ycand=red(T2(cand))을 얻는다.

  • T1,T2:  각기 다른 pre-trained transformer(BERT)
  • T(x)=h1,⋯,hN: BERT output(token별 embedding)
  • red(⋅): BERT output에서 하나의 vector를 뽑는 reducer이며, 실험 결과에서 첫번째 token embedding을 사용하는게 성능이 조금 더 좋았다고 한다

ii. Scoring

yctxt, ycandi의 dot-product를 사용한다

  • s(ctxt,candi)=yctxt⋅ycandi

iii. Training

positive set(input, label)으로 학습 셋을 구성(bath size: n)하여 학습할 때

  • yctxt⋅ycandi,⋯,yctxt⋅ycandn를 계산하여 n개의 logit이 나오며(candi: positive label, n−1개의 negative label), cross-entroply loss로 학습
  • in-batch negative 방식으로 학습이 가능하기 때문에 batch size를 크게 할 수 있음

iv. Inference

candidate set이 고정이기 때문에 embedding을 미리 계산해둘 수 있다. 즉, 입력 query인 yctxt만 계산하면 되기 때문에 속도가 매우 빠르다.

 

 

2) Cross-encoder

i. Model

두 개의 입력 sequence를 하나로 합치고 encoding하여 하나의 vector representaion yctxt,cand=first(T(ctxt,cand))=h1을 얻을 수 있다.

  • candidate, context를 합쳐 self-attention을 계산하기 때문에 rich interactions을 얻을 수 있다고 함(candidate-sensitive input representation)

ii. Scoring

Linear(또는 Non-linear) layer를 통과시켜 score 얻음

  • s(ctxt,candi)=yctxt,candiW

iii. Training

  • n개의 logit s(ctxt,candi),⋯,s(ctxt,candn)에 대해 cross entropy loss로 학습
  • gpu 메모리가 상대적으로 크기 때문에 batch size를 Bi-encoder보다 작게 해야함
  • encoding을 매번 새롭게 해야하기 때문에 in-batch negative 방식을 사용할 수 없음

iv. Inference

candidate set의 임베딩을 매번 새롭게 계산하기 때문에 느리지만 정확도는 높음

 

 

 

3) Poly-encoder(★)

Poly-encoder는 Bi-encoder, Cross-encoder의 장점을 모두 활용하기 위한 모델이다.

  • candidate은 Bi-encoder에서 처럼 embedding을 미리 계산해둘 수 있음 → fast inference
  • context는 Cross-encoder에서 처럼 candidate과의 joined embedding 계산 → richer information

i. Model

➀ Candidate Encoder: ycandi 계산

➁ Context Feature Encoding:

  • T(x)=h1,⋯,hN으로 입력에 대한 embedding 계산
  • m개의 context code(trainable parameter)를 Query로, input embedding h1,⋯,hN을 Key, Value로 attention 계산하여 m개의 context feature 얻음(Emb1,⋯,Embm)
  • Embi=yctxti=∑jwjcihjwhere(w1ci,⋯,wNci)=softmax(ci⋅h1,⋯,ci⋅hN)
  • m<N이기 때문에 Cross-encoder에서의 self-attention보다 속도가 훨씬 빠르며 richer information을 얻을 수 있음

➂ Context Encoding: yctxt 계산

  • ycandi을 Query로, context feature Emb1(yctxti),⋯,Embm(yctxti)를 Key, Value로 attention 계산하여 yctxt 계산
  • yctxt=∑iwiyctxtiwhere(w1,⋯,wm)=softmax(ycandi⋅yctxt1⋯ycandi⋅yctxtm)

ii. Scoring

s(ctxt,candi)=yctxt⋅ycandi 또는 Non-linear layer등 사용

 

 

3. 실험결과

1) Performance

2) Speed

 

 

 

728x90
저작자표시 비영리 변경금지 (새창열림)

'논문 및 개념 정리' 카테고리의 다른 글

[2021] LoRA: Low-Rank Adaptation of Large Language Models  (0) 2022.07.14
[2021] GPT Understands, Too (P-tuning)  (0) 2022.04.29
[LM] Perplexity 개념  (0) 2022.02.17
[GPT3] 주요 내용 정리  (0) 2022.02.16
[2020] Spot The Bot: A Robust and Efficient Framework for the Evaluation of Conversational Dialogue Systems  (0) 2021.08.13
  1. 1. Introduction
  2. 2. Model
  3. 1) Bi-Encoder
  4. 2) Cross-encoder
  5. 3) Poly-encoder(★)
  6. 3. 실험결과
  7. 1) Performance
  8. 2) Speed
'논문 및 개념 정리' 카테고리의 다른 글
  • [2021] LoRA: Low-Rank Adaptation of Large Language Models
  • [2021] GPT Understands, Too (P-tuning)
  • [LM] Perplexity 개념
  • [GPT3] 주요 내용 정리
Fine애플
Fine애플
이것저것
끄적끄적이것저것
Fine애플
끄적끄적
Fine애플
전체
오늘
어제
  • 분류 전체보기 (167)
    • 논문 및 개념 정리 (27)
    • Pattern Recognition (8)
    • 개발 (57)
    • python 메모 (45)
    • pytorch, tensorflow (5)
    • 알고리즘 (9)
    • Toy Projects (4)
    • 통계이론 (2)
    • Reinforcement Learning (10)

블로그 메뉴

  • 홈

공지사항

인기 글

태그

  • miniconda
  • transformer
  • pandas
  • GPU
  • 개발환경
  • reinforcement learning
  • 언어모델
  • BigBird
  • tensorflow
  • ubuntu
  • container
  • 알고리즘
  • 딥러닝
  • python
  • Probability
  • PyTorch
  • Docker
  • Bert
  • 자연어
  • nlp

최근 댓글

최근 글

hELLO · Designed By 정상우.
Fine애플
[2020] Poly-encoders: architectures and pre-training strategies for fast and accurate multi-sentence scoring
상단으로

티스토리툴바

개인정보

  • 티스토리 홈
  • 포럼
  • 로그인

단축키

내 블로그

내 블로그 - 관리자 홈 전환
Q
Q
새 글 쓰기
W
W

블로그 게시글

글 수정 (권한 있는 경우)
E
E
댓글 영역으로 이동
C
C

모든 영역

이 페이지의 URL 복사
S
S
맨 위로 이동
T
T
티스토리 홈 이동
H
H
단축키 안내
Shift + /
⇧ + /

* 단축키는 한글/영문 대소문자로 이용 가능하며, 티스토리 기본 도메인에서만 동작합니다.