Tensor Shape Notation
Tensor shape notation records what each axis means before interpreting a formula. Many AI paper equations look simple because they hide batch, token, head, node, coordinate, or candidate axes.
A useful rule is:
Common Axes
| Symbol | Meaning | Example |
|---|---|---|
| batch size | independent examples | |
| sequence length | tokens, residues, time steps | |
| set, graph, atom, or node count | atoms, residues, graph nodes | |
| edge count | molecular bonds, contact edges | |
| channel count | image channels or feature maps | |
| feature dimension | embedding width | |
| attention heads | multi-head attention | |
| head dimension | per-head query/key/value width | |
| candidates or classes | retrieval items, labels, conformers | |
| coordinate dimension | usually for 3D coordinates |
Batch and Feature Convention
A batch of feature vectors is often:
A batch of token sequences is:
A coordinate set is:
Do not treat the last axis as always “features.” In coordinate models, the coordinate axis transforms under rotation; feature channels do not.
Operation Axes
| Operation | Typical Shape | Mixed Axis |
|---|---|---|
| Linear layer | , | feature axis |
| Self-attention | token axis through | |
| Convolution | local spatial axes | |
| GNN message passing | node features , edges | graph neighborhood |
| Pooling | node/set/token axis | |
| Pairwise distance | node pair and coordinate axes |
Attention Shape
For multi-head self-attention:
The attention logits are:
so:
Softmax is taken over the key axis , not over the batch, head, or feature axis:
Graph and Molecular Shapes
Molecular and protein models often combine graph, coordinate, and feature axes:
| Object | Shape |
|---|---|
| Atom features | |
| Bond edges | |
| Atom coordinates | |
| Residue features | |
| Protein-ligand pair features |
For batched graphs, shape is often ragged. A single tensor shape may hide a batch_index, padding mask, or packed edge list.
Broadcasting
Broadcasting should be explicit in formulas that mix learned parameters and batched data. For layer normalization:
are broadcast across and .
Checks
- What does each axis mean?
- Which axis is reduced by sum, mean, softmax, pooling, or normalization?
- Which axis is mixed by a matrix multiplication?
- Which axes are broadcast?
- Is the implementation batch-first, sequence-first, or channel-first?
- Are graph or molecular examples padded, packed, or ragged?
- Does a coordinate axis transform under rotation or translation?
- Does a reported loss average over batch, token, atom, pair, candidate, or graph units?