SamSec007 commited on
Commit
5a1a59b
ยท
verified ยท
1 Parent(s): 357ae7c

Final model card: full install guide, usage, features, limitations, troubleshooting

Browse files
Files changed (1) hide show
  1. README.md +263 -62
README.md CHANGED
@@ -1,19 +1,38 @@
1
  ---
2
- language: en
 
3
  license: mit
4
  library_name: phishbyte
5
  pipeline_tag: text-classification
6
  tags:
7
  - phishing-detection
8
  - email-security
 
 
9
  - pytorch
10
  - from-scratch
11
  - no-pretrained-weights
12
  - cascading-inference
13
  - lightweight
14
  - explainable-ai
 
 
 
 
 
 
 
 
 
 
 
15
  datasets:
16
- - CEAS-2008
 
 
 
 
 
17
  metrics:
18
  - f1
19
  - precision
@@ -26,102 +45,284 @@ model-index:
26
  type: text-classification
27
  name: Phishing Email Detection
28
  dataset:
29
- name: CEAS-2008
30
  type: ceas-2008
31
  metrics:
32
  - type: f1
33
- value: 0.948
 
34
  - type: accuracy
35
- value: 0.944
 
36
  - type: precision
37
- value: 0.954
 
38
  - type: recall
39
- value: 0.943
 
 
 
 
 
 
40
  ---
41
 
42
- # Phish_Byte
43
 
44
- A from-scratch PyTorch model for **email phishing detection**.
45
- **F1 0.948** on CEAS-2008. **12,545 parameters** (โ‰ˆ9,000ร— smaller than DistilBERT).
46
- **1,500+ emails/sec** on a laptop GPU. Every verdict explains itself.
47
 
48
- ## Why this exists
49
 
50
- Every phishing detection model on HuggingFace is currently a fine-tuned
51
- transformer (DistilBERT, BERT, RoBERTa) โ€” 65 to 110 million parameters,
52
- ~250 MB on disk, ~50 ms per email on GPU. Phish_Byte takes a different
53
- bet: a small custom MLP trained from scratch, fed by 29 carefully chosen
54
- features, routed through a cascading inference pipeline. The model is
55
- **9,000ร— smaller** than DistilBERT, performs competitively, deploys
56
- without a GPU, and explains every decision.
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
57
 
58
  ## Usage
59
 
 
 
60
  ```python
61
  from phishbyte import PhishByteEngine
62
 
63
- engine = PhishByteEngine.from_pretrained("AnonymousSingh-007/phishbyte")
 
 
 
 
64
  verdict = engine.analyze(raw_email_string)
65
 
66
- print(verdict.label) # 'phishing'
67
- print(verdict.probability) # 0.9735
68
- print(verdict.confidence) # 'high'
69
- print(verdict.layer_used) # 2 โ€” MLP made this call
70
- print(verdict.feature_weights) # full per-feature attribution
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
71
  ```
72
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
73
  ## Architecture
74
 
75
  ```
76
- Layer 1 โ€” rule scorers (~1 ms): domain + URL + SPF + subject
77
- โ”‚
78
- โ”œโ”€โ”€โ–บ obvious phishing? short-circuit verdict
79
- โ”‚
80
- โ””โ”€โ”€โ–บ otherwise route to MLP
81
- โ”‚
82
- Layer 2 โ€” MLP (~3 ms): 29 โ†’ 96 โ†’ 48 โ†’ 1 (sigmoid)
83
- โ”‚
84
- โ–ผ
85
- PhishVerdict {label, probability, confidence, layer_used, feature_weights}
 
 
 
 
 
 
 
86
  ```
87
 
88
- ## Performance (CEAS-2008, n=2000 held-out)
89
 
90
- | Metric | Value |
91
- |------------------|----------:|
92
- | F1 score | **0.948** |
93
- | Accuracy | 94.40% |
94
- | Precision | 0.9537 |
95
- | Recall | 0.9432 |
96
- | Parameters | 12,545 |
97
- | Model size | ~50 KB |
98
- | Throughput (GPU) | 1,527 /s |
99
- | Throughput (CPU) | ~800 /s |
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
100
 
