Update README.md
Browse files
README.md
CHANGED
|
@@ -23,7 +23,7 @@ library_name: transformers
|
|
| 23 |
|
| 24 |
# Spam Message Classifier
|
| 25 |
|
| 26 |
-
A state-of-the-art spam message classification model built on **RoBERTa-base** transformer architecture, achieving **99.
|
| 27 |
|
| 28 |
## Model Description
|
| 29 |
|
|
@@ -39,7 +39,7 @@ This model is a fine-tuned version of FacebookAI/roberta-base for binary spam cl
|
|
| 39 |
## Key Features
|
| 40 |
|
| 41 |
- **π€ Transformer-based Architecture**: Built on RoBERTa-base for superior text understanding
|
| 42 |
-
- **β‘ High Performance**: 0.
|
| 43 |
- **π§ Hyperparameter Optimization**: Automated tuning using Optuna framework (25 trials)
|
| 44 |
- **βοΈ Class Imbalance Handling**: Successfully addressed through weighted loss function
|
| 45 |
- **π URL Bias Mitigation**: Enhanced with real-world ham messages containing links
|
|
@@ -142,27 +142,14 @@ This spam classifier is ideal for:
|
|
| 142 |
The model was trained on a combination of two comprehensive SMS spam datasets totaling **11,498 messages**:
|
| 143 |
|
| 144 |
1. **[SMS Spam Collection Dataset](https://www.kaggle.com/datasets/uciml/sms-spam-collection-dataset)** - UCI Machine Learning Repository
|
| 145 |
-
2. **
|
| 146 |
-
|
| 147 |
-
**
|
| 148 |
-
|
| 149 |
-
- Ham Messages: 9,669 (84.1%)
|
| 150 |
-
- Spam Messages: 1,829 (15.9%)
|
| 151 |
-
- Average Message Length: ~80 characters
|
| 152 |
-
- Language: English
|
| 153 |
-
|
| 154 |
-
**Dataset Split**:
|
| 155 |
-
- Training Set: 70% (~8,048 messages)
|
| 156 |
-
- Validation Set: 15% (~1,725 messages) - for hyperparameter tuning
|
| 157 |
-
- Test Set: 15% (~1,725 messages) - completely unseen data for final evaluation
|
| 158 |
-
|
| 159 |
-
**Preprocessing**:
|
| 160 |
-
1. Label encoding (ham β 0, spam/smishing β 1)
|
| 161 |
2. Text cleaning and normalization with Discord-specific preprocessing
|
| 162 |
-
3.
|
| 163 |
-
4.
|
| 164 |
-
5.
|
| 165 |
-
6. Dynamic padding and truncation (max length = 128)
|
| 166 |
|
| 167 |
## Training Procedure
|
| 168 |
|
|
@@ -179,15 +166,15 @@ Automated hyperparameter search using **Optuna framework** (25 trials):
|
|
| 179 |
- Training epochs: 2 to 5 epochs
|
| 180 |
- Warmup ratio: 0.05 to 0.1 for learning rate scheduling
|
| 181 |
|
| 182 |
-
**Best Parameters Found (Trial
|
| 183 |
-
-
|
| 184 |
-
-
|
| 185 |
-
-
|
| 186 |
-
-
|
| 187 |
-
-
|
| 188 |
-
-
|
| 189 |
-
-
|
| 190 |
-
-
|
| 191 |
|
| 192 |
### Training Strategy
|
| 193 |
|
|
@@ -210,33 +197,31 @@ Automated hyperparameter search using **Optuna framework** (25 trials):
|
|
| 210 |
|
| 211 |
| Metric | Score |
|
| 212 |
|--------|-------|
|
| 213 |
-
| **Overall Accuracy** | **99.
|
| 214 |
-
| **Weighted F1-Score** | **0.
|
| 215 |
-
| **Spam F1-Score** | **0.
|
| 216 |
-
| **Spam Precision** | **
|
| 217 |
-
| **Spam Recall** | **99.
|
| 218 |
-
| **Ham Precision** | **99.
|
| 219 |
-
| **Ham Recall** | **
|
| 220 |
|
| 221 |
### Confusion Matrix
|
| 222 |
|
| 223 |
| | Predicted Ham | Predicted Spam |
|
| 224 |
|---------------|---------------|----------------|
|
| 225 |
-
| **Actual Ham** |
|
| 226 |
-
| **Actual Spam** | 1 |
|
| 227 |
|
| 228 |
### Performance Analysis
|
| 229 |
|
| 230 |
-
- **True Positives**:
|
| 231 |
-
- **True Negatives**:
|
| 232 |
-
- **False Positives**:
|
| 233 |
-
- **False Negatives**: 1
|
| 234 |
-
- **False Positive Rate**: 0.00%
|
| 235 |
-
- **Miss Rate**: 0.36%
|
| 236 |
|
| 237 |
### Generalizability
|
| 238 |
|
| 239 |
-
> π **Strong Generalization**: All performance metrics are evaluated on a **completely unseen test set** (15% of data
|
| 240 |
|
| 241 |
## Challenges Addressed & Solutions
|
| 242 |
|
|
@@ -248,7 +233,7 @@ Automated hyperparameter search using **Optuna framework** (25 trials):
|
|
| 248 |
|
| 249 |
### β
Class Imbalance Handling (SUCCESSFULLY ADDRESSED)
|
| 250 |
|
| 251 |
-
**Challenge**: The combined dataset exhibits natural imbalance
|
| 252 |
|
| 253 |
**Solution**: Implemented weighted loss function during training to handle the imbalanced dataset effectively, resulting in exceptional performance for both classes.
|
| 254 |
|
|
@@ -256,7 +241,7 @@ Automated hyperparameter search using **Optuna framework** (25 trials):
|
|
| 256 |
|
| 257 |
**Challenge**: Ensuring model generalizes well to unseen data.
|
| 258 |
|
| 259 |
-
**Solution**: Comprehensive evaluation on completely held-out test set (15% of data) never used during training or hyperparameter tuning, with demonstrated strong generalization (99.
|
| 260 |
|
| 261 |
## Limitations
|
| 262 |
|
|
|
|
| 23 |
|
| 24 |
# Spam Message Classifier
|
| 25 |
|
| 26 |
+
A state-of-the-art spam message classification model built on **RoBERTa-base** transformer architecture, achieving **99.42% accuracy** and **0.9782 F1-score for spam class** for the test set. Developed as the core spam detection component for **Amy**, an intelligent Discord moderation bot.
|
| 27 |
|
| 28 |
## Model Description
|
| 29 |
|
|
|
|
| 39 |
## Key Features
|
| 40 |
|
| 41 |
- **π€ Transformer-based Architecture**: Built on RoBERTa-base for superior text understanding
|
| 42 |
+
- **β‘ High Performance**: 0.9782 F1-score for spam detection, 99.42% overall accuracy
|
| 43 |
- **π§ Hyperparameter Optimization**: Automated tuning using Optuna framework (25 trials)
|
| 44 |
- **βοΈ Class Imbalance Handling**: Successfully addressed through weighted loss function
|
| 45 |
- **π URL Bias Mitigation**: Enhanced with real-world ham messages containing links
|
|
|
|
| 142 |
The model was trained on a combination of two comprehensive SMS spam datasets totaling **11,498 messages**:
|
| 143 |
|
| 144 |
1. **[SMS Spam Collection Dataset](https://www.kaggle.com/datasets/uciml/sms-spam-collection-dataset)** - UCI Machine Learning Repository
|
| 145 |
+
2. **Discord Text Messages** β a manually collected dataset of real Discord messages containing both ham and spam samples. (This dataset was created to mitigate `<URL>` bias.)
|
| 146 |
+
|
| 147 |
+
**Preprocessing Steps**:
|
| 148 |
+
1. Label encoding (ham β 0, spam β 1)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 149 |
2. Text cleaning and normalization with Discord-specific preprocessing
|
| 150 |
+
3. Train/validation/test split (70/15/15)
|
| 151 |
+
4. Tokenization with RoBERTa tokenizer
|
| 152 |
+
5. Dynamic padding and truncation
|
|
|
|
| 153 |
|
| 154 |
## Training Procedure
|
| 155 |
|
|
|
|
| 166 |
- Training epochs: 2 to 5 epochs
|
| 167 |
- Warmup ratio: 0.05 to 0.1 for learning rate scheduling
|
| 168 |
|
| 169 |
+
**Best Parameters Found (Trial 6/25)**:
|
| 170 |
+
- Hidden dropout: 0.10069482002001506
|
| 171 |
+
- Attention dropout: 0.12460257350587067
|
| 172 |
+
- Learning rate: 4.976184540342024e-05
|
| 173 |
+
- Weight decay: 0.04490021845024478
|
| 174 |
+
- Batch size: 16
|
| 175 |
+
- Gradient accumulation steps: 4
|
| 176 |
+
- Epochs: 4
|
| 177 |
+
- Warmup ratio: 0.07622459860163384
|
| 178 |
|
| 179 |
### Training Strategy
|
| 180 |
|
|
|
|
| 197 |
|
| 198 |
| Metric | Score |
|
| 199 |
|--------|-------|
|
| 200 |
+
| **Overall Accuracy** | **99.41%** |
|
| 201 |
+
| **Weighted F1-Score** | **0.9941** |
|
| 202 |
+
| **Spam F1-Score** | **0.9782** |
|
| 203 |
+
| **Spam Precision** | **96.55%** |
|
| 204 |
+
| **Spam Recall** | **99.12%** |
|
| 205 |
+
| **Ham Precision** | **99.86%** |
|
| 206 |
+
| **Ham Recall** | **99.45%** |
|
| 207 |
|
| 208 |
### Confusion Matrix
|
| 209 |
|
| 210 |
| | Predicted Ham | Predicted Spam |
|
| 211 |
|---------------|---------------|----------------|
|
| 212 |
+
| **Actual Ham** | 725 | 4 |
|
| 213 |
+
| **Actual Spam** | 1 | 112 |
|
| 214 |
|
| 215 |
### Performance Analysis
|
| 216 |
|
| 217 |
+
- **True Positives**: 112 spam messages correctly identified
|
| 218 |
+
- **True Negatives**: 725 ham messages correctly identified
|
| 219 |
+
- **False Positives**: 4
|
| 220 |
+
- **False Negatives**: 1
|
|
|
|
|
|
|
| 221 |
|
| 222 |
### Generalizability
|
| 223 |
|
| 224 |
+
> π **Strong Generalization**: All performance metrics are evaluated on a **completely unseen test set** (15% of data) that was never used during training or hyperparameter tuning, ensuring robust real-world performance and preventing overfitting.
|
| 225 |
|
| 226 |
## Challenges Addressed & Solutions
|
| 227 |
|
|
|
|
| 233 |
|
| 234 |
### β
Class Imbalance Handling (SUCCESSFULLY ADDRESSED)
|
| 235 |
|
| 236 |
+
**Challenge**: The combined dataset exhibits natural imbalance.
|
| 237 |
|
| 238 |
**Solution**: Implemented weighted loss function during training to handle the imbalanced dataset effectively, resulting in exceptional performance for both classes.
|
| 239 |
|
|
|
|
| 241 |
|
| 242 |
**Challenge**: Ensuring model generalizes well to unseen data.
|
| 243 |
|
| 244 |
+
**Solution**: Comprehensive evaluation on completely held-out test set (15% of data) never used during training or hyperparameter tuning, with demonstrated strong generalization (99.42% accuracy on unseen data).
|
| 245 |
|
| 246 |
## Limitations
|
| 247 |
|