Functions and operators

Concat⁡(head1,…,headh)WO\operatorname{Concat}(\mathrm{head}_1, \dots, \mathrm{head}_h) W^O Concatenation

Join vectors end to end: a vector of length m and one of length n become one of length m + n.

In ML papers

Concat⁡(a,b)\operatorname{Concat}(\mathbf{a}, \mathbf{b}) places vectors end to end, so lengths add. Applied to matrices it joins them along the feature axis unless the paper says otherwise. Multi-head attention (Vaswani et al. 2017) concatenates the outputs of its hh heads and then projects them with WOW^O.

Papers also write concatenation with brackets: [a;b][\mathbf{a}; \mathbf{b}] (a semicolon, often meaning stacked vertically) or [a,b][\mathbf{a}, \mathbf{b}]; some use ⊕\oplus (Direct sum / XOR) or ∥\Vert. In code: torch.cat or np.concatenate.

How to type it

LaTeXShows
\operatorname{Concat}(\mathbf{a}, \mathbf{b})Concat⁡(a,b)\operatorname{Concat}(\mathbf{a}, \mathbf{b})
[\mathbf{a}; \mathbf{b}] stacked[a;b][\mathbf{a}; \mathbf{b}]
[\mathbf{a}, \mathbf{b}] side by side[a,b][\mathbf{a}, \mathbf{b}]

A worked example

Concat⁡((1,2),(3,4,5))=(1,2,3,4,5)\operatorname{Concat}\big((1, 2), (3, 4, 5)\big) = (1, 2, 3, 4, 5)

Eight heads of width 64 concatenate to a vector of width 512.

Common confusions

Equations that use it

Related

a⊕b\mathbf{a} \oplus \mathbf{b}Direct sum / XORQ,K,VQ, K, VQ, K, V (query, key, value)X∈RB×T×dX \in \mathbb{R}^{B \times T \times d}Tensor shapesp(x;θ)p(x; \theta)Semicolon (parameterized by)

Decode this example →