Interactive demo · Foundations of Deep Learning · Chapter 12

Attention explorer

Each word of a sentence is a token vector xn. Self-attention forms queries Q = XW(q), keys K = XW(k) and values V = XW(v) and returns Y = Softmax[QKT/√D]V (12.14). The heat map is the matrix of attention weights anm: row n says how much output n draws on input m; every row is non-negative and sums to one. Change the scaling, the temperature, the mask, the positional encodings and the order of the words, and watch the weights. Click a row to select a query.

Sentence

Inputs

Norm s of the orthogonal inputs

Weight matrices

Dimension D

Scores

Temperature T (scores divided by T)

Mask

Positional encoding (12.25), amplitude

Order of the words

Try these

Embeddings have N(0, 1) entries and the weight matrices N(0, 1/D) entries, drawn from a seeded generator, so the same settings always give the same numbers. The positional encoding uses L = 10000. "Jacobian size" is maxi ∑j |∂ai/∂zj| = maxi 2ai(1 − ai) for the selected row: near 0 the softmax is saturated and passes almost no gradient.

In the lecture notes