Text Classification
Safetensors
PyTorch
English
phishbyte
phishing-detection
email-security
cybersecurity
security
from-scratch
no-pretrained-weights
cascading-inference
lightweight
explainable-ai
nlp
phishing
spam-detection
malware-detection
threat-detection
email-classification
feature-engineering
interpretable-ml
tfidf
residual-network
context-gating
calibrated-probabilities
dmarc-alignment
Eval Results (legacy)
Push model using huggingface_hub.
Browse files- README.md +27 -252
- config.json +4 -1
- model.safetensors +2 -2
README.md
CHANGED
|
@@ -1,252 +1,27 @@
|
|
| 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 |
-
- residual-network
|
| 29 |
-
- context-gating
|
| 30 |
-
- calibrated-probabilities
|
| 31 |
-
- dmarc-alignment
|
| 32 |
-
datasets:
|
| 33 |
-
- ceas-2008
|
| 34 |
-
- enron-email
|
| 35 |
-
- spamassassin
|
| 36 |
-
- ling-spam
|
| 37 |
-
- nazario-phishing
|
| 38 |
-
- nigerian-fraud
|
| 39 |
-
metrics:
|
| 40 |
-
- f1
|
| 41 |
-
- precision
|
| 42 |
-
- recall
|
| 43 |
-
- accuracy
|
| 44 |
-
model-index:
|
| 45 |
-
- name: phishbyte
|
| 46 |
-
results:
|
| 47 |
-
- task:
|
| 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"
|
| 68 |
-
example_title: "Phishing email example"
|
| 69 |
-
- 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!"
|
| 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 |
-
|
| 87 |
-
```bash
|
| 88 |
-
git clone https://github.com/AnonymousSingh-007/Phish_Byte.git
|
| 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
|
| 103 |
-
|
| 104 |
-
engine = PhishByteEngine.from_pretrained("SamSec007/phishbyte")
|
| 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 |
-
|
| 150 |
-
## Architecture
|
| 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 |
-
}
|
| 248 |
-
```
|
| 249 |
-
|
| 250 |
-
## License
|
| 251 |
-
|
| 252 |
-
MIT
|
|
|
|
| 1 |
+
---
|
| 2 |
+
library_name: phishbyte
|
| 3 |
+
license: mit
|
| 4 |
+
pipeline_tag: text-classification
|
| 5 |
+
tags:
|
| 6 |
+
- calibrated-probabilities
|
| 7 |
+
- cascading-inference
|
| 8 |
+
- context-gating
|
| 9 |
+
- cross-signal-fusion
|
| 10 |
+
- cybersecurity
|
| 11 |
+
- dmarc-alignment
|
| 12 |
+
- email-security
|
| 13 |
+
- explainable-ai
|
| 14 |
+
- from-scratch
|
| 15 |
+
- model_hub_mixin
|
| 16 |
+
- nlp
|
| 17 |
+
- no-pretrained-weights
|
| 18 |
+
- phishing
|
| 19 |
+
- phishing-detection
|
| 20 |
+
- pytorch
|
| 21 |
+
- pytorch_model_hub_mixin
|
| 22 |
+
---
|
| 23 |
+
|
| 24 |
+
This model has been pushed to the Hub using the [PytorchModelHubMixin](https://huggingface.co/docs/huggingface_hub/package_reference/mixins#huggingface_hub.PyTorchModelHubMixin) integration:
|
| 25 |
+
- Code: https://github.com/AnonymousSingh-007/Phish_Byte
|
| 26 |
+
- Paper: [More Information Needed]
|
| 27 |
+
- Docs: [More Information Need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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
config.json
CHANGED
|
@@ -1,10 +1,13 @@
|
|
| 1 |
{
|
|
|
|
| 2 |
"dropout1": 0.3,
|
| 3 |
"dropout2": 0.2,
|
| 4 |
"dropout3": 0.1,
|
|
|
|
| 5 |
"hidden_1": 620,
|
| 6 |
"hidden_2": 310,
|
| 7 |
"hidden_3": 155,
|
| 8 |
"hidden_4": 76,
|
| 9 |
-
"
|
|
|
|
| 10 |
}
|
|
|
|
| 1 |
{
|
| 2 |
+
"context_dim": 13,
|
| 3 |
"dropout1": 0.3,
|
| 4 |
"dropout2": 0.2,
|
| 5 |
"dropout3": 0.1,
|
| 6 |
+
"fusion_dim": 64,
|
| 7 |
"hidden_1": 620,
|
| 8 |
"hidden_2": 310,
|
| 9 |
"hidden_3": 155,
|
| 10 |
"hidden_4": 76,
|
| 11 |
+
"raw_dim": 38,
|
| 12 |
+
"tfidf_dim": 50
|
| 13 |
}
|
model.safetensors
CHANGED
|
@@ -1,3 +1,3 @@
|
|
| 1 |
version https://git-lfs.github.com/spec/v1
|
| 2 |
-
oid sha256:
|
| 3 |
-
size
|
|
|
|
| 1 |
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:10304df2d5d30eb28a7cbabb41ce31ff64d764c66e4af3d9d90a6c33676de0c1
|
| 3 |
+
size 3003164
|