Tied vocabulary projection
×reuses weights
Project each normalized feature vector into vocabulary logits.
- in
- [B batch, T positions, 768 d]
- out
- [B batch, T positions, 50257 vocabulary]
Parameters
Reuses Token embedding: weights are counted there, with no additional parameter ownership here.
Explanation
Each entry scores one vocabulary token as the next token for its position. The softmax and the choice of token happen outside the model.
Each vocabulary row of WTE serves both the input lookup and, transposed, the output scoring.
Sources
In codetf.matmul(h_flat, wte, transpose_b=True)
Direct evidence
The original graph explicitly multiplies by wteᵀ.
model.py 169–172 ↗ · openai/gpt-2 @ 9b63575ef427
Excerpt
h_flat = tf.reshape(h, [batch*sequence, hparams.n_embd])
logits = tf.matmul(h_flat, wte, transpose_b=True)
logits = tf.reshape(logits, [batch, sequence, hparams.n_vocab])The maintained model declares lm_head.weight tied to transformer.wte.weight and applies the vocabulary projection without a bias.
modeling_gpt2.py 637–698 ↗ · huggingface/transformers @ 71c6f699ac9b
Excerpt
_tied_weights_keys = {"lm_head.weight": "transformer.wte.weight"}… lines 639–641 omitted …
self.transformer = GPT2Model(config)
self.lm_head = nn.Linear(config.n_embd, config.vocab_size, bias=False)… lines 644–694 omitted …
hidden_states = transformer_outputs.last_hidden_state… lines 696–697 omitted …
logits = self.lm_head(hidden_states[:, slice_indices, :])