Position embedding table

×

One learned row per absolute position, 0 through 1,023.

Epos=WPE[position_ids]{\htmlData{light=wpe}{E_{\mathrm{pos}}}}=\mathrm{WPE}[\mathrm{position\_ids}]
in
[B batch, T positions]
out
EposE_{\mathrm{pos}} [B batch, T positions, 768 d]
Parameters786,432

786,432 parameters owned by this component

ComponentCalculationParameters
table1,024 × 768786,432

Not checked against a checkpoint.

Explanation

The table has one row per position, so a sequence, cached positions included, holds at most 1,024 tokens (model.py 152).

Sources

In codetf.gather(wpe, positions_for(X, past_length))

Open pinned code ↗

Direct evidence

wpe is created alongside wte and gathered by position index.

model.py 152–157 ↗ · openai/gpt-2 @ 9b63575ef427

Excerpt
        wpe = tf.get_variable('wpe', [hparams.n_ctx, hparams.n_embd],

… lines 153–156 omitted …

        h = tf.gather(wte, X) + tf.gather(wpe, positions_for(X, past_length))

The constructor sets the position-table row count from max_position_embeddings; the lookup selects rows by position ID. The model configuration supplies the numeric count.

modeling_gpt2.py 492–577 ↗ · huggingface/transformers @ 71c6f699ac9b

Excerpt
        self.wpe = nn.Embedding(config.max_position_embeddings, self.embed_dim)

… lines 494–575 omitted …

        position_embeds = self.wpe(position_ids)