long8v / PTIR

Paper Today I Read
19 stars 0 forks source link

[21] cosFormer: Rethinking Softmax in Attention #22

Open long8v opened 2 years ago

long8v commented 2 years ago
image

paper

Introduction

Our Method

CosFormer의 아이디어는 non-decomposable non-linear softmax연산을 decomposable non-linear re-weighting mechanism과 linear operation으로 대체하는 것이다.

image

일반적인 트랜스포머는 O(L**2) 만큼 복잡도가 든다. 이때 주요한 점은 similarity function을 어느 것이나 선택할 수 있다는 점이다. S(Q, K)를 linear하게 하기 위해서 similarity function을 decomposible similarity function으로 만들 수 있다. -> exp(Q KT)가 아니라 \phi(Q)\phi(K)가 similarity가 되는 것

image

그 이후 우리는 matrix property를 통해 KV를 먼저 구해주면 linear complexity O(Nd^2)를 달성할 수 있다. 일반적으로 N >> d 이므로 O(N)으로 표현할 수있다. image

image image

우리는 softmax의 특징을 (i) non-negative (ii) non-linear re-weighting으로 보았는데, 이를 확인하기 위해 similarity matrix를 구할 때 다양한 함수를 사용했다. non-negative의 성질 때문에 ReLU > LeakyReLU > Identity 였고, non-linear의 성질 때문에 softmax > ReLU였다.

CosFormer 1) linear projection kernel = ReLU, dot product를 했다.

image

negtive value를 제거하기 위해 kernel은 ReLU를 사용했다.

image

similiarity function은 dot product를 row별로 했다.

image

2) cos-Based Re-weighting Mechanism softmax가 하는 non-linear re-weighting이 중요한데, attention weight의 분포에 집중하게 해주고 학습 과정을 안정화시킨다. 우리는 또한 이가 멀리 있는 connection에 대해 패널티를 주고 가까운 곳 대해선 enforce 해주는 효과를 볼 수 있었다.

image

이러한 cosine strategy는 완벽하게 decompose 가능하다 (수식 생략)

image

Result

image image

papers