Spam classification decides whether an email or message is spam or legitimate. A pretrained GPT model learns this task through supervised fine-tuning rather than instruction prompting alone. section 1.1 section 6.4
Adapt the model by replacing its vocabulary-sized output layer with a two-class head for spam and not spam. Freeze most parameters, then train the new head together with the final transformer block and final LayerNorm. section 6.5
The classification flow is:
- Load pretrained GPT-2 weights into the GPTModel and verify that ordinary text generation remains coherent. section 6.4
- Tokenize each message and pass the resulting sequence through the transformer. section 6.5
- Use the final token representation, which has access to all preceding tokens under causal attention, to produce two logits. section 6.5
Worked tensor flow
For the four-token input “Do you have time,” GPT-2 small produces an output shaped [1, 4, 2]. Selecting the final row yields two class scores, such as [-3.5983, 3.9902], for the spam decision. section 6.5
Figure 6.9 Adapting a GPT model for spam classification by altering its architecture. Initially, the model’s linear output layer mapped 768 hidden units to a vocabulary of 50,257 tokens. To detect spam, we replace this layer with a new output layer that maps the same 768 hidden units to just two classes, representing “spam” and “not spam.”
Use the architecture diagram to compare GPT’s original vocabulary projection with the two-class spam output layer. section 6.5
