Downloads · 30 days
10
7% of all-time downloads
jamal-ibrahim/distilbert-email-spam-classifier-v1
distilbert-email-spam-classifier-v1 is a text classification model from jamal-ibrahim. Use it when you need a label for a piece of text. The card lists the license as apache-2.0.
This repository contains a fine-tuned distilbert-base-uncased model for binary classification of email messages:
Downloads · 30 days
10
7% of all-time downloads
All-time downloads
136
Public
Parameters
67M
268 MB on disk
Likes
0
Public
Click a slice to open those files.
.safetensors268 MB · 100%
From the Hugging Face model README
This repository contains a fine-tuned distilbert-base-uncased model for binary classification of email messages:
This model represents Phase 1 of a multi-stage fraud detection system. The objective of this phase is to establish a strong, reproducible, text-only baseline using a transformer architecture before integrating additional metadata and adversarial strategies in subsequent phases.
The system is designed for research, experimentation, and as a foundation for more advanced email security architectures.
Fraud detection in email communication is inherently adversarial. Attackers continuously adapt their language and techniques. Effective systems require layered defenses rather than relying on a single signal source.
Instead of immediately building a complex hybrid system, this project follows a staged engineering approach:
Phase 1 – Text-only transformer baseline
Phase 2 – Text + structured metadata (sender domain, headers, reputation signals)
Phase 3 – Adversarial and synthetic augmentation
Phase 4 – Temporal adaptation and drift monitoring
The purpose of Phase 1 is to:
This model isolates the contribution of textual semantics to fraud detection performance.
Training was conducted on the Enron Spam Dataset (public research corpus).
Preprocessing steps:
Data split strategy:
Important limitation:
The Enron dataset reflects early 2000s spam patterns and does not represent modern spear-phishing, business email compromise, or AI-generated scams.
Base model: distilbert-base-uncased
Classification head: Linear layer with 2 output neurons
Maximum sequence length: 256 tokens
Loss function: Class-weighted CrossEntropyLoss (to address imbalance)
Optimizer: AdamW
Learning rate: 2e-5
Weight decay: 0.01
Warmup: 10% of total training steps
Scheduler: Linear schedule with warmup
Mixed precision training: Enabled when GPU available
Early stopping: Validation loss monitored with patience = 2
Evaluation performed on held-out test set.
Metrics reported:
Typical performance on Enron:
F1 Score: 0.93 – 0.96
ROC-AUC: ~0.97
Threshold was optimized using validation data to maximize F1 or enforce high recall.
Fraud detection systems prioritize recall to minimize false negatives.
Manual inspection of misclassified samples revealed:
False Positives:
False Negatives:
Key observation:
Text-only transformers capture strong lexical fraud signals (urgency, financial triggers, threat language), but struggle when attackers successfully mimic legitimate structure and tone.
This validates the need for metadata integration in Phase 2.
The following analyses were conducted:
Findings:
Threshold tuning improves recall-oriented configurations.
This model is intended for:
It is not intended to function as a standalone production-grade email security system.
Production systems require:
Performance may degrade on:
Phase 2: Hybrid architecture combining DistilBERT embeddings with structured metadata features.
Phase 3: Controlled synthetic adversarial augmentation using language model-generated variants.
Phase 4: Temporal evaluation and drift detection framework.
from transformers import AutoTokenizer, AutoModelForSequenceClassification
import torch
model_name = "YOUR_USERNAME/YOUR_MODEL_NAME"
tokenizer = AutoTokenizer.from_pretrained(model_name)
model = AutoModelForSequenceClassification.from_pretrained(model_name)
text = "Urgent: Your account has been suspended. Click here to verify."
inputs = tokenizer(text, return_tensors="pt", truncation=True, padding=True, max_length=256)
with torch.no_grad():
outputs = model(**inputs)
probabilities = torch.softmax(outputs.logits, dim=1)
print("Fraud probability:", probabilities[0][1].item())
If you use this model in research, please cite:
DistilBERT: Sanh et al., 2019. DistilBERT: a distilled version of BERT.
Enron Dataset: Klimt & Yang, 2004. The Enron Corpus.