[論文レビュー] cosFormer: Rethinking Softmax in Attention
cosFormerはattentionにおけるsoftmaxを線形で非負のコサイン再加重機構に置換し、長さが長いシーケンスにも対応可能な線形の時間/空間計算量を実現しつつ、言語モデリング、下流タスク、長距離ベンチマークで元のTransformerと同等以上の性能を達成する。
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 が効率的な計算のために2つの線形項の和に分解されるようにcosFormerの定式化を導出する。
- 自己回帰型・双方向型・長距離タスクに対して、カーネルベースおよびパターンベースの効率的トランスフォーマーと比較する。
実験結果
リサーチクエスチョン
- RQ1softmaxアテンションを性能を損なうことなく線形演算子に置換えられるかどうか。
- RQ2コサインベースの再重み付け機構がsoftmaxと同様の安定性と localityを様々なNLPタスクで提供するかどうか。
- RQ3cosFormerは自己回帰および双方向の言語モデリング、下流分類および長距離ベンチマークでどのように性能を示すか。
主な発見
- cosFormerは言語モデリングおよび下流タスクで、vanilla Transformerと同等またはそれ以上の精度を、線形の時間/空間計算量で達成する。
- cosFormerはWikiText-103の自己回帰タスクで、いくつかのベースラインと比較して収束が速く、困惑度が競争力を持つことを示す。
- 下流の分類タスク(GLUE、IMDB、AMAZON)において、cosFormerはvanilla Transformerの性能に匹敵するか近づき、多くの効率的なトランスフォーマーを上回る。
- Long-Range Arenaベンチマークでは、cosFormerは最先端または競争力のある結果を達成し、タスク間の総合平均で最良を含む。
- アブレーションは、コサインベースの再重み付けが収束速度と最終性能を改善することを示し、局所性バイアスが自然言語モデリングに有益であることを示唆する。
より良い研究を、今すぐ始めましょう
論文設計から論文執筆まで、研究時間を劇的に削減しましょう。
クレジットカード登録不要
このレビューはAIが作成し、人間の編集者が確認しました。