Attention
表示
個輸入信息,給定任務相關(guān)的查詢向量
時,注意力函數(shù)為:
其中為score function,表示
在查詢向量
的注意力大小。
在絕大多數(shù)場景中,
。
下表總結(jié)了常用的score function的計算方法
| Name | score function | Citation |
|---|---|---|
| Additive/Concat | Bahdanau at al.,2015 | |
| Location | Luong at al.,2015 | |
| General | Luong at al.,2015 | |
| Dot Product | Luong at al.,2015 | |
| Scaled Dot-Product | Vaswani at al.,2017 |
Self-Attention
假設輸入序列為,輸出序列為
,首先我們可以通過線性變換得到三組向量序列:
其中,
,
分別為查詢向量序列,鍵向量序列和值向量序列,
,
,
分別為可學習的參數(shù)矩陣。
輸出向量可通過以下方法計算得到:
其中為輸出和輸入向量序列的位置,連接權(quán)重
由注意力機制動態(tài)生成。由于自注意力模型的權(quán)重是動態(tài)生成的,因此可以處理變長的信息序列。
自注意力模型計算的權(quán)重
只依賴
和
的相關(guān)性,而忽略了輸入信息的位置信息。因此在單獨使用時,自注意力模型一般需要加入位置編碼信息來進行修正Vaswani at al., 2017
最新研究
- DiSAN: Directional Self-Attention Network for RNN/CNN-Free Language Understanding
- Reinforced Self-Attention Network: a Hybrid of Hard and Soft Attention for Sequence Modeling
- Convolutional Self-Attention Network
- Self-Attention with Relative Position Representations
- Modeling Localness for Self-Attention Networks