- 最終更新
- 2026/08/17
3秒でわかる
文中の各語が他の語をどれだけ参照すべきかを重みで決める仕組み。Transformerの中核で、長い文脈の理解を支えています。
30秒図解
もう少し詳しく
どういうものか
Self-Attentionは、
なぜ必要か
「その本は
具体例
import numpy as np
def self_attention(X, Wq, Wk, Wv):
Q, K, V = X @ Wq, X @ Wk, X @ Wv
d_k = K.shape[-1]
scores = Q @ K.T / np.sqrt(d_k) # 各語と各語の関連の強さ
weights = np.exp(scores) / np.exp(scores).sum(axis=-1, keepdims=True)
return weights @ V # 重み付きで情報を集めるnp.sqrt(d_k) で
つまずきやすいところ
計算量が系列長の
似た用語との違い
| 語 | 意味 |
|---|---|
| Self-Attention | 同じ |
| Cross-Attention | 別の |
| Transformer | Self-Attentionを |

