Papers · Architectures and attention · 2020

An Image is Worth 16x16 Words: Transformers for Image Recognition at Scale

Alexey Dosovitskiy, Lucas Beyer, Alexander Kolesnikov and others

The notation of the ViT paper, explained: its 8 displayed equations, then every symbol it uses, grouped by category and shown the way the paper writes it.

Read the paper on arXiv

Read from arXiv's HTML version: 8 displayed equations and 124 pieces of inline math. 25 symbols and constructs from the catalog, read as attention and transformers.

The paper's displayed equations

Open any of them in the decoder for a symbol-by-symbol reading.

  1. (1)
    z0=[xclass; xp1E; xp2E;⋯ ; xpNE]+Epos,E∈R(P2⋅C)×D, Epos∈R(N+1)×D\mathbf{z}_{0} =[\mathbf{x}_{\text{class}};\,\mathbf{x}^{1}_{p}\mathbf{E};\,\mathbf{x}^{2}_{p}\mathbf{E};\cdots;\,\mathbf{x}^{N}_{p}\mathbf{E}]+\mathbf{E}_{pos}, \mathbf{E}\in\mathbb{R}^{(P^{2}\cdot C)\times D},\,\mathbf{E}_{pos}\in\mathbb{R}^{(N+1)\times D}
    Decode →
  2. (2)
    z′ℓ=MSA⁡(LN⁡(zℓ−1))+zℓ−1,ℓ=1…L\mathbf{z^{\prime}}_{\ell} =\operatorname{MSA}(\operatorname{LN}(\mathbf{z}_{\ell-1}))+\mathbf{z}_{\ell-1}, \ell=1\ldots L
    Decode →
  3. (3)
    zℓ=MLP⁡(LN⁡(z′ℓ))+z′ℓ,ℓ=1…L\mathbf{z}_{\ell} =\operatorname{MLP}(\operatorname{LN}(\mathbf{z^{\prime}}_{\ell}))+\mathbf{z^{\prime}}_{\ell}, \ell=1\ldots L
    Decode →
  4. (4)
    y=LN⁡(zL0)\mathbf{y} =\operatorname{LN}(\mathbf{z}_{L}^{0})
    Decode →
  5. (5)
    [q,k,v]=zUqkvUqkv∈RD×3Dh,[\mathbf{q},\mathbf{k},\mathbf{v}] =\mathbf{z}\mathbf{U}_{qkv} \mathbf{U}_{qkv} \in\mathbb{R}^{D\times 3D_{h}},
    Decode →
  6. (6)
    A=softmax⁡(qk⊤/Dh)A∈RN×N,A =\operatorname{softmax}\left(\mathbf{q}\mathbf{k}^{\top}/\sqrt{D_{h}}\right) A \in\mathbb{R}^{N\times N},
    Decode →
  7. (7)
    SA⁡(z)=Av .\operatorname{SA}(\mathbf{z}) =A\mathbf{v}\,.
    Decode →
  8. (8)
    MSA⁡(z)=[SA⁡1(z);SA⁡2(z);⋯ ;SA⁡k(z)] UmsaUmsa∈Rk⋅Dh×D\operatorname{MSA}(\mathbf{z}) =[\operatorname{SA}_{1}(z);\operatorname{SA}_{2}(z);\cdots;\operatorname{SA}_{k}(z)]\,\mathbf{U}_{msa} \mathbf{U}_{msa}\in\mathbb{R}^{k\cdot D_{h}\times D}
    Decode →

Famous equations in this paper

Symbols, by category

Most used first. The examples are written as the paper writes them.

