SamSec007 commited on
Commit
2969169
·
verified ·
1 Parent(s): 539d3ca

v10 model card: context-gated fusion, version history v2-v10, plain-language architecture guide

Browse files
Files changed (1) hide show
  1. README.md +94 -121
README.md CHANGED
@@ -26,9 +26,9 @@ tags:
26
  - interpretable-ml
27
  - tfidf
28
  - residual-network
29
- - cross-signal-fusion
30
- - lexical-analysis
31
  - calibrated-probabilities
 
32
  datasets:
33
  - ceas-2008
34
  - enron-email
@@ -48,20 +48,20 @@ model-index:
48
  type: text-classification
49
  name: Phishing Email Detection
50
  dataset:
51
- name: 7-corpus benchmark (CEAS, Enron, SpamAssassin, Ling-Spam, Nazario, Nigerian, farshad72)
52
  type: ceas-2008
53
  metrics:
54
  - type: f1
55
  value: 0.9445
56
  name: F1 Score
57
  - type: accuracy
58
- value: 0.9470
59
  name: Accuracy
60
  - type: precision
61
- value: 0.9369
62
  name: Precision
63
  - type: recall
64
- value: 0.9523
65
  name: Recall
66
  widget:
67
  - 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"
@@ -70,22 +70,17 @@ widget:
70
  example_title: "Legitimate email example"
71
  ---
72
 
73
- # Phish_Byte v8
74
 
75
  A from-scratch PyTorch model for **email phishing detection** — no pretrained weights, no transformers, no fine-tuning.
76
 
77
- **F1 0.944** on 5,000 held-out samples from a 7-corpus, 166K-email benchmark.
78
- **716K parameters** (~90× smaller than DistilBERT).
79
- **815 emails/sec** on a laptop GPU.
80
- **104 engineered features** across 8 analysis modules.
81
- **Temperature-calibrated confidence** — probability outputs are empirically calibrated, not just monotonic scores.
82
- Every verdict explains itself with full per-feature attribution.
83
 
84
  > The only non-transformer phishing detection model on HuggingFace.
85
 
86
  ---
87
 
88
- ## ⚠️ Install — no PyPI package yet
89
 
90
  `pip install phishbyte` does **not** work. Clone the source repository:
91
 
@@ -94,10 +89,14 @@ git clone https://github.com/AnonymousSingh-007/Phish_Byte.git
94
  cd Phish_Byte
95
  python -m venv venv && source venv/bin/activate # Windows: .\venv\Scripts\Activate.ps1
96
  pip install -r requirements.txt
97
- python verify_install.py # confirms everything before you start
98
  ```
99
 
100
- Then from inside the cloned folder:
 
 
 
 
101
 
102
  ```python
103
  from phishbyte import PhishByteEngine
@@ -106,63 +105,45 @@ engine = PhishByteEngine.from_pretrained("SamSec007/phishbyte")
106
  verdict = engine.analyze(raw_email_string)
107
 
108
  print(verdict.label) # "phishing" or "legitimate"
109
- print(verdict.probability) # calibrated P(phish) in [0.0, 1.0]
110
  print(verdict.confidence) # "high" / "medium" / "low"
111
- print(verdict.layer_used) # 1 = rules decided, 2 = MLP decided
112
- print(verdict.feature_weights) # all 104 signal values
113
  ```
114
 
115
- `from_pretrained()` downloads ~3 MB (weights + thresholds + TF-IDF vocab) and caches locally. Every call after the first is instant.
116
-
117
- ---
118
 
119
- ## Analyse a real email from Gmail
120
 
121
  1. Open the email → **⋮** → **Show original**
122
  2. Select all (Ctrl+A), copy (Ctrl+C)
123
  3. Run `python cli.py`, paste when prompted, press Enter then Ctrl+Z (Windows) or Ctrl+D (Mac/Linux)
124
 
125
- Or save as `.eml`:
126
 
127
  ```bash
