Sets, shapes and definitions

X∈RB×T×dX \in \mathbb{R}^{B \times T \times d} Tensor shapes

ℝ with a superscript of sizes joined by × declares an array’s shape: ℝ^{B×T×d} is a 3-axis tensor.

In ML papers

X∈Rn×dX \in \mathbb{R}^{n \times d} says XX is an array of real numbers with shape (n,d)(n, d): nn rows and dd columns. Each ×\times separates one axis from the next, so RB×T×d\mathbb{R}^{B \times T \times d} is a three-axis tensor: batch size BB, sequence length TT, model width dd.

Common letters: BB batch, TT or nn or LL sequence length, dd or dmodeld_{\text{model}} width, hh heads, dkd_k per-head key size, ∣V∣|\mathcal{V}| vocabulary. Writing the shape of each term next to a formula is the fastest way to check it: in a product the inner sizes must match, and the outer ones give the result.

How to type it

LaTeXShows
\mathbb{R}^{n \times d}Rn×d\mathbb{R}^{n \times d}
\mathbb{R}^{B \times T \times d}RB×T×d\mathbb{R}^{B \times T \times d}

A worked example

Q∈RT×dk, K∈RT×dk  ⇒  QK⊤∈RT×TQ \in \mathbb{R}^{T \times d_k},\ K \in \mathbb{R}^{T \times d_k} \;\Rightarrow\; QK^\top \in \mathbb{R}^{T \times T}

With T=4T = 4 tokens and dk=64d_k = 64, the attention scores form a 4×44 \times 4 grid, one per query-key pair.

Common confusions

Related

W∈Rd×kW \in \mathbb{R}^{d \times k}Real numbers (ℝ) and shapesRn×d\mathbb{R}^{n \times d}Times (cross)x∈Rd\mathbf{x} \in \mathbb{R}^dElement ofW∈Rm×n\mathbf{W} \in \mathbb{R}^{m \times n}Bold uppercase (matrix)

Decode this example →