Token embedding (machine learning): Difference between revisions
Fix spelling and an unclosed delimiter that broke rendering of the blockquote (via update-page on MediaWiki MCP Server) |
Close the unbalanced inline math delimiter and correct the dot-product index (via update-page on MediaWiki MCP Server) |
||
| Line 109: | Line 109: | ||
<blockquote> | <blockquote> | ||
With a weight-tied $\mathbf{W}_U, unembedding is essentially calculating the [[vector dot product]]s $\ell_i$ of output $\vec o$ with the embedding vectors $\mathbf{W}_E[i]$ for each [[token]] $t_i$ in the vocabulary. As $\vec o \cdot \mathbf{W}_E[ | With a weight-tied $\mathbf{W}_U$, unembedding is essentially calculating the [[vector dot product]]s $\ell_i$ of output $\vec o$ with the embedding vectors $\mathbf{W}_E[i]$ for each [[token]] $t_i$ in the vocabulary. As $\vec o \cdot \mathbf{W}_E[i] = \| \vec o \| \| \mathbf{W}_E[i] \| \cos \theta$, where $\theta$ is the angle between $\vec o$ and $\mathbf{W}_E[i]$, one expects $\ell_i$ to be larger when the directions of $\vec o$ and $\mathbf{W}_E[i]$ align, signifying a higher possibility the model's output predicts token $t_i$. | ||
</blockquote> | </blockquote> | ||
Revision as of 15:33, 11 November 2026



Embedding and unembedding functions
Let $t_i \in T$ be tokens obtained from tokenisation of raw data.
Let $\mathbb{E}\equiv \mathbb{R}^n$ be a vector space.
Then vector embedding function
$$\begin{gathered} \operatorname{E}: T \to \mathbb{E}\\ \forall t_i \in T: t_i \mapsto \vec{e}_i \end{gathered}$$
$\mathbb{E}$ is then known as the n-dimensional embedding space of $\operatorname{E}$, which contains embedding vectors $\vec e_i$.
Similarly,
$$\begin{gathered} \operatorname{U}: \mathbb{E} \to 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.