Views
No views yet
| Property | Value |
|---|---|
| Base Model | openai-community/gpt2 (124M parameters) |
| Task | Binary Text Classification (Spam vs Not Spam) |
| Framework | Hugging Face Transformers (PyTorch) |
| Training Approach | Freezing + Selective Unfreezing |
out_head = nn.Linear(768, 2) classification headmodel.h[-1])model.ln_f)out_head)| Metric | Score |
|---|---|
| Test Accuracy | ~95% |
| Validation Accuracy | ~95%+ |
1from transformers import pipeline
2# Load the model directly via pipeline
3classifier = pipeline("text-classification", model="mustafaege/spam-detector-gpt2-hf")
4# Test with spam message
5result = classifier("Congratulations! You've won a free prize! Click here now!")
6print(result)
7# Output: [{'label': 'LABEL_1', 'score': 0.98}]
8# Test with normal message
9result = classifier("Hey, are we still meeting tomorrow?")
10print(result)
11# Output: [{'label': 'LABEL_0', 'score': 0.95}]1from transformers import GPT2Model, GPT2Tokenizer
2import torch
3import torch.nn as nn
4# Load model and tokenizer
5model_name = "mustafaege/spam-detector-gpt2-hf"
6tokenizer = GPT2Tokenizer.from_pretrained(model_name)
7model = GPT2Model.from_pretrained(model_name)
8# Add classification head (if not saved with it)
9model.out_head = nn.Linear(768, 2)
10# Prepare input
11text = "Free prize! Click here now!"
12inputs = tokenizer(text, return_tensors="pt", truncation=True, max_length=128)
13# Get last token hidden state
14outputs = model(**inputs)
15last_token_hidden = outputs.last_hidden_state[:, -1, :]
16# Get prediction
17logits = model.out_head(last_token_hidden)
18prediction = torch.argmax(logits, dim=-1)
19print("SPAM" if prediction.item() == 1 else "NOT SPAM")LABEL_0: Not Spam (ham)LABEL_1: Spammodel.safetensors - Model weightsconfig.json - Model configurationvocab.json, merges.txt - Tokenizer filestokenizer_config.json - Tokenizer configurationspecial_tokens_map.json - Special tokens mappingtraining_plots.png for loss and accuracy curves during training.