Self-Attention

0.0(0)
Studied by 0 people
call kaiCall Kai
Locked
learnLearn
examPractice Test
spaced repetitionSpaced Repetition
heart puzzleMatch
flashcardsFlashcards
GameKnowt Play
Card Sorting

1/118

flashcard set

Earn XP

Last updated 6:58 AM on 8/5/26
Name
Mastery
Learn
Test
Matching
Spaced
Call with Kai
Chat

No analytics yet

Send a link to your students to track their progress

119 Terms

1
New cards

What is the goal of self-attention?

To compute a new representation of each token by allowing it to incorporate information from every other token in the sequence.

2
New cards
3
New cards

Why can't a token representation be computed independently in language?

Because the meaning of a token often depends on the surrounding context (e.g.

4
New cards
5
New cards

What is the input to a self-attention layer?

A sequence of token embeddings X=[x₁

6
New cards
7
New cards

What is the dimensionality of a token embedding?

Each embedding xᵢ belongs to ℝ^(d_model).

8
New cards
9
New cards

How is the Query vector computed?

Q = XW_Q.

10
New cards
11
New cards

How is the Key vector computed?

K = XW_K.

12
New cards
13
New cards

How is the Value vector computed?

V = XW_V.

14
New cards
15
New cards

What are W_Q

W_K and W_V?

16
New cards
17
New cards

Why are three different projection matrices used instead of one?

Because the model must solve three different optimization problems: deciding what to look for

18
New cards
19
New cards

What are the dimensions of W_Q?

W_Q ∈ ℝ^(d_model × d_k).

20
New cards
21
New cards

Are W_Q

W_K and W_V initialized with meaningful values?

22
New cards
23
New cards

Does the token embedding itself contain Query

Key and Value?

24
New cards
25
New cards

Why can the same embedding produce three different vectors?

Because it is multiplied by three different matrices (W_Q

26
New cards
27
New cards

What does the attention score measure?

The compatibility between one token's Query and another token's Key.

28
New cards
29
New cards

How is the attention score computed?

score(i

30
New cards
31
New cards

Why is the dot product used in attention?

Because it measures similarity or compatibility between two vectors in the learned space.

32
New cards
33
New cards

Why is the attention score divided by √d_k?

To prevent large dot products from making the Softmax saturate and producing tiny gradients.

34
New cards
35
New cards

What is the formula for scaled dot-product attention?

Attention(Q

36
New cards
37
New cards

What does the Softmax operation produce?

A probability distribution over all tokens.

38
New cards
39
New cards

What properties do attention weights satisfy?

Each weight is non-negative and all weights sum to 1.

40
New cards
41
New cards

How is the output representation computed?

As the weighted sum of all Value vectors.

42
New cards
43
New cards

Why is the output a weighted sum of Values instead of Keys?

Because Values contain the information to propagate after attention weights have been determined.

44
New cards
45
New cards

Do Query

Key and Value vectors have intrinsic meanings?

46
New cards
47
New cards

Why do people describe Query as 'What am I looking for?' Because it behaves that way after training

not because the vector explicitly contains a question.

48
New cards
49
New cards

Why do people describe Key as 'What information do I contain?' Because it behaves like a descriptor that other Query vectors compare against.

50
New cards
51
New cards

Why do people describe Value as 'The information to transfer'?

Because it is the only vector multiplied by the attention weights and propagated to the next layer.

52
New cards
53
New cards

What determines the meaning of W_Q

W_K and W_V?

54
New cards
55
New cards

Do the names Query

Key and Value matter mathematically?

56
New cards
57
New cards

What would happen if we renamed Query

Key and Value to A

58
New cards
59
New cards

What determines the role of Query?

Its output is used only on the left side of the dot product QKᵀ.

60
New cards
61
New cards

What determines the role of Key?

Its output is used only on the right side of the dot product QKᵀ.

62
New cards
63
New cards

What determines the role of Value?

Its output is used only after the attention weights have been computed.

64
New cards
65
New cards

Why can't Query become a Value vector?

Because Query disappears after computing attention scores and is never propagated to the next layer.

66
New cards
67
New cards

Why can't Key become a Value vector?

Because Key is only used to compute attention scores and is discarded afterward.

68
New cards
69
New cards

Why can't Value determine which tokens receive attention?

Because Value is not involved in computing the attention scores.

70
New cards
71
New cards

Which matrices influence the attention weights?

Only W_Q and W_K.

72
New cards
73
New cards

Which matrix influences the information that is transmitted?

Only W_V.

74
New cards
75
New cards

If the model attends to the wrong token

which matrices receive the strongest corrective gradients?

76
New cards
77
New cards

If the model attends to the correct token but extracts poor information

which matrix receives the strongest corrective gradients?

78
New cards
79
New cards

How does gradient descent know that W_Q should become a Query matrix?

It doesn't. W_Q specializes because its output only influences attention scores.

80
New cards
81
New cards

How does gradient descent know that W_V should become a Value matrix?

It doesn't. W_V specializes because its output only influences the transmitted information.

82
New cards
83
New cards

What does gradient descent optimize?

The model's loss function by adjusting parameters in the direction that reduces prediction error.

84
New cards
85
New cards

What is backpropagation?

The algorithm that computes how every parameter contributed to the loss using the chain rule.

86
New cards
87
New cards

What does ∂L/∂W_Q represent?

How changing W_Q would affect the loss.

88
New cards
89
New cards

What does ∂L/∂W_K represent?

How changing W_K would affect the loss.

90
New cards
91
New cards

What does ∂L/∂W_V represent?

How changing W_V would affect the loss.

92
New cards
93
New cards

Why are the gradients for W_Q

W_K and W_V different?

94
New cards
95
New cards

What mathematical rule allows gradients to flow backward through the network?

The chain rule of calculus.

96
New cards
97
New cards

Why does specialization emerge naturally?

Because each matrix repeatedly receives gradients corresponding only to its architectural role.

98
New cards
99
New cards

Does the transformer explicitly encode 'look for nouns' or 'find verbs' in Query vectors?

No. Such behaviors emerge because they minimize prediction loss.

100
New cards