본 포스트는 arXiv에 2021년 1월에 업로드된 'A Survey of Transformers'의 내용을 요약, 정리하였습니다.
A Survey of Transformers
Transformers have achieved great success in many artificial intelligence fields, such as natural language processing, computer vision, and audio processing. Therefore, it is natural to attract lots of interest from academic and industry researchers. Up to
arxiv.org
Transformer는 많은 AI 필드에서 사용되고 있는 아키텍처입니다. 저자가 이 survey paper를 쓴 이유로는 현재까지 Transformer를 다양한 형태로 변형한 아키텍처(X-formers)가 제안되었지만, 체계적이고 종합적인 Transformer의 변형 모델에 대한 리뷰가 없다는 것을 제시하고 있습니다.
그렇기 때문에, 다양한 Transformer의 변형 아키텍쳐인 X-formers에 대해
1. Architectural modification
2. Pre-Training Models
3. Applications
이 세가지 각각의 관점에서 어떠한 발전이 이루어졌는지를 비교, 분석하는 것을 목적으로 합니다.
1. Introduction & Background
Paper에서는 Background 섹션에서 Vanila Transformer를 자세하게 설명하고 진행하였지만, 이번 포스트에서는 X-formers의 소개에 초점이 맞추어져 있기 때문에 Vanila Transformer에 대한 설명은 생략하겠습니다.
자세한 내용은 'Attention is All You Need'논문과 유튜브 해설(나동빈 님)을 참고하시면 됩니다.
다양한 X-formers는 'Attention is All You Need'에서 제시한 (Vanila) Transformer를 세 가지 관점으로 확장, 변형하였습니다.
1) Model Efficiency
Transformer를 적용하는 데에 있어 가장 큰 도전은 길이가 긴 데이터(Long sequences)를 처리하는 데 있어서 Self-attention module의 computation & memory complexity의 비효율성입니다.
일반적인 경우에는 sequence length(T)보다 hidden dimension(D)가 더 크기 때문에, Complexity에 있어서 position-wide FFN에서의 병목 현상이 발생합니다. 하지만, long sequence의 경우에는($T > D$) self-attention에서의 병목 현상이 발생합니다.
Long sequence에서의 이런 문제를 해결하기 위해(Time complexity를 낮추기 위해) lightweight attention, divide-and-conquer 방법론을 비롯한 다양한 연구가 진행되었습니다.
2) Model Generalization
Transformer는 다양한 분야에 적용할 수 있는 flexible architecture이고, input data에 대해 편향되기 쉽기 때문에(원문에서는 makes few assumtions on the structural bias of input data라고 표현하고 있습니다), 작은 규모의 데이터에 대해 학습하는 것이 어렵습니다. 이런 문제를 해결하기 위해 structural bias, regularization, 큰 규모의 unlabled data에 대해 사전학습한 후에 data를 학습시키는 방법들을 도입했습니다.
3) Model Adaptation
Transformer를 다양한 task와 application에 적용하기 위한 연구가 진행되었습니다.
2. Architectural modification : Self-Attention
Paper에서는 Attention module이 transformer의 key component이기 때문에, attention-related variants를 별도의 섹션으로 구분하였다고 설명합니다.
Self-Attention은 Transformer에서 중요한 역할을 수행합니다. 하지만, Self-Attention은 앞서 언급했듯이 실제 적용 단계에서 두 가지 문제점이 존재합니다.
1) Complexity
Self-attention의 complexity는 $O(T^2 \cdot D)$이기 때문에, 긴 시퀀스를 다룰 때 병목 현상이 발생합니다.
2) Structural prior
Self-attention은 입력에 대해 structural bias가 없기 때문에, 사전 학습이 없는 Transformer는 작거나 중간 규모의 데이터에 overfit되는 경향이 있습니다.
위의 문제점을 개선하기 위해, attention 메커니즘에서 많은 발전들이 이루어졌습니다.
2.1 Sparse Attention
일반적인 Self-attention은 모든 token은 다른 token 각각과 attention이 이루어져야 합니다. 하지만, 학습된 attention matrix A($Q^TK$)는 sparse 하다는 관찰 결과는, query는 모든 key와 attention 연산을 할 필요성이 적다는 것을 의미합니다. 그렇기 때문에, query와 attention이 이루어지는 key들을 제한함으로써, query-key pair를 생성할 수 있고, 이에 대해서만 attention을 수행한다면 계산 복잡도를 줄일 수 있습니다.
Sparse Attention은 position-based, content-based sparse attention으로 나누어집니다.
1) Position-based sparse attention
위의 그림에서 보이는 Atomic sparse attention은 적용했을 때 효과가 각각 다르고, 데이터의 유형과 모델의 목적에 따라 사용합니다. 예를 들어, band attention은 locality를 강조하기 위해 사용하고, band attention에서 receptive field를 넓히기 위해 stride를 두는 dilated attention을 사용할 수 있습니다.
실제로 다양한 X-former는 Atomic sparse attention을 결합하여 사용합니다. 인상 깊었던 내용은 band attention과 internal global-node attention을 결합하여 사용하는 Longformer에서 attention token을 설정하는 방법이었는데, global node들은 sequence classification task에서 [CLS] token, Question answering task에서 question token들이 설정됩니다.
이렇게 각각 task의 특징에 따라 attention을 진행하는 query를 다르게 설정하여 attention의 계산 복잡도는 줄이면서 기대하는 attention의 효과를 얻을 수 있습니다.
2) Content-based sparse attention
Content-based sparse attention는 앞서 설명했던 position-based sparse attention과는 달리, query vector와 유사한 key vector들을 선정하고, 선정된 key vector와 attention이 이루어집니다.
Routing Transformer(k-means clustering), Reformer(locality-sensitive hashing), Sparse Adaptive Connection(graph) 등등 다양한 transformer들이 key token을 선정하기 위한 다양한 알고리즘을 적용하고 있습니다.
'논문리뷰' 카테고리의 다른 글
Dense Passage Retrieval for Open-Domain Question Answering (0) | 2021.12.05 |
---|---|
GPT Understands, Too (0) | 2021.11.21 |
Pitfalls in the Evaluation of Sentence Embeddings (1) | 2021.11.07 |
A Survey of Transformers - 中 (0) | 2021.09.12 |