CoolFace
Modelpublic

aamoshdahal/email-phishing-distilbert-finetuned

sourceHugging Faceupdated 1y agoView on Hugging Face
2likes798downloads
Model Card

๐Ÿ“ง Model Card for aamoshdahal/email-phishing-distilbert-finetuned

This model is a fine-tuned version of DistilBERT (distilbert-base-uncased) trained specifically for phishing email detection. It classifies email content into two categories: phishing and legitimate.

The model was trained using a `Phishing Email Dataset` and evaluated against the `cybersectony/PhishingEmailDetectionv2.0` dataset.

It is optimized for:

  • โ€”High recall to catch most phishing attempts
  • โ€”High precision to reduce false positives
  • โ€”Fast inference via the lightweight DistilBERT architecture
  • โ€”Interpretability, with support for token-level explanations using `transformers-interpret`

This model is ideal for security tools, email scanning systems, awareness training platforms, and research on adversarial phishing attacks.

Model Details

Model Description

This is a fine-tuned DistilBERT model trained to classify email content as either phishing or legitimate. It was developed as part of a cybersecurity research project to detect phishing attempts in email messages using finetuned transformer model.

  • โ€”Developed by: @aamoshdahal
  • โ€”Model type: DistilBERT (Transformer-based sequence classifier)
  • โ€”Language(s): English
  • โ€”Finetuned from model: distilbert-base-uncased

Intended Uses & Users

This model is intended to be used as a lightweight and reliable phishing email detector. It can be integrated into:

  • โ€”Email clients or gateways to filter phishing emails in real time
  • โ€”Security software or firewalls as an additional phishing classifier
  • โ€”Educational tools for training users to recognize phishing attempts
  • โ€”Research environments to study adversarial or evolving phishing tactics
Foreseeable Users:
  • โ€”Cybersecurity professionals
  • โ€”Software developers integrating NLP into email platforms
  • โ€”Researchers working on phishing detection
Foreseeable Impact:
  • โ€”Improved early detection of phishing attacks
  • โ€”Reduced exposure to credential theft and fraud
  • โ€”Increased public understanding of phishing strategies

๐Ÿš€ How to Get Started with the Model

You can use the code snippet below to quickly load the fine-tuned model and make predictions on any email content:

from transformers import AutoTokenizer, AutoModelForSequenceClassification
import torch
from transformers_interpret import SequenceClassificationExplainer

# Load the model and tokenizer from Hugging Face Hub
model_id = "aamoshdahal/email-phishing-distilbert-finetuned"
tokenizer = AutoTokenizer.from_pretrained(model_id)
model = AutoModelForSequenceClassification.from_pretrained(model_id)

# Set device (GPU if available)
device = torch.device("cuda" if torch.cuda.is_available() else "cpu")
model.to(device)
model.eval()

# Example email for prediction
email = \"\"\"Dear user,

We detected suspicious activity on your account. Please verify your identity immediately by clicking the link below to avoid suspension.

[Phishing Link Here]

Thank you,
Security Team\"\"\"

# Tokenize and prepare the input
encoded_input = tokenizer(email, return_tensors='pt', truncation=True, padding=True).to(device)

# Make prediction
with torch.no_grad():
    outputs = model(**encoded_input)
    probs = torch.nn.functional.softmax(outputs.logits, dim=1)

# Output prediction
labels = ["legitimate", "phishing"]
pred_label = labels[probs.argmax()]
confidence = probs.max().item()

print(f"Prediction: {pred_label} ({confidence:.2%} confidence)")

explainer = SequenceClassificationExplainer(model=model, tokenizer=tokenizer)
word_attributions = explainer(email, class_name="LABEL_0")
explainer.visualize()

๐Ÿ‹๏ธโ€โ™‚๏ธ Training Details

๐Ÿ“ฆ Training Data

The model was fine-tuned on a balanced phishing email dataset compiled from multiple public sources, including:

  • โ€”Enron Email Dataset
  • โ€”CEAS 2008 Phishing Corpus
  • โ€”Ling-Spam Dataset
  • โ€”SpamAssassin
  • โ€”Nazario Phishing Emails
  • โ€”Nigerian Fraud Email Dataset

These were aggregated and preprocessed via the Phishing Email Dataset on Kaggle. Each data entry includes a combined text_combined field, which concatenates the subject line, body text, sender address, and timestamp to provide full context for classification.


โš™๏ธ Training Procedure

This model was fine-tuned using the Hugging Face ๐Ÿค— Trainer API with the following configuration:

  • โ€”Base model: distilbert-base-uncased
  • โ€”Architecture: Transformer-based sequence classifier (DistilBertForSequenceClassification)
  • โ€”Epochs: 3
  • โ€”Batch size: 16
  • โ€”Learning rate: 2e-5
  • โ€”Weight decay: 0.01
  • โ€”Evaluation strategy: Per epoch
  • โ€”Monitoring: All metrics logged via Weights & Biases (W&B)

The model was trained using a Tesla A100 GPU (40GB VRAM) on Google Colab Pro.

Preprocessing
  • โ€”Duplicate and null record removal
  • โ€”Lowercasing and whitespace cleanup
  • โ€”Tokenization using DistilBertTokenizer
  • โ€”Label encoding (0 = legitimate, 1 = phishing)
  • โ€”Random Undersampling to ensure class balance

๐Ÿ“Š Evaluation Results

For updated results and runs check this public wandb project. Full Report

The fine-tuned DistilBERT model was evaluated on a test dataset containing both phishing and legitimate emails. Below is a summary of its performance compared to baseline models (raw DistilBERT and raw BERT):

๐Ÿ“ˆ Fine-Tuned DistilBERT (Best Performing)

EpochTraining LossValidation LossAccuracyPrecisionRecallF1 ScoreROC AUC
10.03230.02430.99360.99160.99610.99390.9996
20.00830.02970.99380.99680.99120.99400.9998
30.00440.02750.99510.99590.99470.99530.9997
  • โ€”Test Set Summary:
  • โ€”Accuracy: 96.62%
  • โ€”Precision: 95.90%
  • โ€”Recall: 97.46%
  • โ€”F1 Score: 96.67%
  • โ€”ROC AUC: 0.9953

โš ๏ธ Raw DistilBERT (Untrained)

  • โ€”Accuracy: 49.57%
  • โ€”Precision: 0.00%
  • โ€”Recall: 0.00%
  • โ€”F1 Score: 0.00
  • โ€”ROC AUC: 0.5694

โš ๏ธ Raw BERT (Untrained)

  • โ€”Accuracy: 49.57%
  • โ€”Precision: 0.00%
  • โ€”Recall: 0.00%
  • โ€”F1 Score: 0.00
  • โ€”ROC AUC: 0.4984