Gaykar commited on
Commit
6948870
·
verified ·
1 Parent(s): 1f1a3eb

Create README.md

Browse files
Files changed (1) hide show
  1. README.md +205 -0
README.md ADDED
@@ -0,0 +1,205 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ---
2
+ license: artistic-2.0
3
+ language:
4
+ - en
5
+ base_model:
6
+ - distilbert/distilbert-base-uncased
7
+ ---
8
+
9
+ # Model Card for PhishingDistilBERT
10
+
11
+ ## Model Summary
12
+
13
+ **PhishingDistilBERT** is a DistilBERT-based NLP model fine-tuned specifically for email understanding tasks, particularly phishing and suspicious email detection.
14
+ The model introduces **custom special tokens** to explicitly encode email structure such as subject, body, links, and phone numbers, making it more robust for email-based security applications.
15
+
16
+ It can be used both as:
17
+ - a **sequence classification model** for email safety detection, and
18
+ - an **embedding generator** for downstream ML pipelines (e.g., XGBoost).
19
+
20
+ ---
21
+
22
+ ## Model Details
23
+
24
+ ### Model Description
25
+
26
+ This model is fine-tuned from `distilbert-base-uncased` on curated email datasets. During preprocessing, email-specific entities such as URLs and phone numbers are replaced with dedicated tokens, and the subject and body are explicitly separated using structural markers.
27
+
28
+ **Special Tokens Used**
29
+ - `[SSUB]`, `[ESUB]` – Start/End of Subject
30
+ - `[SBODY]`, `[EBODY]` – Start/End of Body
31
+ - `[LINK]` – URLs
32
+ - `[PHONE]` – Phone numbers
33
+
34
+ These design choices help the model better learn semantic and structural patterns commonly found in phishing emails.
35
+
36
+ - **Developed by:** Atharva Gaykar
37
+ - **Model type:** Transformer-based text classification & embedding model
38
+ - **Language:** English
39
+ - **License:** Artistic-2.0
40
+ - **Finetuned from:** distilbert/distilbert-base-uncased
41
+
42
+ ---
43
+
44
+ ## Intended Uses
45
+
46
+ ### Primary Use Cases
47
+ - Phishing email classification
48
+ - Suspicious vs safe email detection
49
+ - Feature extraction for traditional ML models
50
+ - Email embedding generation for downstream classifiers
51
+
52
+ ### Out-of-Scope Uses
53
+ - Non-text email analysis (images, attachments)
54
+ - Commercial deployment without proper evaluation and compliance
55
+ - Tasks unrelated to email or message-level text analysis
56
+
57
+ ---
58
+
59
+ ## Bias, Risks, and Limitations
60
+
61
+ - The model is trained on public phishing datasets and may reflect biases present in those sources.
62
+ - Performance may degrade on highly obfuscated or novel phishing techniques.
63
+ - Not recommended for direct commercial use without extensive validation.
64
+
65
+ Users should carefully evaluate the model in their target environment before deployment.
66
+
67
+ ---
68
+
69
+ ## How to Get Started
70
+
71
+ ```python
72
+ from transformers import DistilBertTokenizerFast, DistilBertForSequenceClassification
73
+ import torch
74
+ import numpy as np
75
+
76
+ bert_path = "Gaykar/PhishingDistilBERT"
77
+
78
+ tokenizer = DistilBertTokenizerFast.from_pretrained(bert_path)
79
+ model = DistilBertForSequenceClassification.from_pretrained(bert_path)
80
+
81
+ device = torch.device("cuda" if torch.cuda.is_available() else "cpu")
82
+ model.to(device)
83
+ model.eval()
84
+
85
+ def get_cls_embedding(text, model, tokenizer, device):
86
+ with torch.no_grad():
87
+ inputs = tokenizer(
88
+ text,
89
+ return_tensors="pt",
90
+ truncation=True,
91
+ padding=True,
92
+ max_length=256
93
+ )
94
+ inputs = {k: v.to(device) for k, v in inputs.items()}
95
+ outputs = model.distilbert(**inputs)
96
+ cls_embedding = outputs.last_hidden_state[:, 0, :].squeeze().cpu().numpy()
97
+ return cls_embedding
98
+
99
+ text = "[SSUB] Urgent Account Alert [ESUB] [SBODY] Click [LINK] to verify your account. [EBODY]"
100
+ embedding = get_cls_embedding(text, model, tokenizer, device)
101
+
102
+ print("Embedding shape:", embedding.shape)
103
+ print("First 10 dimensions:", embedding[:10])
104
+ ````
105
+
106
+ ---
107
+
108
+ ## Training Details
109
+
110
+ ### Training Data
111
+
112
+ The model was trained using well-known phishing and email security datasets, including **CEAS**, combined with additional curated CSV sources.
113
+
114
+ ### Data Preprocessing
115
+
116
+ 1. Cleaned and merged multiple CSV datasets
117
+ 2. Replaced:
118
+
119
+ * URLs → `[LINK]`
120
+ * Phone numbers → `[PHONE]`
121
+ 3. Combined subject and body using structural tokens:
122
+
123
+ * `[SSUB]`, `[ESUB]`, `[SBODY]`, `[EBODY]`
124
+
125
+ ### Training Hyperparameters
126
+
127
+ ```python
128
+ training_args = TrainingArguments(
129
+ output_dir="./distilbert_safe_suspicious",
130
+ eval_strategy="steps",
131
+ eval_steps=50,
132
+ save_strategy="steps",
133
+ save_steps=50,
134
+ save_total_limit=3,
135
+ load_best_model_at_end=True,
136
+ metric_for_best_model="eval_loss",
137
+ greater_is_better=False,
138
+ learning_rate=4e-5,
139
+ per_device_train_batch_size=16,
140
+ per_device_eval_batch_size=8,
141
+ num_train_epochs=4,
142
+ weight_decay=0.01,
143
+ logging_strategy="steps",
144
+ logging_steps=50,
145
+ seed=42,
146
+ )
147
+ ```
148
+
149
+ ---
150
+
151
+ ## Evaluation
152
+
153
+ ### Evaluation Metrics
154
+
155
+ * Accuracy
156
+ * F1 Score
157
+
158
+ ### Testing Setup
159
+
160
+ * 10% held-out test split from the full dataset
161
+
162
+ ### Results
163
+
164
+ * **DistilBERT (standalone):** Strong classification performance
165
+ * **DistilBERT embeddings + XGBoost + URL features:**
166
+ **99.4% accuracy**
167
+
168
+ ![Evaluation Result](https://cdn-uploads.huggingface.co/production/uploads/685998a37db0a027171ecb9f/Dr3okP_bmVOxHgeaqIQDM.png)
169
+
170
+ ---
171
+
172
+ ## Technical Specifications
173
+
174
+ ### Model Architecture
175
+
176
+ * DistilBERT encoder
177
+ * Sequence classification head
178
+ * CLS-token embedding extraction supported
179
+
180
+ ### Compute Infrastructure
181
+
182
+ * **Hardware:** NVIDIA T4 GPU
183
+ * **Frameworks:** PyTorch, Hugging Face Transformers
184
+
185
+ ---
186
+
187
+ ## Environmental Impact
188
+
189
+ Carbon emissions were not explicitly measured.
190
+ Users may estimate emissions using the Machine Learning Impact Calculator if needed.
191
+
192
+ ---
193
+
194
+ ## Model Card Authors
195
+
196
+ * **Atharva Gaykar**
197
+
198
+ ---
199
+
200
+ ## Contact
201
+
202
+ For questions, feedback, or research collaboration, please reach out via the Hugging Face model repository.
203
+
204
+ ---
205
+