c21 · E2

Derive: Attention, Images and Sequences

c21.E2.1E2 · expression

A stack of one-dimensional convolutional layers, each with kernel width and stride one, pads its input so that every layer returns a row of the same length.

(a) Show that one output of the stack can see input positions. Check the counts that section 21.1 gives for two and three layers of width three.

(b) How many layers of width three does a row of 1000 values need before one output can see the whole row? Repeat for width five.

(c) Section 21.6 says a convolution has a path length that grows like the logarithm of the sequence length. Explain why that statement describes a stack whose layers shrink the sequence, not the stride-one stack of section 21.1. This exercise connects the two sections.

This tier asks for a derivation, so there is no automatic checker. Write your answer, then open the worked solution and compare.

c21.E2.2E2 · expression

Attention weights come from the softmax where is the score of item .

(a) Show that every weight is strictly positive when every score is finite.

(b) Compute the smallest weight for the scores 2, 1, 0, to three decimal places, and for the scores 5, 1, 0, to five decimal places.

(c) Explain why this is an edge case for the claim that attention chooses which words matter, and say what operation produces an exact zero. This exercise connects sections 21.3 and 21.4.

This tier asks for a derivation, so there is no automatic checker. Write your answer, then open the worked solution and compare.

c21.E2.3E2 · expression

A transformer block has model width and attention heads, each with key length , where . Each head computes queries, keys and values with three learned maps of shape .

(a) Show that the three maps across all heads hold weights, independent of .

(b) The concatenated head outputs are projected back with a map. Show that the attention sublayer holds weights in total.

(c) Compute the two counts for and , and explain what the result says about the claim in section 21.5 that eight heads keep the cost close to that of one full-width head.

This tier asks for a derivation, so there is no automatic checker. Write your answer, then open the worked solution and compare.

Other tiers

E1 Practise · E3 Open

Every hint opened, solution viewed and answer checked is recorded in this browser only. See Progress to export or delete it.