16/42
Part 3 of 6 · The worked exampleLearn

A bare reshape mixes positions

Now the tempting shortcut: a reshape straight to the heads' shape.

print(q.reshape(B, H, T, d))
tensor([[[[ 0,  1],
          [ 2,  3],
          [10, 11]],

         [[12, 13],
          [20, 21],
          [22, 23]]]])

A bare reshape reads the twelve numbers in order, position 0's four channels, then position 1's, then position 2's, and pours them into the new shape:

A bare reshape, on the same twelve numbers
"head 0" (3, 2)
row 001row 123row 21011
"head 1" (3, 2)
row 01213row 12021row 22223

Red rows hold the wrong position. "head 0", row 1 is the back half of position 0, and "head 1", row 0 is the back half of position 1.

The shape is right. The rows are no longer positions.