논문 링크: Self-Attention with Relative Position Representations
앞서 Attention Augmented Convolutional Networks, Music Transformer 논문에 등장했던 Relative Position Encoding 개념이 처음 등장한 논문이다.
처음 Transformer 구조가 등장했을때는 Sinusoids 함수를 이용한 absolute positional encoding 방식을 사용했다. 본 논문은 그것을 대체할 Relative Positional encoding 방법을 소개하고 있다.
medium에서 Relative Positional encoding에 대해 좋은 글이 있어서 링크를 올려본다.
How Self-Attention with Relative Position Representations works
An explanation of how Relative Position Representation embeddings allow Transformers to encode sequential information in an input sequence.
medium.com
Encoding 방법을 요약하자면
1. 현재 단어와 다른 단어 사이의 거리를 embedding look up table에 저장한다.
2. embedding matrix의 relative position을 absolute position으로 한번 바꾸어야 하기 때문에 embedding matrix가 embedding look up table을 참조해서 i*j*d의 tensor로 변환시킨다.
3. linear projected Value와 변환된 Tensor를 matrix multiplication시킨다.
끝.
물론 위 방법을 그대로 쓰는것은 추천하지 않는다. 본 논문의 방법은 i*j*d 형태의 tensor때문에 O(L^{2}D)의 메모리가 날아간다. Batch수가 늘어날수록 메모리 사용량이 급증하기 때문에 본 논문의 방법은 꽤 비효율적이라 볼 수 있을것이다. 게다가 embedding lookup table을 제작하는 코드를 만드는것도 정말 힘빠지는 일이다. 이미 Music Transformer 에서 더욱 쉽고 memory effiecient 방법을 소개하고 있으니 참조 하면 좋을듯 싶다.
Improvements:
1. Absolute Positional encoding 대신 Relative Postional encoding을 사용한다. 모델이 학습데이터에 있는 상대적인 거리를 학습할 수 있다.
끝.