Shape Notation and Axis Conventions
A tensor shape is usually written as a tuple of axis sizes.
(32, 10)
(8, 28, 28)
(4, 12, 64)
The numbers alone are not enough. A shape becomes meaningful only when you know what each axis represents.
(32, 10) 32 examples, 10 features
(8, 28, 28) 8 images, each 28 by 28
(4, 12, 64) 4 sequences, 12 positions, 64 features per position
Different libraries and domains sometimes use different axis orders. For example, image data may be written as:
(batch, height, width, channels)
or:
(batch, channels, height, width)
Neither order is morally better. What matters is consistency.
Batch-first convention
In this course, early chapters usually use batch-first shapes:
(batch, features)
(batch, height, width)
(batch, sequence_length, features)
This convention keeps the first question simple: how many examples are moving through the model together?
Later, we will point out when a different convention appears.
A tensor has shape (16, 20, 8) and means (batch, positions, features). How many positions does each example have?
Compute it first, then check your number.
HintMatch names to numbers
Align (batch, positions, features) with (16, 20, 8).
SolutionWork it out
The shape is (16, 20, 8). The second axis is positions, so each example
has 20 positions.
A tensor has shape (4, 12, 64) and means (batch, sequence_length, hidden_features). What is the hidden feature size?
Compute it first, then check your number.
HintLook at the last axis
The axis names and sizes are in the same order.
SolutionWork it out
The last axis is hidden_features, and the last number in the shape is
64.