プリンキピア

第11章注意機構とTransformer

11.3. Attention Scoring Functions11.3 注意のスコア関数

In Section 11.2, we used a number of different distance-based kernels, including a Gaussian kernel to model interactions between queries and keys. As it turns out, distance functions are slightly more expensive to compute than dot products. As such, with the softmax operation to ensure nonnegative attention weights, much of the work has gone into attention scoring functions a in (11.1.3) and Fig. 11.3.1 that are simpler to compute.
英語のヒント
11.2節では、クエリとキーのあいだの相互作用をモデル化するために、ガウスカーネルを含む、距離にもとづくさまざまなカーネルを使った。実は、距離の関数は内積より計算の費用が少し高い。そのため、ソフトマックス演算で注意の重みが非負になることを保証しつつ、多くの研究は、(11.1.3)と図11.3.1の、もっと計算しやすい注意のスコア関数aに注がれてきた。
Fig. 11.3.1図11.3.1
Computing the output of attention pooling as a weighted average of values, where weights are computed with the attention scoring function 𝑎 and the softmax operation.
英語のヒント
値の重みつき平均として注意プーリングの出力を計算する。重みは注意のスコア関数𝑎とソフトマックス演算で計算される。
import math
import torch
from torch import nn
from d2l import torch as d2l