Notation conventions

  1. NN, zz, LL

    Italic letters (variables) 38 uses

    A plain italic letter is a variable; conventions say what kind (x input, y target, W weights…).

  2. z0\mathbf{z}_{0}, xclass\mathbf{x}_{\text{class}}, xp1\mathbf{x}^{1}_{p}

    Subscript (index or label) 36 uses

    A subscript picks an element (xᵢ), a time step (h_t), a named copy (W_q), or the parameters (p_θ).

  3. xp1\mathbf{x}^{1}_{p}, xp2\mathbf{x}^{2}_{p}, xpN\mathbf{x}^{N}_{p}

    Superscript (power or label) 27 uses

    Usually a power (x² = x·x), but a capital or a word up there is often just a label (W^Q).

  4. ℓ\ell

    Loss (ℒ) 8 uses

    The loss: the number training tries to make small. Also written L, J(θ) or ℓ.

  5. ⋯\cdots, …\ldots

    Dots (ellipsis) 4 uses

    “And so on”: continue the pattern.

  6. 5∗5^{*}, ∗\ast

    Star (optimal) 2 uses

    As a superscript, the optimal value: θ* is the best θ. Between two terms, convolution.

  7. kvkv

    Multi-letter names 1 use

    A run of italic letters like pos or model is usually one name, not a product of single letters.

Greek letters

  1. β\beta

    Beta 2 uses

    Usually a decay rate (Adam’s β₁, β₂), a shift parameter in normalization, or a weight on a loss term.

Vectors and matrices

  1. z\mathbf{z}, x\mathbf{x}, y\mathbf{y}

    Bold lowercase (vector) 30 uses

    A bold lowercase letter is a vector: a list of numbers.

  2. ×\times

    Times (cross) 20 uses

    Usually the “by” in a shape (n × d); also plain multiplication or a cross product.

  3. ⋅\cdot

    Centre dot 14 uses

    A dot product between vectors, plain multiplication between numbers, or an empty slot f(·).

  4. E\mathbf{E}, U\mathbf{U}

    Bold uppercase (matrix) 11 uses

    A bold capital letter is a matrix (or a higher-order tensor).

  5. KK

    Q, K, V (query, key, value) 3 uses

    In attention: queries Q, keys K and values V, each a matrix with one row per token.

  6. k⊤\mathbf{k}^{\top}

    Transpose 1 use

    Swap rows and columns. xᵀy is a dot product; xyᵀ is an outer product.

Calculus and gradients

  1. z′z^{\prime}

    Prime 3 uses

    Either a derivative, f′(x), or simply "another one": x′ is a second sample, s′ the next state.

Probability and statistics

  1. pp, PP, qq

    Probability p(x) 18 uses

    A probability or probability density; p is usually the true or model distribution, q an approximation.

  2. ;;

    Semicolon (parameterized by) 7 uses

    In p(x; θ), the semicolon separates the variable x from fixed parameters θ.

Functions and operators

  1. ±\pm

    Plus or minus 27 uses

    Both signs at once: a ± b means a + b and a − b. In results tables, a mean and its spread.

  2. MLP⁡\operatorname{MLP}

    Feed-forward network (FFN, MLP) 1 use

    A small network applied to each position: a linear layer, an activation, and another linear layer.

  3. softmax⁡\operatorname{softmax}

    Softmax 1 use

    Turns a vector of scores into probabilities: exponentiate each, then divide by the total.

  4. Dh\sqrt{D_{h}}

    Square root 1 use

    The square root. In attention, dividing by √d_k keeps dot products at a sensible scale.

  5. tanh⁡\tanh

    Hyperbolic tangent 1 use

    An S-shaped activation squashing any number into (−1, 1).

Sets, shapes and definitions

  1. ∈\in

    Element of 8 uses

    “Is in” or “belongs to”: x ∈ S says x is a member of the set S.

  2. R(P2⋅C)×D\mathbb{R}^{(P^{2}\cdot C)\times D}, R(N+1)×D\mathbb{R}^{(N+1)\times D}, RD×3Dh\mathbb{R}^{D\times 3D_{h}}

    Tensor shapes 8 uses

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

  3. {−1,1}\{-1,1\}

    Set braces 1 use

    A set: a collection of items. {x | condition} is every x that satisfies the condition.

2 things the catalog has no entry for yet
  • SA⁡\operatorname{SA} SA 4
  • MSA⁡\operatorname{MSA} MSA 2

Formulas from arXiv's HTML version of the paper, © their authors; the explanations are this site's. Title and authors as arXiv lists them.

More architectures and attention papers