# Attention in Natural Language Processing

自然言語処理におけるアテンション

Andrea Galassi, Marco Lippi, Paolo Torroni · arXiv · 2019年2月4日

- **課題** アテンションは入力要素の関連度を学習するニューラルネットワークの仕組みです。実装の方法は多様なため、この論文は1つの一般的なモデルと4つの次元による分類体系にまとめています。
- **手法** RNNsearchのアラインメントスコアとsoftmaxの重みを出発点に、キー、クエリ、値、互換関数、分布関数からなる一般的なアテンションモデルを定義しています。
- **結果** 論文はアテンションモデルを入力表現、互換関数、分布関数、多重性の4つの次元で体系化しています。経験的な性能比較は示されていません。

## アテンションが必要な理由と研究の範囲

多くの自然言語処理の問題では、入力要素ごとに課題への関連度が異なります。感情分析では特定の側面を説明する単語だけが重要になり、機械翻訳では次の単語を生成する際に原文の一部の単語だけが必要になります。こうした問題に対応するには、モデルが入力の関連度を自ら学習し、計算資源を重要な要素に集中させられる必要があります。この論文は、この仕組みであるアテンションを自然言語処理の観点から1つの一般的なモデルにまとめ、ベクトル表現を入力とするアテンション構造を対象としています。論文では、アテンションの実験的な性能比較を目的としておらず、複数のタスクとデータセットを1つの基準で評価する経験的な比較は範囲外であると述べられています。

## RNNsearchの例で見るアテンションの動作

RNNsearchは、アテンションを機械翻訳に適用した代表的な構造です。双方向RNNエンコーダが入力xの要素ごとに注釈h\_iを計算し、デコーダは各時点tで、直前の隠れ状態s\_(t-1)と注釈群をアラインメントモデルに入力してスコアe\_tiを得ます。このスコアはsoftmaxで正規化され、a\_ti = exp(e\_ti) / Σ\_j exp(e\_tj) の形の重みになります。最後に文脈ベクトルc\_t = Σ\_i a\_ti h\_i が計算され、このベクトルはデコーダRNNが次の出力分布を計算する際に使われます。つまり、原文全体を固定長のベクトル1つに圧縮するのではなく、時点ごとに注釈全体から必要な情報を選んで取り出す方法です。