128
  python cli.py --file suspicious.eml
129
  ```
130
 
131
- ---
132
-
133
- ## What changed in v8 vs v7
134
-
135
- | | v7 | v8 |
136
- |---|:---:|:---:|
137
- | Parameters | 254K | **716K** |
138
- | Features | 85 | **104** |
139
- | Architecture | 85→360→180×2→90→48→1 | **104→620→310×2→155→76→1** |
140
- | Training corpus | 83K emails, 6 sources | **166K emails, 7 sources** |
141
- | F1 (held-out) | 0.950 | **0.944** |
142
- | Cross-signal fusion | None | **Yes — 5 inter-module features** |
143
- | Lexical domain analysis | None | **Yes — character-level on sender + link domain** |
144
- | BDI features | 3 | **5 (+ IP-target forms, open redirects)** |
145
- | Confidence calibration | Post-hoc threshold | **Learned temperature parameter (Platt scaling)** |
146
- | Training metric | Naive 0.5 cutoff | **Youden-optimal threshold** |
147
 
148
- The F1 drop from 0.950 to 0.944 reflects a harder benchmark — the corpus doubled in size and the evaluation pool now includes modern notification-style legitimate emails (CNN news digests, mailing lists, marketing email) that the 83K model never saw.
 
 
 
149
 
150
  ---
151
 
152
- ## How it works — plain language
153
 
154
- Eight independent analysis modules run on every email:
155
 
156
- 1. **Domain analysis** — checks whether From, Reply-To, and Return-Path addresses are internally consistent; detects display-name spoofing (e.g. "PayPal Security" sending from an unrelated domain); flags suspicious domain patterns
157
- 2. **URL and body analysis** — HTTPS/HTTP ratio, anchor text vs href mismatch, urgency language normalized per 100 words, link density by unique destinations
158
- 3. **SPF validation** — live DNS lookup to verify the sending server is authorized
159
- 4. **Subject line analysis** — urgency, currency, brand names, ALL-CAPS, fake RE: prefixes
160
- 5. **Body Domain Identification (BDI)** — finds the most common link destination domain; flags form actions pointing at raw IP addresses; detects open-redirect URL patterns
161
- 6. **Lexical domain analysis** — character-level forensics on the sender domain AND the most-linked domain: digit runs, hyphen stacking, Shannon entropy, typosquat distance to known brands (leet-normalized: `paypa1` → `paypal`)
162
- 7. **Cross-signal fusion** — computes interaction features across all six modules: trust consistency (SPF pass + domain agreement + BDI match), multi-module agreement score, domain/BDI compounding, lexical brand confusion
163
- 8. **TF-IDF vocabulary** — 50 discriminative unigrams learned from the training corpus (no pretrained LM)
164
 
165
- All 104 outputs concatenate into one vector and feed a residual MLP with a learned temperature scalar for calibrated confidence.
 
 
 
166
 
167
  ---
168
 
@@ -170,105 +151,97 @@ All 104 outputs concatenate into one vector and feed a residual MLP with a learn
170
 
171
  ```
172
  raw email
173
- → 8 analysis modules → 104-dim feature vector
174
- → Layer 1 gate: composite score ≥ 0.85 → fast PHISHING verdict
175
- → Layer 2: residual MLP
176
- 104 → 620 → 310 (×2 ResBlock) → 155 → 76 → 1
177
- + input-to-output skip connection
178
- + learned temperature scalar (Platt scaling)
179
- → calibrated P(phish) + PhishVerdict with 104-feature attribution
 
 
 
