📑Paper Review

[paper review] Attention Is All You Need

date
Sep 13, 2022
slug
paper-review-attention
author
status
Public
tags
DeepLearning
paper
summary
type
Post
thumbnail
캡처.PNG
category
📑Paper Review
updatedAt
Sep 6, 2024 04:01 PM
 
실험에서 품질이 우수하고, 병렬 학습이 가능하다는 것을 증명함.
transformer는 다양한 task에서도 데이터를 잘 학습하며, 일반화됨을 보여줌
 

Introduction

recurrent language model과 encoder-decoder의 한계를 넓히기 위해, 수 많은 노력이 계속 됨.
model들은 input과 output의 위치에 따라 부분적으로 계산 진행
 
본질적으로 sequential한 특성은 훈련과정에서의 병렬화를 배제하는데, 이러한 메모리 제약에 의해 샘플간 배치화를 제한하여, 더 긴 길이의 시퀀스를 처리할 수 록 critical한 문제가 발생
최근에 factorization tricks과 conditional computation을 사용함으로서, 상당한 개선을 가져옴.
하지만, 여전히 근본적인 문제가 해결되지 않았음.
 
attention mechanism은 input과 output sequence거리에서 상관없는 dependency 모델링을 가능하게 함으로 다양한 task의 sequence modeling 및 transduction model 등에서 필수적인 부분이 되고 있음.
 
 

Background

모든 input, output에서 병렬적으로 hidden representation을 계산하는 cnn을 basic한 buliding block으로 사용
 
이 모델들에서는 input과 output의 임의의 두 위치로부터의 신호를 관계시키기위해 필요한 계산 수가 그 위치들간 거리에 따라 증가하는데, ConvS2S에서는 선형적으로, ByteNet에서는 logarithmically 하게 증가함. 이는 거리가 멀어질수록 dependency를 학습하는데 어려워지게 만듦.
 
반면 트랜스포머에서는 어떤 상수 번의 계산만이 요구됨. 비록 어텐션 가중 postition을 평균냄으로써 유효 해상도의 감소라는 cost가 있지만, 이후 살펴볼 multi-head attention으로 상쇄시킬 수 있음.
 
self-attention은 sequence의 표현을 계산하기 위해, single sequence내에서 다른 위치와 연관시키는 attention mechanism임
self-attention은 독해, 요약, 텍스트 수반, 문장 표현등 NLP의 다양한 task에서 사용됨.
 

Model Architecture

Transformer는 전반적인 Encoder-Decoder구조를 사용하는데, self-attention, point-wise, fully connected layer들을 encoder, decoder에 쌓아 사용함.
notion image

3.1 encoder and decoder stacks

<Encoder>
encoder는 6개의 layer가 쌓여 구성됨. 각각의 layer는 두 개의 sub-layer를 가지고 있음.
첫 번째 layer는 multi-head self-attention mechanism
두 번째 layer는 point-wise fully connected feed-forward network
두 개의 sub-layer마다 각각 residual connection을 적용하고, 이후 layer normalization을 따르게 함.
 
이 Residual connection의 적용의 편의를 위해, Embedding층을 포함한 모든 layer들이 output dimension 512를 갖도록 통일
 
<Decoder>
decoder 6개의 layer가 구성
두 가지 sub-layer로 구성되어있음.
encoder의 output에 대해 multi-head attention을 수행하는 sub-layer를 추가함.
encoder와 유사하게, residual connection과 layer normalizatiopn을 적용
decoder stack내의 self-attention layer를 수정
 

3.2 Attention

Attention function은 query, key, value, output들이 모두 백터일 때, key-value쌍의 output이 query에 mapping되게 유사함.
notion image
 

3.2.1 Scaled Dot-product attention

“Scaled Dot-Product attention”은 차원의 key와 차원의 value들로 구성되어 있음.
 
실제로는 모든 쿼리들이 하나의 행렬 Q로써, 키와 value들은 행렬 k와 V로써 packed되어 동시에 어텐션 함수가 계산됨. 어텐션 output 또한 V와 shape가 동일한 행렬이 되며 아래와 같이 계산됨.
notion image
어텐션 함수는 additice attention과 dot-product attention인데, dot-product attention인데, dot-product attention의 경우 scaling factor로써의 를 제외하면 본 연구의 제안 알고리즘과 동일함
additive attention은 단일 은닉층의 feed-forward network를 이용해 연관성 함수를 계산함. 두 방법이 이론상 동일한 복잡도를 갖는 반면, 실무에서는 dot-product attention이 고도로 최적화된 행렬곱 code로 구현할 수 있어 더 빠름
 

3.2.2 multi-head attention

차원의 key, value, query을 single attention function을 performing 하기 전에, query, key, value를 각각 차원으로 변환하는 서로 다른 h개의 학습 가능한 선형 사영을 진행한 뒤, 각각의 다른 projected version에 대해 병렬적으로 attention을 진행하는 것이 더 이롭다는 사실을 알게됨.
notion image
 
 
  1. 하나의 계층당 총 계산 복잡성
  1. 계산을 시행할 때, 병렬화가 가능
  1. 네트워크 내부 long-range de[emdencies간의 경로의 길이
 

Experiments & conclusion

notion image
본 연구에서는 transformer 를 제시함
transformer 는 오로지 attention에 기반을 둔 first sequence transductuon model이다.
recurrent layer들을 encoder decoder구조인 multi-headed, self-attentopn로 대체하였음.