본문 바로가기

자연어처리(NLP)

Rethinking Positional Encoding In Language Pre-training 논문 리뷰

반응형

 안녕하세요 '코딩 오페라'블로그를 운영하고 있는 저는 'Master.M'입니다. 현재 저는 '초등학생도 이해하는 자연어 처리'라는 주제로 자연어 처리(NLP)에 대해 포스팅을 하고 있습니다. 제목처럼 진짜 핵심 내용을 쉽게 설명하는 것을 목표로 하고 있으니 자연어 처리(NLP)에 입문하고 싶은 분들은 많은 관심 부탁드립니다. 이번 시간에 알아볼 내용은 'Rethinking Positional Encoding In Language Pre-training' 논문입니다. 

 

Abstract

  • absolute positional encoding에서 추가작업을 통해 다른 종류의 정보를 상관관계있이 혼합이 가능
  • downstream 작업에서 [CLS] token(문장의 정보들을 가지고 있는 특별한 token)을 다른 일반적인 단어 token들과 동일하게 처리하는 것에 대해 의문을 제기
  • "Transformer with Untied Positional Encoding (TUPE)" 모델을 제안함

 

Introduction

  • Original Transformer (absolute positional encoding)

https://codingopera.tistory.com/43

 

4-1. Transformer(Self Attention) [초등학생도 이해하는 자연어처리]

안녕하세요 '코딩 오페라'블로그를 운영하고 있는 저는 'Master.M'입니다. 현재 저는 '초등학생도 이해하는 자연어 처리'라는 주제로 자연어 처리(NLP)에 대해 포스팅을 하고 있습니다. 제목처럼 진

codingopera.tistory.com

  • Relative Postional Encoding

https://codingopera.tistory.com/53

 

Self-Attention with Relative Position Representations 논문 리뷰

안녕하세요 '코딩 오페라'블로그를 운영하고 있는 저는 'Master.M'입니다. 현재 저는 '초등학생도 이해하는 자연어 처리'라는 주제로 자연어 처리(NLP)에 대해 포스팅을 하고 있습니다. 제목처럼 진

codingopera.tistory.com

  • 위 Abstract에서 설명한 문제들이 발생
  • 이를 해결하기 위해 상관관계가 다른 부분은 계산을 별도로 수행
  • 첫 번째로, postional(위치) 상관관계와 contextual(문맥, 의미) 상관관계는 다르므로 서로 다른 파라미터들을 통해 계산
  • 두 번째로, 일반 단어 token과 [CLS] token의 상관관계는 다르므로 서로 다른 파라미터들을 통해 계산

 

Preliminary

  • Attention Module

Multi-head Attention

- Multi-head Attention은 위와 같이 구성

- 각 head에서 Attention을 계산하고 마지막에 이 값들을 서로  concat 하여 합침

 

input of Multi-head Attention
output of Multi-head Attention
Multi-head Attention
Attention formulation

- "Multi-head Attention"은 이 논문에서 설명하는 식이고, "Attention formulation"는 논문 Attention is all you need 에서 설명하는 Attention의 구조 식 (이 둘을 비교하면서 보면 이해가 쉬움)

- exp(a_ij)/sigma(exp(a_ij')) : softmax

- a_ij : attention score = QK^(T)/root(dk)

 

더 자세한 사항은 아래 글 참고

https://codingopera.tistory.com/53

 

Self-Attention with Relative Position Representations 논문 리뷰

안녕하세요 '코딩 오페라'블로그를 운영하고 있는 저는 'Master.M'입니다. 현재 저는 '초등학생도 이해하는 자연어 처리'라는 주제로 자연어 처리(NLP)에 대해 포스팅을 하고 있습니다. 제목처럼 진

codingopera.tistory.com

 

  • Positional Encoding

Absolute Positional Encoding

Absolute Positional Encoding

- 논문 "Attention is all you need"에서 설명한 positional encoding으로 기본이 되는 방식

- 단어 의미 token인 "w"와  positional encoding "p"를 그냥 더하여 Attention 계산

 

 

Relative Positional Encoding

Relative Positional Encoding
T5 Relative Positional Encoding

- 논문 "Self-Attention with Relative Position Representations"에서 제안한 positional encoding 방식

- 단어의 절대적인 위치대신 단어간 상대적인 위치 "a_(j-i)"를 Key에 더해줌

- i, j는 단어의 위치를 나타냄

- T5 모델에 사용된 positional encoding의 경우 bias가 더해짐

 

자세한 내용은 아래글 참조

https://codingopera.tistory.com/53

 

Self-Attention with Relative Position Representations 논문 리뷰

안녕하세요 '코딩 오페라'블로그를 운영하고 있는 저는 'Master.M'입니다. 현재 저는 '초등학생도 이해하는 자연어 처리'라는 주제로 자연어 처리(NLP)에 대해 포스팅을 하고 있습니다. 제목처럼 진

codingopera.tistory.com

 

Transformer With Untied Positional Encoding

  • Untie The Correlations Between Positions And Words

- 앞서 설명했던 absolute positional encoding을 전개하면 다음과 같이 됨

- 2, 3번째 항은 단어 의미 token과 positinal encoding 간의 내적으로 이루어져 있는데 이는 상관관계가 없음

- 위 식을 통해 attention을 그림으로 나타낸 결과역시 2, 3번째 항의 상관관계가 없는 것을 확인

 

proposed method

- 위의 문제를 해결하기 위해 다음과 같은 방법이 제안됨

- 기존에 단어 의미 token과 positional token을 합쳐 전개하는 방식 대신 단어 token은 단어 token 끼리, positonal token은 positional token끼리 내적 연산 후 나중에 합침 

absolute positional encoding proposed method
relative positional encoding proposed method

- 위 식은 각각 absolute와 relative positional encoding을 사용하는 식임

 

Experiment

  • BERT-A : absolute positional encoding BERT
  • BERT-R : relative positional encoding BERT
  • TUPE-A : absolute positional encoding TUPE
  • TUPE-R : relative positional encoding TUPE

 

  지금 까지 저희는 'Rethinking Positional Encoding In Language Pre-training'에 대해 알아보았습니다. 도움이 되셨나요? 만약 되셨다면 구독 및 좋아요로 표현해 주시면 정말 많은 힘이 됩니다. 궁금한 사항 혹은 앞으로 다루어 주었으면 좋을 주제가 있으시면 댓글 남겨주시면 감사하겠습니다. 저는 '코딩 오페라'의 'Master.M'이었습니다. 감사합니다.

 

 

Reference

https://arxiv.org/abs/2006.15595

 

Rethinking Positional Encoding in Language Pre-training

In this work, we investigate the positional encoding methods used in language pre-training (e.g., BERT) and identify several problems in the existing formulations. First, we show that in the absolute positional encoding, the addition operation applied on p

arxiv.org

 

반응형