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.
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.
code/ch12_transformers.py (explorer_inputs, explorer_attention, js_shuffle); the weights shown here equal explorer_attention number for number.