[Batch Size, Sequence Length, Hidden Dimension], a hidden dimension of 150 defines the size of the last axis. For example, in a tensor of shape [32, 50, 150]:32 is the batch size (breadth of processing). 50 is the sequence length (number of tokens). 150 is the hidden dimension (vector length/depth of features per token).
Here is the explanation of the three dimensions in the tensor shape [32, 50, 150]:
This number represents how many independent sequences (e.g., sentences, documents, or images) the model processes simultaneously in a single step.
This number represents the number of individual items (tokens/words) within each of those 32 sequences.
This number represents the number of features used to describe each single token.
Summary Visualization: Imagine a stack of 32 books (Batch Size). Each book has 50 pages (Sequence Length). On each page, there is a detailed report with 150 distinct data points (Hidden Dimension).
1. The Formula
The head dimension is calculated by dividing the total hidden dimension ($d_{model}$) by the number of attention heads ($h$):
Head Dimension(*dk*)=Number of Heads(*h*)Hidden Dimension(*dmodel*)
• Example: If your hidden dimension is 512 and you have 8 heads, the head dimension is $512 / 8 = \mathbf{64}$.
• Constraint: The hidden dimension must be evenly divisible by the number of heads.
2. Relationship to Your Previous Example [32, 50, 150]
If we apply this to your previous tensor where the Hidden Dimension was 150:
• Suppose you choose 10 attention heads.
• The Head Dimension would be $150 / 10 = \mathbf{15}$.
• Inside the attention layer, the tensor of shape [32, 50, 150] is reshaped into [32, 50, 10, 15] (Batch, Sequence, Heads, Head Dimension).
• Each of the 10 heads independently processes a vector of length 15, not 150.