How to use from the
Use from the
Transformers library
# Use a pipeline as a high-level helper
from transformers import pipeline

pipe = pipeline("text-classification", model="Project-Bastion/phishing-email-classifier")
# pip install -U transformers accelerate
# Load model directly
from transformers import AutoTokenizer, AutoModelForSequenceClassification

tokenizer = AutoTokenizer.from_pretrained("Project-Bastion/phishing-email-classifier")
model = AutoModelForSequenceClassification.from_pretrained("Project-Bastion/phishing-email-classifier", device_map="auto")
Quick Links

phishing-email-classifier

Flags phishing emails from their text (subject + body). An 82M-parameter DistilRoBERTa classifier that scores above the two most-downloaded open phishing-email models on nine of twelve public phishing and spam corpora (CEAS-08, TREC-05/06/07, Nazario, Nigerian fraud, Enron, locuoco, LLM-written phishing) and within 0.004 AUROC of the best on the other three, with far fewer false alarms at the default threshold. Runs on CPU or in your browser with no server.

Try it in your browser: a static page that runs the model locally (transformers.js, ONNX int8, about 86 MB, downloaded once). The email text you paste never leaves your device.

Results

Test splits of public phishing-email benchmarks (AUROC; recall at 1% false-positive rate in brackets). All models scored with identical code on identical emails. For cybersectony's 4-class model the phishing-email logit is compared with the legitimate-email logit.

Benchmark (emails) phishing-email-classifier cybersectony/phishing-email-detection-distilbert_v2.4.1 (312k downloads) ptouch/phishing-distilbert-cyber207 (248k downloads)
CEAS_08 (3,392) 0.9999 (0.998) 0.9847 (0.610) 0.9669 (0.499)
TREC_05 (5,450) 0.9995 (0.990) 0.9856 (0.837) 0.9553 (0.666)
TREC_06 (1,607) 0.9990 (0.980) 0.9860 (0.812) 0.9445 (0.576)
TREC_07 (5,235) 0.9996 (0.998) 0.9630 (0.608) 0.8906 (0.470)
Nazario (299) 0.9995 (0.987) 0.9317 (0.081) 0.9079 (0.169)
Nigerian fraud (649) 1.0000 (1.000) 0.9897 (0.879) 0.9940 (0.968)
SpamAssassin (565) 0.9987 (0.963) 0.9976 (0.951) 0.9996 (0.982)
Enron (3,004) 0.9997 (0.996) 0.9995 (0.994) 0.9914 (0.866)
Ling (284) 0.9967 (0.957) 0.9980 (0.978) 1.0000 (1.000)
locuoco spam-ham-phish, phish vs ham (16,529) 1.0000 (1.000) 0.9686 (0.568) 0.9457 (0.057)
LLMGen-Phishing-Email-Dataset (676) 0.9968 (0.996) 0.6948 (0.089) 0.5147 (0.052)
zefang-liu/phishing-email-dataset (17,236) 0.9991 (0.979) 0.9998 (0.998) 0.9884 (0.866)

At the default threshold (margin 0) the false-positive rate on legitimate mail is 0.2% (CEAS_08), 0.3% (TREC_07) and 0.1% (locuoco), against 10.2%, 10.2% and 18.5% for cybersectony. Corpus labels are used as published: CEAS_08, TREC_05/06/07 and Enron mark spam as phishing.

Usage

import torch
from transformers import AutoTokenizer, AutoModelForSequenceClassification
repo = "Project-Bastion/phishing-email-classifier"
tok = AutoTokenizer.from_pretrained(repo); model = AutoModelForSequenceClassification.from_pretrained(repo).eval()

def phishing_margin(subject, body):
    enc = tok(f"{subject}\n{body}", truncation=True, max_length=256, return_tensors="pt")
    with torch.no_grad(): logits = model(**enc).logits[0]
    return float(logits[1] - logits[0])            # label 0 = legitimate, 1 = phishing

m = phishing_margin("Urgent: verify your account within 24 hours",
                    "We detected unusual activity on your bank account. Confirm your password and card details now at http://secure-bank-verify.example.com/login")
print(m, "PHISHING" if m > 0 else "ok")            # raise the threshold for fewer false alarms

The score is a logit margin (phishing minus legitimate); 0 corresponds to p = 0.5.

Files

onnx/model_quantized.onnx (weight-only int8, 86 MB, the demo default) and onnx/model.onnx (fp32, 329 MB) for transformers.js / onnxruntime. fp32 gives the same decisions as PyTorch on 315 checked emails; int8 gives the same decisions with a largest margin difference of 0.63.

Limits

  • Slightly behind cybersectony on zefang-liu and Ling (and behind ptouch on SpamAssassin and Ling): test on your own mail and tune the threshold before relying on it.
  • English email text only, first 256 tokens; it does not look at URLs, headers or attachments.

License and credits

Apache-2.0. Base model: distilroberta-base (Apache-2.0). Training data: locuoco/the-biggest-spam-ham-phish-email-dataset-300000 (MIT); Dizzzy0x00/LLMGen-Phishing-Email-Dataset (Apache-2.0); the Phishing Email Curated Datasets of Champa, Rabbi and Zibran (2023), Zenodo, doi:10.5281/zenodo.8339691 (CC-BY-4.0; CEAS_08, TREC_05/06/07, Nazario, Nigerian fraud, SpamAssassin, Enron, Ling), part via kudzaiprichard/aura-phishing-email-corpus. zefang-liu/phishing-email-dataset (LGPL-3.0) is used for evaluation only. Revision v1 of this repo holds the earlier weights.

Downloads last month
-
Safetensors
Model size
82.1M params
Tensor type
F32
ยท
Inference Providers NEW
This model isn't deployed by any Inference Provider. ๐Ÿ™‹ Ask for provider support

Model tree for Project-Bastion/phishing-email-classifier

Quantized
(25)
this model

Evaluation results

  • AUROC on CEAS_08 test split (3392 emails)
    self-reported
    1.000
  • AUROC on TREC_07 test split (5235 emails)
    self-reported
    1.000
  • AUROC on LLMGen-Phishing-Email-Dataset test split (676 emails)
    self-reported
    0.997