File size: 3,774 Bytes
5cf6538
81be832
 
 
5cf6538
81be832
 
 
 
 
 
 
 
 
 
 
 
5cf6538
 
81be832
5cf6538
81be832
 
5cf6538
81be832
5cf6538
81be832
 
 
 
5cf6538
81be832
5cf6538
81be832
 
5cf6538
81be832
 
 
5cf6538
81be832
5cf6538
81be832
 
5cf6538
81be832
 
 
 
5cf6538
81be832
5cf6538
81be832
 
 
 
 
5cf6538
81be832
5cf6538
 
 
81be832
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
---
license: mit
language:
- en
library_name: transformers
pipeline_tag: text-classification
tags:
- phishing
- email-security
- bert
- text-classification
base_model: bert-base-uncased
widget:
- text: "Your account has been suspended. Verify now at http://secure-login.example.ru"
  example_title: Phishing example
- text: "Reminder: the team retro is tomorrow at 10am in the Oak meeting room."
  example_title: Legitimate example
---

# BERT Email Phishing Detector

Fine-tuned [`bert-base-uncased`](https://huggingface.co/bert-base-uncased) for
binary classification of email/message text as **phishing** or **legitimate**.

## Labels

| id | label       |
|----|-------------|
| 0  | legitimate  |
| 1  | phishing    |

## Intended use

- Research and education on phishing detection.
- A component / baseline in a larger email-security pipeline.

**Not intended** as a standalone production email security gateway. Always keep
a human in the loop for high-stakes decisions, and combine with URL reputation,
sender authentication (SPF/DKIM/DMARC) and other signals.

## How to use

```python
from transformers import pipeline

clf = pipeline("text-classification", model="<your-username>/bert-phishing-detector")
clf("Verify your account now at http://secure-login.example.ru")
# [{'label': 'phishing', 'score': 0.99}]
```

## Training

- **Base model:** `bert-base-uncased`
- **Objective:** binary sequence classification (cross-entropy)
- **Max sequence length:** 256 tokens
- **Optimizer / LR:** AdamW, 2e-5, weight decay 0.01, 6% warmup
- **Epochs:** 3 (best checkpoint by validation F1)

Training code: [`src/train.py`](src/train.py) in the project repository.

## Evaluation

Fine-tuned for 3 epochs on ~65.7k emails and evaluated on an 8,207-email
held-out test split:

| Metric    | Score  |
|-----------|--------|
| Accuracy  | 0.9948 |
| Precision | 0.9956 |
| Recall    | 0.9944 |
| F1        | 0.9950 |

> These scores are very high partly because the training data (the Kaggle
> phishing-email collection) is cleanly separable. Expect lower performance on
> noisier, real-world email — validate on your own data before relying on it.

## Limitations & biases

- **Distribution shift is the big one.** The training corpus is heavily
  preprocessed (lowercased, punctuation and stop-words removed) and the
  legitimate emails skew toward early-2000s corporate mail (Enron). The model
  scores ~99% on held-out data from this same distribution, but can misclassify
  raw, modern, or very short emails (e.g. a casual "Hi team, notes attached"
  message may be flagged as phishing). For best results, feed it text
  preprocessed the same way as training, and treat the headline metrics as
  in-distribution — not a promise of real-world accuracy.
- Trained primarily on **English** text; performance on other languages is
  untested.
- Phishing tactics evolve quickly; the model can go stale and should be
  periodically retrained on fresh data.
- May produce false positives on legitimate marketing emails that share
  surface features with phishing (urgency, links, "verify" language).
- The bundled `data/sample_emails.csv` is a tiny illustrative sample. Train on a
  large, representative corpus before relying on any metric.

## Data

Bring your own labeled corpus with a `text` column and an integer `label`
column (0 = legitimate, 1 = phishing). Commonly used public sources include the
Nazario phishing corpus, the Enron email dataset (legitimate mail), SpamAssassin
public corpus, and various Kaggle phishing-email datasets. Check each dataset's
license before redistribution.

## Ethical considerations

This model classifies text and can make mistakes. Do not use it to
automatically delete mail or take irreversible actions without human review.