Skip to main content
QUICK REVIEW

[논문 리뷰] cosFormer: Rethinking Softmax in Attention

Zhen Qin, Weixuan Sun|arXiv (Cornell University)|2022. 02. 17.
Advanced Neural Network ApplicationsComputer Science인용 수 65
한 줄 요약

cosFormer는 주의에서 소프트맥스(softmax)를 선형적이고 음수가 아닌 코사인 기반 재가중치 메커니즘으로 대체하여 선형 시간/공간 복잡도를 달성하면서 언어 모델링, 다운스트림 작업, 장거리 벤치마크에서 일반 Transformer의 성능과 동등하거나 그보다 우수한 성과를 보인다.

ABSTRACT

Transformer has shown great successes in natural language processing, computer vision, and audio processing. As one of its core components, the softmax attention helps to capture long-range dependencies yet prohibits its scale-up due to the quadratic space and time complexity to the sequence length. Kernel methods are often adopted to reduce the complexity by approximating the softmax operator. Nevertheless, due to the approximation errors, their performances vary in different tasks/corpus and suffer crucial performance drops when compared with the vanilla softmax attention. In this paper, we propose a linear transformer called cosFormer that can achieve comparable or better accuracy to the vanilla transformer in both casual and cross attentions. cosFormer is based on two key properties of softmax attention: i). non-negativeness of the attention matrix; ii). a non-linear re-weighting scheme that can concentrate the distribution of the attention matrix. As its linear substitute, cosFormer fulfills these properties with a linear operator and a cosine-based distance re-weighting mechanism. Extensive experiments on language modeling and text understanding tasks demonstrate the effectiveness of our method. We further examine our method on long sequences and achieve state-of-the-art performance on the Long-Range Arena benchmark. The source code is available at https://github.com/OpenNLPLab/cosFormer.

연구 동기 및 목표

  • softmax 어텐션이 성능을 희생하지 않으면서 선형 연산자로 대체될 수 있는지 조사한다.
  • 음수성을 보존하고 코사인 기반 재가중을 통해 시의성/근접성 편향을 도입하는 선형 어텐션 변형을 개발한다.
  • 오토리그레시브 및 양방향 언어 모델링, 다운스트림 분류 작업, 그리고 장거리 시퀀스 벤치마크에서 cosFormer를 평가한다.

제안 방법

  • softmax 기반 유사성을 음수가 되지 않는 선형 커널로 교체하기 위해 ReLU를 사용한다.
  • phi(Q)와 phi(K)를 이용한 선형 프로젝션으로 선형 시간/공간을 달성하기 위해 주의 계산을 분해한다.
  • Ptolemy 기반 분해를 사용하여 softmax의 지역성 및 안정화 효과를 모방하는 코사인 기반 재가중 메커니즘을 도입한다.
  • O = Q'K'^{T} cos(...)V가 효율적인 계산을 위해 두 개의 선형 항으로 합으로 분해되도록 cosFormer 공식을 도출한다.
  • 자원효율적인 트랜스포머들을 대상으로 자가회귀, 양방향 및 장거리 과제에서 커널 기반 및 패턴 기반의 비교를 수행한다.

실험 결과

연구 질문

  • RQ1softmax 어텐션을 선형 연산으로 효과적으로 대체해 비음수성 및 지역성과 같은 어텐션 특성을 보존할 수 있는가?
  • RQ2코사인 기반 재가중 메커니즘이 softmax와 유사한 안정성과 지역성을 다양한 NLP 과제에서 제공하는가?
  • RQ3cosFormer가 오토리그레시브 및 양방향 언어 모델링, 다운스트림 분류 및 장거리 벤치마크에서 어떤 성능을 보이는가?

주요 결과

  • cosFormer는 언어 모델링 및 다운스트림 과제에서 일반 Transformer와 동등하거나 더 나은 정확도와 함께 선형 시간/공간 복잡도를 달성한다.
  • cosFormer는 위키텍스트-103 자가회귀 작업에서 여러 기준선에 비해 더 빠른 수렴 및 경쟁력 있는 perplexity를 보인다.
  • 다운스트림 분류 과제(GLUE, IMDB, AMAZON)에서 cosFormer는 일반 Transformer의 성능에 근접하거나 이를 능가하고 많은 효율적 트랜스포머를 능가한다.
  • Long-Range Arena 벤치마크에서 cosFormer는 최첨단 또는 경쟁력 있는 결과를 얻으며, 작업 간 최상의 평균점을 포함한다.
  • 고찰에 따르면 코사인 기반 재가중이 수렴 속도와 최종 성능을 향상시키며 지역성 편향이 자연어 모델링에 이점을 준다는 것을 시사한다.

이 논문 읽기

누빈트 뷰어에서 원문을 열고, 읽으면서 궁금한 곳을 바로 물어보세요.

누빈트에서 이 논문 읽기

이 리뷰는 AI가 논문 원문을 바탕으로 만들었습니다. 인용하기 전에 원문을 확인해 주세요.