![Figure 2: Architecture of RNNsearch \[2\] ( left) and its attention model (right)](https://refivu.com/papers/256bf9a6-8f17-4632-954e-011dbadca408/figures/figure-74448dd22ae9e59ea6673a5d6d28eb46.png?thumb=512)

**Fig. 2** . Architecture of RNNsearch \[2\] ( left) and its attention model (right).

[出典](https://arxiv.org/abs/1902.02181v4) · [CC BY 4.0](https://creativecommons.org/licenses/by/4.0/) · Andrea Galassi, Marco Lippi, Paolo Torroni · Attention in Natural Language Processing · 論文の図を引用 · 元のPDFの3ページ目から図の部分を抽出しています。

## キー、クエリ、値に分けた一般的なアテンションモデル

この論文はRNNsearchの構造を一般化し、キーK、クエリq、値V、互換関数f、分布関数gからなるモデルを提示しています。キーKはアテンション分布を計算するためのデータの特徴であり、クエリqは必要に応じて使われる基準となる要素です。互換関数はe = f(q, K)によってエネルギースコアを作り、分布関数はa = g(e)でそれを重みに変換します。値Vがある場合はZ\_i = a\_i v\_iの形で値に重みを掛け、c = Σ z\_iによって文脈ベクトルを得ます。論文は、クエリがアテンションの基準を与える一般的な構造であり、質問応答や情報検索のクエリとは異なる概念だと区別しています。

![Figure 3: Core attention model](https://refivu.com/papers/256bf9a6-8f17-4632-954e-011dbadca408/figures/figure-a7b346fa9e3957c31c632957e73184c9.png?thumb=512)

**Fig. 3** . Core attention model.

[出典](https://arxiv.org/abs/1902.02181v4) · [CC BY 4.0](https://creativecommons.org/licenses/by/4.0/) · Andrea Galassi, Marco Lippi, Paolo Torroni · Attention in Natural Language Processing · 論文の図を引用 · 元のPDFの4ページ目から図の部分を抽出しています。

## 4つの次元で分類したアテンション

論文はアテンションモデルを、入力表現、互換関数、分布関数、入出力の多重性という4つの次元で分類しています。入力表現では、文脈エンコーディングを使う方式と、生データの埋め込みに直接適用するinner attention、自分自身をクエリとして使うself-attention、階層構造を使うhierarchical-input方式を区別しています。互換関数では、類似度に基づく内積系、クエリをキー空間に変換するgeneral attention、結合表現を使うadditive・concat attention、畳み込みに基づく方式を扱います。分布関数では、softmaxとsigmoid、sparsemax、位置制約、ハードアテンションと局所アテンションを比較しています。

多重性では、multihead、multidimensional、coattentionを説明しています。

![Figure 4: General attention model](https://refivu.com/papers/256bf9a6-8f17-4632-954e-011dbadca408/figures/figure-2c10fd6c76ce33ab64e4de9e0757ad33.png?thumb=512)

**Fig. 4** . General attention model.

[出典](https://arxiv.org/abs/1902.02181v4) · [CC BY 4.0](https://creativecommons.org/licenses/by/4.0/) · Andrea Galassi, Marco Lippi, Paolo Torroni · Attention in Natural Language Processing · 論文の図を引用 · 元のPDFの5ページ目から図の部分を抽出しています。

![Figure 6: Hierarchical input attention models deﬁned by Zhao and Zhang \[43\] (center), Yang et al. \[52\] (left), and Ma et al. \[113\] (right). The number inside t…](https://refivu.com/papers/256bf9a6-8f17-4632-954e-011dbadca408/figures/figure-5f3fcaaae7ccf81ee05661e76d79da24.png?thumb=512)

**Fig. 6** . Hierarchical input attention models deﬁned by Zhao and Zhang \[43\] (center), Yang et al. \[52\] (left), and Ma et al. \[113\] (right). The number inside the attention shapes indicates the order of application. Di fferent colors highlight different parts of the inputs.

[出典](https://arxiv.org/abs/1902.02181v4) · [CC BY 4.0](https://creativecommons.org/licenses/by/4.0/) · Andrea Galassi, Marco Lippi, Paolo Torroni · Attention in Natural Language Processing · 論文の図を引用 · 元のPDFの8ページ目から図の部分を抽出しています。

## Coattentionと集約関数

Coattentionは、クエリとキーがいずれもシーケンスである場合を扱います。coarse-grained方式は、一方の圧縮表現を他方のアテンションのクエリとして使い、fine-grained方式は、キー要素とクエリ要素のすべての組み合わせについてcocompatibility関数で行列Eを計算します。その後、aggregation関数がEからキーの重みa\_Kとクエリの重みa\_Qを求めます。たとえば、attention pooling方式は行と列の最大値を取り、あるキーが少なくとも1つのクエリ要素と強く結びつくと高い重みを受け取るようにします。論文では、こうした方式が特定のタスクに適していると説明していますが、すべてのクエリ要素との関係を同時に考慮する方式は計算コストがより大きいと報告しています。

## 事前知識と解釈の限界

論文は、アテンションの重みが入力の関連度を示すため、解釈のための道具として使えると説明しています。しかし近年の研究では、アテンションを信頼できる説明手段とみなすのは難しいという結果が示されています。JainとWallaceは、アテンションが他の説明指標と一致せず、似た分布でも異なる結果を生みうることを示しました。WiegreffeとPinterは、アテンションの重みに説明可能性がありうるものの、その説明は忠実な再構成というより、もっともらしい再構成に近いと見ました。論文はこの議論を紹介していますが、アテンションによる説明の信頼性を結論として確定してはいません。

![Figure 1: Example of attention visualization for an aspect-based sentiment a nalysis task, from \[1, Fig. 6\]. Words are highlighted according to attenti on scor…](https://refivu.com/papers/256bf9a6-8f17-4632-954e-011dbadca408/figures/figure-c2dc847cdfe246a73a8d0b93d84de7bc.png?thumb=512)

**Fig. 1** . Example of attention visualization for an aspect-based sentiment a nalysis task, from \[1, Fig. 6\]. Words are highlighted according to attenti on scores. Phrases in bold are the words considered relevant for the task or human rationales.

[出典](https://arxiv.org/abs/1902.02181v4) · [CC BY 4.0](https://creativecommons.org/licenses/by/4.0/) · Andrea Galassi, Marco Lippi, Paolo Torroni · Attention in Natural Language Processing · 論文の図を引用 · 元のPDFの2ページ目から図の部分を抽出しています。

## 論文情報

- **著者**: Andrea Galassi, Marco Lippi, Paolo Torroni
- **学会・ジャーナル**: arXiv · プレプリント
- **公開日**: 2019年2月4日
- **登録日**: 2026年11月6日
- **更新日**: 2021年10月11日
- **バージョン**: v4
- **arXiv**: 1902.02181
- **DOI**: 10.1109/tnnls.2020.3019893
- **カテゴリ**: cs.CL · cs.AI · cs.LG · stat.ML
- **ライセンス**: [CC BY 4.0](https://creativecommons.org/licenses/by/4.0/)
- **掲載内容**: 論文情報・解説・論文の図

[元論文 ↗](https://arxiv.org/abs/1902.02181v4) · [PDF ↗](https://arxiv.org/pdf/1902.02181v4)

この解説は、Refivuの韓国語解説をAIで翻訳したものです。不正確な翻訳や誤りが含まれる可能性があります。論文と図の利用条件は各出典に従います。

## アブストラクト

Attention is an increasingly popular mechanism used in a wide range of neural architectures. The mechanism itself has been realized in a variety of formats. However, because of the fast-paced advances in this domain, a systematic overview of attention is still missing. In this article, we define a unified model for attention architectures in natural language processing, with a focus on those designed to work with vector representations of the textual data. We propose a taxonomy of attention models according to four dimensions: the representation of the input, the compatibility function, the distribution function, and the multiplicity of the input and/or output. We present the examples of how prior information can be exploited in attention models and discuss ongoing research efforts and open challenges in the area, providing the first extensive categorization of the vast body of literature in this exciting domain.

## この論文を引用

Andrea Galassi, Marco Lippi, Paolo Torroni (2019). Attention in Natural Language Processing. arXiv:1902.02181v4. https://doi.org/10.1109/tnnls.2020.3019893

**BibTeX**

```
@article{galassi2019attention,
  title = {{Attention in Natural Language Processing}},
  author = {Andrea Galassi and Marco Lippi and Paolo Torroni},
  year = {2019},
  eprint = {1902.02181},
  archivePrefix = {arXiv},
  doi = {10.1109/tnnls.2020.3019893},
  url = {https://arxiv.org/abs/1902.02181v4}
}
```

## この論文の用語

- [Transformer](https://refivu.com/ja/terms/515e8433c447-transformer)
- [self-attention](https://refivu.com/ja/terms/426589b81077-self-attention)
- [Attention](https://refivu.com/ja/terms/28f6748abd85-attention)
- [SoftMax function](https://refivu.com/ja/terms/ce0db7dbb3f0-softmax-function)
- [context vector](https://refivu.com/ja/terms/48425b908472-context-vector)
- [soft attention](https://refivu.com/ja/terms/273692c14df4-soft-attention)
- [RNNsearch](https://refivu.com/ja/terms/83d9bbdf5979-rnnsearch)
- [additive attention](https://refivu.com/ja/terms/dc1effe7dceb-additive-attention)
- [attention weights](https://refivu.com/ja/terms/d95d24af291e-attention-weights)

## ほかの論文解説

- [Universal Language Model Fine-tuning for Text Classification](https://refivu.com/ja/papers/f2470a4a-1c9b-423c-8757-ba73cfe37b54-universal-language-model-fine-tuning-for-text-classification.md)
- [BART: Denoising Sequence-to-Sequence Pre-training for Natural Language Generation, Translation, and Comprehension](https://refivu.com/ja/papers/13b055d5-7dcd-422f-b6d8-3704e3d48533-bart-denoising-sequence-to-sequence-pre-training-for.md)
- [Training Tips for the Transformer Model](https://refivu.com/ja/papers/f2437599-de07-4bc9-b659-4823dff3be26-training-tips-for-the-transformer-model.md)
- [Sentiment Analysis Based on Deep Learning: A Comparative Study](https://refivu.com/ja/papers/01238de6-5a95-42bc-adff-3e5385ae4ea6-sentiment-analysis-based-on-deep-learning-a-comparative.md)
- [Prefix-Tuning: Optimizing Continuous Prompts for Generation](https://refivu.com/ja/papers/01cf041e-b71c-444b-8b44-e94ac976a9db-prefix-tuning-optimizing-continuous-prompts-for-generation.md)
- [Neural Machine Translation of Rare Words with Subword Units](https://refivu.com/ja/papers/0950e659-f6cc-4852-b244-bbb2742bf059-neural-machine-translation-of-rare-words-with-subword.md)
- [Deep Reinforcement Learning framework for Autonomous Driving](https://refivu.com/ja/papers/baaead94-eeef-4412-9a69-b14b7ab4fe14-deep-reinforcement-learning-framework-for-autonomous-driving.md)
- [U-shape Transformer for Underwater Image Enhancement](https://refivu.com/ja/papers/090ea979-276e-4ff3-b5ba-8d3483b8e2e8-u-shape-transformer-for-underwater-image-enhancement.md)
- [MSRF-Net: A Multi-Scale Residual Fusion Network for Biomedical Image Segmentation](https://refivu.com/ja/papers/6a391bec-28c7-48c8-b3ae-92ae5788cd01-msrf-net-a-multi-scale-residual-fusion-network.md)
- [Advanced Steel Microstructural Classification by Deep Learning Methods](https://refivu.com/ja/papers/40557ea6-2c03-4d59-8884-5b126f8414d1-advanced-steel-microstructural-classification-by-deep.md)
- [Generalizing to Unseen Domains: A Survey on Domain Generalization](https://refivu.com/ja/papers/d6aa63bc-3ab4-4a9e-91bf-ef0365bed5aa-generalizing-to-unseen-domains-a-survey-on-domain.md)
- [Rethinking RGB-D Salient Object Detection: Models, Data Sets, and Large-Scale Benchmarks](https://refivu.com/ja/papers/5abc609e-361c-4e17-87a0-9ee4d3898f77-rethinking-rgb-d-salient-object-detection-models-data.md)

---

AI解説には誤りが含まれることがあります。 [Refivu](https://refivu.com/ja/papers/256bf9a6-8f17-4632-954e-011dbadca408-attention-in-natural-language-processing)
