Three tokens have embeddings x1=(1,0), x2=(0,1) and x3=(1,1). Take Q=K=V=X (no projection matrices) and dk=2. What are the attention weights and output for token 1 using scaled dot-product attention?

Sequence models and transformers, Attention
Level L2 Elementary. Length Medium. Nature Mat Mathematical.

What's being asked

Whether you can run the three steps of self-attention (scores, softmax, weighted sum) with actual numbers.

Key idea

out1=∑ja1jvj with a1j=softmaxj(q1⋅kj/dk).

Steps

  1. Dot products with q1=(1,0): q1⋅k1=1, q1⋅k2=0, q1⋅k3=1.
  2. Scale by dk=2≈1.414: scores =(0.7071, 0, 0.7071).
  3. Exponentiate: e0.7071=2.028, e0=1, e0.7071=2.028. The sum is 5.056.
  4. Weights a1=(0.4011, 0.1978, 0.4011), which add to 1.
  5. Output =0.4011(1,0)+0.1978(0,1)+0.4011(1,1)=(0.8022, 0.5989).
  6. Token 1 attends most to itself and to the similar token 3, and least to the orthogonal token 2.

Common mistakes

How long your answer should be

Half a page with the numbers shown.

Last checked on 4 December 2026.

Read this

Previous in Sequence models and transformers: Reference: "the cat is on the mat" (6 words). Candidate 1: "the the the the the the the". Candidate 2: "the cat mat". (a) What is the clipped unigram precision of Candidate 1? (b) For Candidate 2, what are the unigram precision and the brevity penalty, so what is its unigram-only BLEU?
Next in Sequence models and transformers: A language model gives logits (2,1,0,−1) for four tokens. What are the sampling probabilities at temperature T=1, T=0.5 and T=2? What happens as T→0 and as T→∞?