Embedding

Embedding · node type · Gather

Looks up a learned vector for each token id: how words, notes or categories become numbers.

Also called Lookup table, Token embedding, Gather

Figure 1. Embedding inside Classify the tone of a film review, a real model in WeightSpace. The outlined node is Embedding; select any node for its shapes and parameters.

What it does

An embedding is a table with one learned row per item in a vocabulary. Given a sequence of ids, it returns the matching rows. It is mathematically the same as multiplying a one-hot vector by a weight matrix, but far cheaper. During training, items used in similar contexts drift toward similar vectors, so distance in the embedding space starts to reflect meaning. In ONNX it is a Gather on a weight initializer. A model’s vocabulary size often makes the embedding its largest single tensor.

Formula

et = E[xt] (row xt of E ∈ RV × D)equivalently et = onehot(xt)T E

Shapes and parameters

Shapes
Table [V, D] (vocabulary, width); ids [N, T]; output [N, T, D].
Parameters
V × D. A 20,000-word table with 128 dimensions has 2,560,000 parameters; a 30,522-token BERT table with 768 dimensions has about 23.4 million.
Used for
The first layer of every text model, the token and segment tables in BERT-style models, the IMDB sentiment CNN, and speaker or style vectors in speech synthesis.

Figure 2. The typed ports of Embedding, in the same format as every model drawing. Letters such as N or C stand for any size.

In WeightSpace

Read-only in WeightSpace today. Text models in the catalog are edited at their output layer; the vectors for individual words stay as shipped.