第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 in (11.1.3) and Fig. 11.3.1 that are simpler to compute.
英語のヒント
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