180
  ```
181
 
182
  ---
183
 
184
- ## Benchmarks
185
 
186
- Evaluated on 5,000 held-out samples, self-reported.
187
 
188
- | Metric | Phish_Byte v8 | DistilBERT fine-tuned\* |
189
- |--------|:------------:|:---------------------:|
190
- | F1 score | 0.944 | ~0.967 |
191
- | Accuracy | 94.70% | ~97% |
192
- | Parameters | **716K** | 66,000,000 |
193
- | Model size | **~3 MB** | ~263 MB |
194
- | Throughput (GPU) | **815/sec** | ~50/sec |
195
- | GPU required | **No** | Practically yes |
196
- | Header + SPF analysis | **Yes** | No |
197
- | Per-feature attribution | **104 features** | Token-level SHAP |
198
- | Confidence calibrated | **Yes (temperature)** | No |
199
 
200
- \* Self-reported by a different author on a different split. Not apples-to-apples — treat both F1 numbers as directional.
201
 
202
- ---
203
 
204
- ## Feature groups (104 total)
205
-
206
- | Group | Count | What it captures |
207
- |-------|:-----:|-----------------|
208
- | Domain | 7 | header consistency, brand impersonation, display-name spoof, suspicious pattern |
209
- | URL + Body | 10 | link security, anchor mismatch, urgency, caps ratio, digit ratio |
210
- | SPF | 3 | live DNS sender authorization |
211
- | Subject | 7 | urgency, security theme, brand, currency, caps, fake RE, fake txn ID |
212
- | BDI | 5 | MCLD mismatch, form action mismatch, external link ratio, IP-target form, open redirect |
213
- | Lexical — sender domain | 6 | digit runs, hyphen runs, entropy, vowel anomaly, typosquat distance, length |
214
- | Lexical — most-linked domain | 6 | same six on the dominant link destination |
215
- | Cross-signal fusion | 5 | trust consistency, SPF-pass URL discount, multi-module agreement, domain/BDI compounding, lexical brand confusion |
216
- | TF-IDF | 50 | top-50 discriminative unigrams from training corpus |
217
- | Composite | 5 | per-module summary scores |
218
 
219
  ---
220
 
221
- ## Training corpus (166K emails, 7 sources)
222
-
223
- | Source | Emails |
224
- |--------|-------:|
225
- | CEAS-2008, Enron, SpamAssassin, Ling-Spam, Nazario, Nigerian Fraud | ~83K |
226
- | farshad72/spam_email (HuggingFace) | ~83K |
227
- | **Total after dedup** | **~166K** |
228
-
229
- Balance: ~56% phishing / 44% legitimate.
 
 
 
 
 
 
 
 
 
 
230
 
231
  ---
232
 
233
- ## Troubleshooting
234
 
235
- Run `python verify_install.py` first — it identifies the exact problem rather than a confusing traceback.
236
-
237
- | Error | Fix |
238
- |-------|-----|
239
- | `ModuleNotFoundError: No module named 'phishbyte'` | Not in cloned folder or venv not activated |
240
- | `ImportError: cannot import name 'X'` | `git pull origin main` |
241
- | `pip install phishbyte` fails | No PyPI package yet — clone the repo |
242
- | Model download hangs | Check internet — Hub: huggingface.co/SamSec007/phishbyte |
243
- | Windows symlink warning | Harmless — ignore or enable Developer Mode |
244
 
245
  ---
246
 
247
- ## Limitations — read before deploying
248
 
249
- - **Most training data predates 2010.** Modern phishing (OAuth abuse, QR lures, redirect chains through legitimate cloud services) is underrepresented. Recall on 2020s attacks is not independently verified.
250
- - **No DMARC feature yet.** Emails sent via legitimate ESPs (Marketo, Mailgun, SendGrid) will trigger `spf_fail` even when `dmarc=pass`. This causes false positives on marketing email from large organizations. DMARC extraction is the next planned feature.
251
- - **No adversarial robustness testing.** Use as one signal in defence-in-depth, not a standalone gate.
252
- - **F1 0.944 is self-reported** on a held-out split of the training corpus.
253
- - **English-language only.**
 
 
 
 
 
 
254
 
255
  ---
256
 
257
- ## Roadmap
258
 
259
- - [ ] DMARC feature — fixes false positives on ESP-delivered legitimate email
260
- - [ ] Retrain on 2020–2024 phishing data (PhishTank, OpenPhish, APWG eCrime)
261
- - [ ] HuggingFace Space demo (try in-browser, zero install)
262
- - [ ] PyPI package (`pip install phishbyte`)
263
- - [ ] arXiv preprint
264
- - [ ] Adversarial robustness test suite
265
 
266
  ## Citation
267
 
268
  ```bibtex
