Two Matrices, Swapped

AttentionHard+30 XP+30

Two Matrices, Swapped

A self-attention layer projects each token xix_ixi​ into three vectors using three learned matrices

qi=WQxi,ki=WKxi,vi=WVxiq_i = W_Q x_i, \qquad k_i = W_K x_i, \qquad v_i = W_V x_iqi​=WQ​xi​,ki​=WK​xi​,vi​=WV​xi​

and then computes, for the query at position iii,

αij=softmax⁡j ⁣(qi⋅kjd),outi=∑jαij vj\alpha_{ij} = \operatorname{softmax}_j\!\left(\frac{q_i \cdot k_j}{\sqrt{d}}\right), \qquad \text{out}_i = \sum_j \alpha_{ij}\, v_jαij​=softmaxj​(d​qi​⋅kj​​),outi​=∑j​αij​vj​

An engineer refactoring the code swaps two lines. The tensor produced by WKW_KWK​ is now handed to the layer as the values, and the tensor produced by WVW_VWV​ is handed to it as the keys. The swap is consistent everywhere, both matrices produce vectors of the same width ddd, and the layer is then trained from a fresh random initialisation on the usual task. So the refactored layer computes

αij=softmax⁡j ⁣(qi⋅vjd),outi=∑jαij kj\alpha_{ij} = \operatorname{softmax}_j\!\left(\frac{q_i \cdot v_j}{\sqrt{d}}\right), \qquad \text{out}_i = \sum_j \alpha_{ij}\, k_jαij​=softmaxj​(d​qi​⋅vj​​),outi​=∑j​αij​kj​

What happens when this layer is trained?

Hints

Solve it to unlock the solution

Once you get it right, the reasoning behind the answer shows up here.

Select all that apply.