Part 3 of 5 · From vectors back to wordsLearn and do
Tie the head to the table
Tying changes how often each row of the table learns:
Predict
A rare token shows up in one batch out of a thousand. How often does its row of the head get a gradient?
It pays twice:
Fewer parameters. One V by C table instead of two. In GPT-2 small that saves 38.6 million numbers, 31% of the model.
Rare tokens learn faster. A row of the input table learns only when its token is in the batch. Shared with the head, it learns at every step.
The head has bias=False because the shared table is the whole head. GPT-2's head has no bias either.
The editor holds TiedLM, the model cut down to its token table and its head. Finish its __init__: add self.lm_head, a layer from n_embd numbers to vocab_size scores with no bias, and tie its weight to self.tok_emb.
Pick an answer above to see the rest
Instructions
1
Finish __init__: add self.lm_head, which turns an n_embd vector into vocab_size scores and shares its weight with self.tok_emb. The tests build it with vocab_size=11 and n_embd=8.