Token IDs Become Position-Aware Records

Integer IDs select rows from a learned token table, then matching learned position rows are added. Calculate the frozen records, derive shapes and parameters, and reject invalid vocabulary IDs or context positions.

The model receives integer IDs, not words and not one-hot vectors. An embedding lookup selects one row from a learned table E:(V,dmodel)E:(V,d_{model}) for each ID.

The chapter vocabulary is:

IDToken
0<bos>
1A
2B
3C
4D
5X
6Y
7<eos>

For input <bos> A B C, the ID tensor is [0,1,2,3][0,1,2,3]. The frozen token rows are the first four standard basis vectors, and the position table adds 0.1 to feature 1, 2, 3, or 4 at positions 0, 1, 2, or 3 respectively. The combined records are therefore

X0=[1.100001.100001.100001.1].X_0= \begin{bmatrix} 1.1&0&0&0\\ 0&1.1&0&0\\ 0&0&1.1&0\\ 0&0&0&1.1 \end{bmatrix}.

Lookup Has the Same Result as a One-Hot Product

A one-hot row for ID 2 multiplied by EE selects row 2, but implementations use direct indexed lookup. The one-hot view can explain the algebra; it should not be mistaken for the required stored input representation.

For I:(B,T)I:(B,T), lookup produces (B,T,dmodel)(B,T,d_{model}). Adding positions broadcasts P[:T]:(T,dmodel)P[:T]:(T,d_{model}) across the batch. It must not broadcast one position across every token.

Validate IDs and Length Before Lookup

Every ID must satisfy 0Ib,t<V0\le I_{b,t}<V. The sequence length must satisfy TCT\le C for this learned position table. Negative IDs, ID 8, or a fifth position are configuration errors, not unknown values that the model can infer.

The embedding contains Vdmodel=8(4)=32Vd_{model}=8(4)=32 learned entries. The position table contains Cdmodel=4(4)=16Cd_{model}=4(4)=16.

Q1. Combine one token and position row

Token A has ID 1 and embedding [0,1,0,0][0,1,0,0]. At position 1, the position row is [0,0.1,0,0][0,0.1,0,0]. What combined record enters the first block?

Compute it first, then check your number.

Hint
Add the two four-coordinate rows.
Solution
The combined record is [0,1.1,0,0][0,1.1,0,0].
Not attempted
Review

Not marked done.

Pause and reflect

In your own words, note what you understood, what remains unclear, or what you want to revisit. The note stays with this lesson.

0 of 1 exercises marked done

Review

Not marked done.