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

SymbolMeaningExample
batch sizeindependent examples
sequence lengthtokens, residues, time steps
set, graph, atom, or node countatoms, residues, graph nodes
edge countmolecular bonds, contact edges
channel countimage channels or feature maps
feature dimensionembedding width
attention headsmulti-head attention
head dimensionper-head query/key/value width
candidates or classesretrieval items, labels, conformers
coordinate dimensionusually 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

OperationTypical ShapeMixed Axis
Linear layer, feature axis
Self-attentiontoken axis through
Convolutionlocal spatial axes
GNN message passingnode features , edges graph neighborhood
Poolingnode/set/token axis
Pairwise distancenode 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:

ObjectShape
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?