4
$\begingroup$

When GPT-2 is fine-tuned for text classification (positive vs. negative), the head of the model is a linear layer that takes the LAST output embedding and outputs 2 class logits. I still can't grasp why this works. If GPT is pre-trained on predicting the next token (and it is) given a some previous sequence, then HOW can a linear layer guess the overall rating of the sequence based only on the embedding of one last output word? I've seen some explanations, but none of them were satisfying. They boiled down to the idea that the last token somehow packs the information about the entire preceding sequence. How can this be? If an embedding maps to a word, then I don't see how this embedding can contain information about the entire sequence.

$\endgroup$

1 Answer 1

4
$\begingroup$

For GPT models (or autoregressive in general) only last embedding is predicted based on the entire sequence, so it makes sense why last token is selected instead of any other. So the question seems to be does last embedding have information about whole sentence/text. I think that your intuition is accurate, but the question is if only linear layer is trained during fine tuning or is it trained jointly with GPT. If its trained jointly then the problem dissapears as the network learns to predict embeddings that describe more of entire sentence instead of describing single token.

$\endgroup$
2
  • $\begingroup$ So is it true that during fine-tuning GPT for text classification we do not just train the linear layer attached to the last embedding (with the transformer block parameters frozen), but all the parameters? I kind of know the answer by now, because it wouldn't be called fine-tuning if the transformer blocks were frozen. $\endgroup$ Jul 8, 2022 at 9:48
  • $\begingroup$ Yes, but what about prompt tuning, or adapters, or any parameter-efficient training procedures? with GPT-like models, prompt tuning is usually done to generate the following texts, not for classification task, so this issue does not occur. But if you want to do prompt tuning with GPT for classification task, then the OP question is very much relevant! $\endgroup$
    – xtof54
    Nov 3, 2022 at 8:59

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.