269
  @software{phishbyte2026,
270
  author = {Singh, Samratth},
271
- title = {Phish_Byte: Cascading from-scratch PyTorch phishing detection},
272
  year = {2026},
273
  url = {https://github.com/AnonymousSingh-007/Phish_Byte}
274
  }
 
26
  - interpretable-ml
27
  - tfidf
28
  - residual-network
29
+ - context-gating
 
30
  - calibrated-probabilities
31
+ - dmarc-alignment
32
  datasets:
33
  - ceas-2008
34
  - enron-email
 
48
  type: text-classification
49
  name: Phishing Email Detection
50
  dataset:
51
+ name: 7-source benchmark (CEAS, Enron, SpamAssassin, Ling-Spam, Nazario, Nigerian, farshad72, puyang2025)
52
  type: ceas-2008
53
  metrics:
54
  - type: f1
55
  value: 0.9445
56
  name: F1 Score
57
  - type: accuracy
58
+ value: 0.9477
59
  name: Accuracy
60
  - type: precision
61
+ value: 0.9402
62
  name: Precision
63
  - type: recall
64
+ value: 0.9489
65
  name: Recall
66
  widget:
67
  - 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"
 
70
  example_title: "Legitimate email example"
71
  ---
72
 
73
+ # Phish_Byte v10
74
 
75
  A from-scratch PyTorch model for **email phishing detection** — no pretrained weights, no transformers, no fine-tuning.
76
 
77
+ **743K parameters.** Every signal is a feature computed directly from the email — domain consistency, live SPF/DKIM/DMARC validation, link forensics, character-level lexical analysis — fed through a **context-gating architecture** that learns how one signal should change the interpretation of another, rather than a fixed hand-written rule.
 
 
 
 
 
78
 
79
  > The only non-transformer phishing detection model on HuggingFace.
80
 
81
  ---
82
 
83
+ ## Install — no PyPI package yet
84
 
85
  `pip install phishbyte` does **not** work. Clone the source repository:
86
 
 
89
  cd Phish_Byte
90
  python -m venv venv && source venv/bin/activate # Windows: .\venv\Scripts\Activate.ps1
91
  pip install -r requirements.txt
92
+ python verify_install.py
93
  ```
94
 
95
+ `verify_install.py` checks every dependency and source file, then does a live test download from this Hub repo. Run it before anything else — it identifies exactly what's wrong instead of a confusing traceback.
96
+
97
+ ---
98
+
99
+ ## Usage
100
 
101
  ```python
102
  from phishbyte import PhishByteEngine
 
105
  verdict = engine.analyze(raw_email_string)
106
 
107
  print(verdict.label) # "phishing" or "legitimate"
108
+ print(verdict.probability) # calibrated P(phish), 0.0–1.0
109
  print(verdict.confidence) # "high" / "medium" / "low"
110
+ print(verdict.layer_used) # 1 = fast rule veto, 2 = full network
111
+ print(verdict.feature_weights) # every signal computed for this email
112
  ```
113
 
114
+ `from_pretrained()` downloads the weights, calibration thresholds, and TF-IDF vocabulary from this repo on first call and caches them locally — every call after that is instant.
 
 
115
 
116
+ ### Analyze a real email from Gmail
117
 
118
  1. Open the email → **⋮** → **Show original**
119
  2. Select all (Ctrl+A), copy (Ctrl+C)
120
  3. Run `python cli.py`, paste when prompted, press Enter then Ctrl+Z (Windows) or Ctrl+D (Mac/Linux)
121
 
122
+ Or save as `.eml` and run:
123
 
124
  ```bash
125
  python cli.py --file suspicious.eml
126
  ```
127
 
128
+ ### CLI quick demo
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
129
 
130
+ ```bash
131
+ python cli.py --demo phish # a known phishing example, no files needed
132
+ python cli.py --demo legit # a known legitimate example
133
+ ```
134
 
135
  ---
136
 
137
+ ## How it works, in plain language
138
 
139
+ Every email is analyzed by several small, independent checks — the sender's domain, the links in the body, whether the mail server proved its identity via SPF/DKIM/DMARC, the subject line, the wording of the message. Each check produces a handful of numbers between 0 and 1.
140
 
141
+ The key design choice is what happens next. Rather than mixing every number together and hoping a network untangles the relationships on its own, Phish_Byte splits its evidence into two groups before the network ever sees them:
 
 
 
 
 
 
 
142
 
143
+ - **Raw evidence** — facts about this specific email, like "the Reply-To address differs from the sender" or "the most common link goes somewhere else."
144
+ - **Context evidence** — facts that change how the raw evidence should be read, like "the server cryptographically proved its identity via DMARC and DKIM," or "this urgency is coercive rather than just professionally formal."
145
+
146
+ A dedicated layer in the network learns a *gate* — for every email, how much should the context evidence turn up or down the weight given to each piece of raw evidence. This isn't a hardcoded rule like "if DMARC passes, ignore link mismatches." The network learns the actual relationship from real data, so it can distinguish a Gmail Reply-To on an authenticated academic mailing list from a Gmail Reply-To on an unauthenticated bank impersonation attempt — two situations a fixed rule would treat identically.
147
 
148
  ---
149
 
 
151
 
152
  ```
153
  raw email
154
+ → domain / URL / auth (SPF+DKIM+DMARC) / subject / link-forensics / lexical analysis
155
+ → cross-signal agreement check
156
+ → context feature computation (coercive vs professional urgency,
157
+ auth-verified sender context, freemail Reply-To context)
158
+ → RAW evidence (38 numbers) and CONTEXT evidence (13 numbers), kept separate
159
+ → Context Fusion Layer: learns a gate deciding how context reweights raw evidence
160
+ → fused representation + 50 TF-IDF word signals
161
+ → residual MLP: 620 → 310 (×2 residual blocks) → 155 → 76 → 1
162
+ → temperature-calibrated confidence score
163
+ → PhishVerdict with every raw and context signal that fired
164
  ```
165
 
166
  ---
167
 
168
+ ## Version history
169
 
170
+ **v2 — 12K parameters, 29 features, single dataset (CEAS-2008, ~39K emails).** The original prototype: a small MLP over hand-picked domain, URL, and subject features. Established the cascading Layer 1 (cheap rules) → Layer 2 (neural network) design that every later version kept.
171
 
172
+ **v7 — 254K parameters, 85 features, 83K emails across 6 datasets.** Added a TF-IDF vocabulary learned directly from the training corpus and Body Domain Identification (most-common-link-domain analysis). First version with real generalization testing beyond a single dataset.
 
 
 
 
 
 
 
 
 
 
173
 
174
+ **v8 — 716K parameters, 104 features, 166K emails across 7 datasets.** Added character-level lexical domain analysis (digit runs, entropy, typosquat distance) and a cross-signal layer that checks whether independent modules agree with each other, rather than scoring each in isolation.
175
 
176
+ **v9 — 718K parameters, 107 features.** Replaced a naive SPF-only authentication check — which misfired constantly on legitimate marketing platforms like Marketo and Mailgun that relay mail on a brand's behalf — with a proper DMARC/DKIM alignment check that reads what the receiving mail server already validated.
177
 
178
+ **v10 (current) — 743K parameters, context-gated fusion architecture.** Split urgency detection into two independent signals (coercive pressure vs. professional formality, previously conflated into one number). Restructured the network so raw evidence and context evidence enter as separate inputs to a learned fusion layer, instead of being concatenated and left for the network to disentangle unaided.
 
 
 
 
 
 
 
 
 
 
 
 
 
179
 
180
  ---
181
 
182
+ ## Feature groups
183
+
184
+ | Group | Count | What it measures |
185
+ |-------|:-----:|-------------------|
186
+ | Domain (raw) | 7 | header consistency, brand impersonation, display-name spoofing |
187
+ | URL + body (raw) | 4 | link security, anchor/href mismatch, link density |
188
+ | SPF (raw) | 3 | basic sender authorization signal |
189
+ | Subject (raw) | 7 | brand mentions, currency, formatting, fake reply prefixes |
190
+ | Char-level (raw) | 5 | capitalization, digit density, HTML/text ratio |
191
+ | BDI (raw) | 5 | most-common-link-domain mismatch, IP-target forms, open redirects |
192
+ | Lexical — sender domain (raw) | 6 | digit runs, hyphen runs, entropy, typosquat distance |
193
+ | Coercive urgency (raw) | 1 | pressure/threat language |
194
+ | Auth-verified ESP context | 1 | how strongly DMARC/DKIM validate the sender |
195
+ | Professional formality (context) | 1 | independent of coercive urgency |
196
+ | Freemail Reply-To context | 2 | raw fact + how much authentication offsets it |
197
+ | Tracking pattern (observational) | 1 | structural resemblance to ESP tracking infrastructure — never used to exempt anything |
198
+ | Cross-signal fusion (context) | 5 | agreement between independent modules |
199
+ | Auth alignment (context) | 3 | DMARC pass, DKIM alignment, composite score |
200
+ | TF-IDF | 50 | words learned directly from the training corpus |
201
 
202
  ---
203
 
204
+ ## Training data
205
 
206
+ | Dataset | Source |
207
+ |---------|--------|
208
+ | CEAS-2008, Enron, SpamAssassin, Ling-Spam, Nazario, Nigerian Fraud | Kaggle |
209
+ | farshad72/spam_email | HuggingFace, 83K rows |
210
+ | puyang2025/seven-phishing-email-datasets | HuggingFace, 203K rows, 7-source unified |
211
+ | **Combined, after deduplication** | **~166,000 emails, ~56% phishing / 44% legitimate** |
 
 
 
212
 
213
  ---
214
 
215
+ ## Benchmarks
216
 
217
+ Evaluated on 12,000 held-out samples, self-reported.
218
+
219
+ | Metric | Value |
220
+ |--------|:-----:|
221
+ | F1 score | 0.9445 |
222
+ | Accuracy | 94.77% |
223
+ | Precision | 0.9402 |
224
+ | Recall | 0.9489 |
225
+ | Parameters | 743K |
226
+ | Model size | ~3 MB |
227
+ | GPU required | No |
228
 
229
  ---
230
 
231
+ ## Limitations
232
 
233
+ - **Most training data predates 2010.** Modern phishing (OAuth abuse, QR lures, redirect chains through legitimate cloud services) is underrepresented.
234
+ - **False positives on legitimate marketing/notification email are reduced but not eliminated.** The context-gating architecture measurably helps but this remains an active area of work.
235
+ - **No adversarial robustness testing has been performed.** Use as one signal in defence-in-depth, not a standalone gate.
236
+ - **Benchmark numbers are self-reported**, not independently verified.
237
+ - **English-language only.**
 
238
 
239
  ## Citation
240
 
241
  ```bibtex
242
  @software{phishbyte2026,
243
  author = {Singh, Samratth},
244
+ title = {Phish_Byte: Context-gated fusion architecture for from-scratch email phishing detection},
245
  year = {2026},
246
  url = {https://github.com/AnonymousSingh-007/Phish_Byte}
247
  }