101
- ## Features (29 inputs)
102
 
103
- - **Domain (5)**: From/Reply-To/Return-Path mismatch, freemail flag, brand impersonation
104
- - **URL (5)**: HTTPS ratio, anchor mismatch, suspicious TLD, urgency, link density
105
- - **SPF (3)**: SPF fail, no record, no sending IP
106
- - **Subject (7)**: urgency, security theme, brand name, currency, all caps, fake RE, fake transaction ID
107
- - **Character-level (5)**: caps ratio, digit ratio, special chars, avg word length, HTML/text ratio
108
- - **Composite (4)**: per-layer normalized scores
 
 
 
109
 
110
- ## Limitations
111
 
112
- - ~5% of decisions are wrong (F1 0.948, not 1.0). Use as one signal in defence-in-depth, not the only gate.
113
- - Trained on CEAS-2008 โ€” English-language phishing from 2008. Modern attack patterns and non-English emails will degrade performance.
114
- - SPF validation is bypassed for training (historical domains don't resolve) but runs live at inference time.
115
- - Adversarial emails crafted specifically to game these features will get through.
 
116
 
117
  ## Citation
118
 
119
  ```bibtex
120
  @software{phishbyte2026,
121
- author = {Singh, Samratth},
122
- title = {Phish_Byte: A cascading from-scratch PyTorch model for email phishing detection},
123
- year = {2026},
124
- url = {https://github.com/AnonymousSingh-007/Phish_Byte}
125
  }
126
  ```
127
 
 
1
  ---
2
+ language:
3
+ - en
4
  license: mit
5
  library_name: phishbyte
6
  pipeline_tag: text-classification
7
  tags:
8
  - phishing-detection
9
  - email-security
10
+ - cybersecurity
11
+ - security
12
  - pytorch
13
  - from-scratch
14
  - no-pretrained-weights
15
  - cascading-inference
16
  - lightweight
17
  - explainable-ai
18
+ - nlp
19
+ - phishing
20
+ - spam-detection
21
+ - malware-detection
22
+ - threat-detection
23
+ - email-classification
24
+ - text-classification
25
+ - feature-engineering
26
+ - interpretable-ml
27
+ - tfidf
28
+ - residual-network
29
  datasets:
30
+ - ceas-2008
31
+ - enron-email
32
+ - spamassassin
33
+ - ling-spam
34
+ - nazario-phishing
35
+ - nigerian-fraud
36
  metrics:
37
  - f1
38
  - precision
 
45
  type: text-classification
46
  name: Phishing Email Detection
47
  dataset:
48
+ name: 6-corpus benchmark (CEAS, Enron, SpamAssassin, Ling-Spam, Nazario, Nigerian)
49
  type: ceas-2008
50
  metrics:
51
  - type: f1
52
+ value: 0.9503
53
+ name: F1 Score
54
  - type: accuracy
55
+ value: 0.9494
56
+ name: Accuracy
57
  - type: precision
58
+ value: 0.9490
59
+ name: Precision
60
  - type: recall
61
+ value: 0.9516
62
+ name: Recall
63
+ widget:
64
+ - text: "From: PayPal Security <security@paypa1-alert.tk>\nReply-To: attacker@evil-domain.ru\nSubject: URGENT: Your account will be suspended\n\nDear Customer, your PayPal account has been suspended. Verify now at http://paypal-login.tk/verify"
65
+ example_title: "Phishing email example"
66
+ - text: "From: alice@company.com\nReply-To: alice@company.com\nSubject: Team lunch tomorrow\n\nHi everyone, lunch is at noon in the usual spot. See you there!"
67
+ example_title: "Legitimate email example"
68
  ---
69
 
70
+ # Phish_Byte v7
71
 
72
+ A from-scratch PyTorch model for **email phishing detection** โ€” no pretrained weights, no transformers, no fine-tuning.
 
 
73
 
74
+ **F1 0.950** ยท **254K parameters** (260ร— smaller than DistilBERT) ยท **995 emails/sec** on a laptop GPU ยท **85 engineered features** ยท every verdict explains itself.
75
 
76
+ ---
77
+
78
+ ## What makes this different
79
+
80
+ Every other phishing detection model on HuggingFace fine-tunes a transformer (DistilBERT, BERT, RoBERTa). Phish_Byte is the only one built from scratch:
81
+
82
+ | | Phish_Byte v7 | DistilBERT fine-tuned |
83
+ |---|:---:|:---:|
84
+ | F1 score | 0.950 | ~0.967 |
85
+ | Parameters | **254K** | 66,000,000 |
86
+ | Model size | **~1 MB** | ~263 MB |
87
+ | Throughput (GPU) | **995/sec** | ~50/sec |
88
+ | GPU required | **No** | Practically yes |
89
+ | Header + SPF analysis | **Yes** | No |
90
+ | Explainability | **85 features** | Token-level SHAP |
91
+ | Pretrained weights | **None** | DistilBERT |
92
+
93
+ The F1 gap is ~1.7 points. The size and throughput advantage is 260ร— and 20ร— respectively. The header analysis (SPF, display-name spoofing, most-common link domain) is unique to Phish_Byte.
94
+
95
+ ---
96
+
97
+ ## โš ๏ธ Install โ€” read this first
98
+
99
+ **`pip install phishbyte` does not work.** There is no PyPI package yet (it is on the roadmap). The only working path is cloning the source repository.
100
+
101
+ ### Step 1 โ€” Clone
102
+
103
+ ```bash
104
+ git clone https://github.com/AnonymousSingh-007/Phish_Byte.git
105
+ cd Phish_Byte
106
+ ```
107
+
108
+ ### Step 2 โ€” Create environment
109
+
110
+ ```bash
111
+ python -m venv venv
112
+
113
+ # Windows:
114
+ .\venv\Scripts\Activate.ps1
115
+
116
+ # Mac / Linux:
117
+ source venv/bin/activate
118
+ ```
119
+
120
+ ### Step 3 โ€” Install dependencies
121
+
122
+ ```bash
123
+ pip install -r requirements.txt
124
+ ```
125
+
126
+ Minimal deps: `torch`, `huggingface_hub`, `safetensors`, `dnspython`, `numpy`, `pandas`.
127
+
128
+ For GPU acceleration (RTX 50-series / Blackwell):
129
+ ```bash
130
+ pip install torch --index-url https://download.pytorch.org/whl/cu128
131
+ ```
132
+
133
+ ### Step 4 โ€” Verify everything works
134
+
135
+ ```bash
136
+ python verify_install.py
137
+ ```
138
+
139
+ This checks every dependency and every source file, then does a live test-download from this Hub repo. **Run this before reporting any issue** โ€” it tells you exactly what is missing.
140
+
141
+ Expected output (all green):
142
+ ```
143
+ โœ… Python 3.11.x
144
+ โœ… torch
145
+ โœ… huggingface_hub
146
+ โœ… safetensors
147
+ โœ… dns
148
+ โœ… numpy
149
+ โœ… pandas
150
+ โœ… phishbyte/__init__.py
151
+ ... (all source files)
152
+ โœ… from phishbyte import PhishByteEngine โ€” works
153
+ โœ… Model loaded from Hub successfully
154
+ โœ… INSTALLATION VERIFIED
155
+ ```
156
+
157
+ ---
158
 
159
  ## Usage
160
 
161
+ ### Run from Python (inside the cloned folder)
162
+
163
  ```python
164
  from phishbyte import PhishByteEngine
165
 
166
+ # Downloads ~1 MB of weights from this Hub repo on first call
167
+ # Cached locally after that โ€” instant on every subsequent call
168
+ engine = PhishByteEngine.from_pretrained("SamSec007/phishbyte")
169
+
170
+ # Analyze any raw email string (headers + body)
171
  verdict = engine.analyze(raw_email_string)
172
 
173
+ print(verdict.label) # "phishing" or "legitimate"
174
+ print(verdict.probability) # P(phish) in [0.0, 1.0]
175
+ print(verdict.confidence) # "high" / "medium" / "low"
176
+ print(verdict.layer_used) # 1 = rules decided, 2 = MLP decided
177
+ print(verdict.feature_weights) # dict of 85 feature scores
178
+ print(verdict) # formatted terminal display
179
+ ```
180
+
181
+ ### CLI
182
+
183
+ ```bash
184
+ # Demo on a known phishing sample from training data
185
+ python cli.py --demo phish
186
+
187
+ # Demo on a known legitimate sample
188
+ python cli.py --demo legit
189
+
190
+ # Analyze a .eml file
191
+ python cli.py --file suspicious.eml
192
+
193
+ # Paste raw email interactively
194
+ python cli.py
195
+
196
+ # JSON output (for scripting)
197
+ python cli.py --demo --json
198
  ```
199
 
200
+ ### Analyze a real email from Gmail
201
+
202
+ 1. Open the email in Gmail
203
+ 2. Click **โ‹ฎ** โ†’ **Show original**
204
+ 3. Select all (Ctrl+A), copy (Ctrl+C)
205
+ 4. Run `python cli.py`, paste when prompted
206
+ 5. Press Enter then **Ctrl+Z** (Windows) or **Ctrl+D** (Mac/Linux) to submit
207
+
208
+ ### Understanding the verdict
209
+
210
+ ```python
211
+ PhishVerdict(
212
+ label = "phishing",
213
+ probability = 0.9735, # how confident the model is
214
+ confidence = "high", # high โ‰ฅ 0.795, low โ‰ค 0.695, medium in-between
215
+ layer_used = 2, # 1 = rules veto, 2 = MLP decision
216
+ feature_weights = {
217
+ # Which signals fired and how strongly
218
+ "display_name_mismatch": 1.00, # "PayPal" in name, attacker domain
219
+ "mcld_mismatch": 1.00, # most common link domain โ‰  sender
220
+ "spf_fail": 1.00, # SPF DNS check failed
221
+ "tfidf_verify": 0.82, # high TF-IDF score for "verify"
222
+ "external_link_ratio": 0.90, # 90% of links go to external domains
223
+ "urgency_score": 0.65, # urgency keywords in body
224
+ ...
225
+ },
226
+ detail = "MLP probability: 97.35%. Layer 1 score: 19.76%.",
227
+ )
228
+ ```
229
+
230
+ ---
231
+
232
  ## Architecture
233
 
234
  ```
235
+ raw email
236
+ โ”‚
237
+ โ–ผ
238
+ Layer 1 โ€” 6 rule scorers (~1 ms)
239
+ domain ยท URL+body ยท SPF ยท subject ยท BDI ยท TF-IDF
240
+ โ†’ 85-dimensional feature vector
241
+ โ†’ composite score โ‰ฅ 0.85? โ†’ fast PHISHING verdict (obvious cases)
242
+ โ”‚
243
+ โ–ผ (everything else โ€” ~100% of real traffic)
244
+ Layer 2 โ€” residual MLP (~3 ms)
245
+ 85 โ†’ 360 โ†’ 180 (ร—2 ResBlock) โ†’ 90 โ†’ 48 โ†’ 1 (sigmoid)
246
+ 254K parameters ยท randomly initialized ยท trained from scratch
247
+ + input-to-output skip connection
248
+ โ”‚
249
+ โ–ผ
250
+ PhishVerdict
251
+ { label ยท probability ยท confidence ยท layer_used ยท feature_weights }
252
  ```
253
 
254
+ The Layer 1 โ†’ Layer 2 routing is intentional: cheap signals handle the clear cases, the neural network handles the ambiguous ones. `layer_used` tells you which path ran for each email โ€” useful for latency auditing and cost accounting at scale.
255
 
256
+ ---
257
+
258
+ ## Feature groups (85 total)
259
+
260
+ | Group | Count | What it captures |
261
+ |-------|:-----:|-----------------|
262
+ | Domain | 7 | From/Reply-To/Return-Path mismatch, freemail, brand impersonation, display name spoof, suspicious domain pattern |
263
+ | URL + Body | 10 | HTTPS ratio, anchor mismatch, suspicious TLD, urgency (normalized per 100 words), link density, caps ratio, digit ratio, special chars, avg word length, HTML/text ratio |
264
+ | SPF | 3 | SPF fail, no record, no sending IP |
265
+ | Subject | 7 | urgency, security theme, brand name, currency, all caps, fake RE prefix, fake transaction ID |
266
+ | BDI | 3 | Most common link domain mismatch, form action domain mismatch, external link ratio |
267
+ | TF-IDF | 50 | Top-50 discriminative unigrams learned from training corpus (no pretrained embeddings) |
268
+ | Composite | 5 | Per-module layer scores |
269
+
270
+ ---
271
+
272
+ ## Training data
273
+
274
+ | Dataset | Emails | Era |
275
+ |---------|-------:|-----|
276
+ | CEAS-2008 | 39,154 | 2008 |
277
+ | Enron | ~29K | 1999โ€“2002 |
278
+ | SpamAssassin | ~10K | 2002โ€“2003 |
279
+ | Nigerian Fraud | ~3.3K | 2000s |
280
+ | Nazario | ~1.5K | 2000s |
281
+ | Ling-Spam | ~2.8K | 1990sโ€“2000s |
282
+ | **Total (after dedup)** | **~83K** | **balanced ~50/50** |
283
+
284
+ ---
285
+
286
+ ## Limitations โ€” read before deploying
287
+
288
+ - **Training data is 15+ years old.** These corpora predate OAuth phishing, QR code lures, redirect chains through Google Docs / Dropbox / OneDrive, and modern adversarial HTML. Recall on 2020s-era attacks is untested and likely degraded.
289
+ - **TF-IDF vocabulary is era-locked.** Learned from 2000s corpora. Modern phishing vocabulary is not represented.
290
+ - **No adversarial robustness testing has been performed.** An attacker aware of the feature set could craft bypasses. Use as one signal in a defence-in-depth stack, not a standalone gate.
291
+ - **F1 0.950 is self-reported** on a held-out split of the training corpus, not independently verified.
292
+ - **English-language only.**
293
+
294
+ ---
295
+
296
+ ## Troubleshooting
297
 
298
+ Run `python verify_install.py` first โ€” it catches nearly every issue below automatically.
299
 
300
+ | Error | Fix |
301
+ |-------|-----|
302
+ | `ModuleNotFoundError: No module named 'phishbyte'` | Not in cloned folder or venv not activated |
303
+ | `ImportError: cannot import name 'X'` | `git pull origin main` |
304
+ | `pip install phishbyte` fails | No PyPI package yet โ€” clone the repo |
305
+ | `NameError: save_model_as_safetensor` | `pip install safetensors` |
306
+ | Windows symlink warning | Harmless โ€” ignore or enable Developer Mode |
307
+
308
+ ---
309
 
310
+ ## Roadmap
311
 
312
+ - [ ] Retrain on 2020โ€“2024 phishing data (PhishTank, OpenPhish, APWG eCrime)
313
+ - [ ] Adversarial robustness test suite
314
+ - [ ] HuggingFace Space demo (zero-install browser trial)
315
+ - [ ] PyPI package (`pip install phishbyte`)
316
+ - [ ] arXiv preprint
317
 
318
  ## Citation
319
 
320
  ```bibtex
321
  @software{phishbyte2026,
322
+ author = {Singh, Samratth},
323
+ title = {Phish_Byte: Cascading from-scratch PyTorch phishing detection},
324
+ year = {2026},
325
+ url = {https://github.com/AnonymousSingh-007/Phish_Byte}
326
  }
327
  ```
328