Token embedding (machine learning): Difference between revisions
Close the unbalanced inline math delimiter and correct the dot-product index (via update-page on MediaWiki MCP Server) |
Harmonise notation: token set becomes script T, embedding dimension n becomes d, so that T means sequence length and d the width throughout (via update-page on MediaWiki MCP Server) |
||
| Line 5: | Line 5: | ||
== Embedding and unembedding [[function]]s == | == Embedding and unembedding [[function]]s == | ||
Let $t_i \in T$ be [[token (machine learning)|token]]s obtained from [[tokenisation (machine learning)|tokenisation]] of raw data. | Let $t_i \in \mathcal{T}$ be [[token (machine learning)|token]]s obtained from [[tokenisation (machine learning)|tokenisation]] of raw data. | ||
Let $\mathbb{E}\equiv \mathbb{R}^ | Let $\mathbb{E}\equiv \mathbb{R}^d$ be a [[vector space]]. | ||
Then '''vector embedding function''' | Then '''vector embedding function''' | ||
$$ | $$ | ||
\operatorname{E}: T \to \mathbb{E}\\ | \operatorname{E}: \mathcal{T} \to \mathbb{E}\\ | ||
\forall t_i \in T: t_i \mapsto \vec{e}_i | \forall t_i \in \mathcal{T}: t_i \mapsto \vec{e}_i | ||
$$ | $$ | ||
$\mathbb{E}$ is then known as the | $\mathbb{E}$ is then known as the $d$-dimensional '''embedding space''' of $\operatorname{E}$, which contains '''embedding vectors''' $\vec e_i$. | ||
Similarly, | Similarly, | ||
$$ | $$ | ||
\operatorname{U}: \mathbb{E} \to T \\ | \operatorname{U}: \mathbb{E} \to \mathcal{T} \\ | ||
\forall \vec e_i \in \mathbb{E}: \vec e_i \mapsto t_i | \forall \vec e_i \in \mathbb{E}: \vec e_i \mapsto t_i | ||
$$ | $$ | ||
Revision as of 15:43, 11 November 2026



Embedding and unembedding functions
Let $t_i \in \mathcal{T}$ be tokens obtained from tokenisation of raw data.
Let $\mathbb{E}\equiv \mathbb{R}^d$ be a vector space.
Then vector embedding function
$$\begin{gathered} \operatorname{E}: \mathcal{T} \to \mathbb{E}\\ \forall t_i \in \mathcal{T}: t_i \mapsto \vec{e}_i \end{gathered}$$
$\mathbb{E}$ is then known as the $d$-dimensional embedding space of $\operatorname{E}$, which contains embedding vectors $\vec e_i$.
Similarly,
$$\begin{gathered} \operatorname{U}: \mathbb{E} \to \mathcal{T} \\ \forall \vec e_i \in \mathbb{E}: \vec e_i \mapsto t_i \end{gathered}$$
is the unembedding function.
Matrix representation
Embedding matrix
Let $\mathbf{W}_E \in \mathbb{R}^{|\mathcal{V}| \times n}$ be a vector embedding matrix.
$$ \vec{e}_i = \mathbf{W}_E[t_i]. $$
Unembedding matrix
Let $\vec o$ denote the output vector.
Let $\mathbf{W}_U \in \mathbb{R}^{n \times |\mathcal{V}|}$ be a vector unembedding matrix.
$$ \mathrm{logits} = \vec o \mathbf{W}_U. $$
Frequently, one sets $\mathbf{W}_U=\mathbf{W}_E^T$, a practice known as weight-tying.