SamSec007 commited on
Commit
328691a
·
verified ·
1 Parent(s): 1b3cbe3

Push model using huggingface_hub.

Browse files
Files changed (3) hide show
  1. README.md +26 -331
  2. config.json +5 -5
  3. model.safetensors +2 -2
README.md CHANGED
@@ -1,331 +1,26 @@
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
39
- - recall
40
- - accuracy
41
- model-index:
42
- - name: phishbyte
43
- results:
44
- - task:
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
-
329
- ## License
330
-
331
- MIT
 
1
+ ---
2
+ library_name: phishbyte
3
+ license: mit
4
+ pipeline_tag: text-classification
5
+ tags:
6
+ - calibrated-probabilities
7
+ - cascading-inference
8
+ - cross-signal-fusion
9
+ - cybersecurity
10
+ - email-security
11
+ - explainable-ai
12
+ - from-scratch
13
+ - lexical-analysis
14
+ - model_hub_mixin
15
+ - nlp
16
+ - no-pretrained-weights
17
+ - phishing
18
+ - phishing-detection
19
+ - pytorch
20
+ - pytorch_model_hub_mixin
21
+ ---
22
+
23
+ This model has been pushed to the Hub using the [PytorchModelHubMixin](https://huggingface.co/docs/huggingface_hub/package_reference/mixins#huggingface_hub.PyTorchModelHubMixin) integration:
24
+ - Code: https://github.com/AnonymousSingh-007/Phish_Byte
25
+ - Paper: [More Information Needed]
26
+ - Docs: [More Information Needed]
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
config.json CHANGED
@@ -2,9 +2,9 @@
2
  "dropout1": 0.3,
3
  "dropout2": 0.2,
4
  "dropout3": 0.1,
5
- "hidden_1": 360,
6
- "hidden_2": 180,
7
- "hidden_3": 90,
8
- "hidden_4": 48,
9
- "input_dim": 85
10
  }
 
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
+ "input_dim": 104
10
  }
model.safetensors CHANGED
@@ -1,3 +1,3 @@
1
  version https://git-lfs.github.com/spec/v1
2
- oid sha256:155f6d652a88522b92a237deb4217aa5d6ba7e7ce6af92aa1d3cb9355e56af5b
3
- size 1032852
 
1
  version https://git-lfs.github.com/spec/v1
2
+ oid sha256:99c2100af984fd5a4ea75e4b6ce74b61416846f18e0bd01ed88bbfd29e581e67
3
+ size 2890612