ei\mathbf{e}_i

eᵢ — a one-hot vector

Read "e i". It is a vector with a 1 in position i and 0 everywhere else: token number i, written as a vector.

ei∈{0,1}∣V∣\mathbf{e}_i \in \{0,1\}^{|V|} has ∣V∣|V| entries and a single 1, at position ii. Multiplying it by a matrix picks out row ii of that matrix: ei⊤WE=WE[i,:]\mathbf{e}_i^\top W_E = W_E[i,:].

No real implementation does that multiplication; it just reads row ii from memory (nn.Embedding in PyTorch). Writing it as a multiplication shows that the embedding step is an ordinary matrix product like every other layer. It also makes the gradient easy to see: only row ii of WEW_E gets updated.

Example

∣V∣=4,  i=2  ⟹  e2=[0,0,1,0]|V| = 4,\; i = 2 \;\Longrightarrow\; \mathbf{e}_2 = [0, 0, 1, 0]

Positions are counted from 0 here, so position 2 is the third slot.

Where the course uses it

Related terms