X∈Rm×nX \in \mathbb{R}^{m \times n}

Matrix — a table of numbers

A rectangular table of numbers, with two axes: rows and columns. An m×n matrix has m rows and n columns. Written as a capital letter, such as W.

A matrix has two axes, so two indices pick one entry: XijX_{ij} is row ii, column jj. Its shape is always said rows first: R3×4\mathbb{R}^{3 \times 4} is 3 rows by 4 columns, 12 numbers in all.

Matrices play two roles in a transformer:

  • Data. A sentence of NN tokens, each a vector of width dmodeld_{\text{model}}, is stacked into an N×dmodelN \times d_{\text{model}} matrix, one token per row.
  • Weights. A learned WW turns vectors of one width into another by matrix multiplication.

In PyTorch a 3×4 matrix has shape (3, 4).

Example

X=[102531040221]∈R3×4  ⟹  X23=0X = \begin{bmatrix} 1 & 0 & 2 & 5 \\ 3 & 1 & 0 & 4 \\ 0 & 2 & 2 & 1 \end{bmatrix} \in \mathbb{R}^{3 \times 4} \;\Longrightarrow\; X_{23} = 0

Row 2, column 3. Each row could be one token's vector.

Where the course uses it

Related terms