Raihan Hidayatullah Djunaedi
commited on
Commit
·
bd6d389
1
Parent(s):
a966011
Update README.md to enhance model description, installation instructions, and usage examples
Browse files
README.md
CHANGED
|
@@ -1,59 +1,172 @@
|
|
| 1 |
---
|
| 2 |
language:
|
| 3 |
-
- id
|
| 4 |
base_model:
|
| 5 |
-
- google/gemma-2-2b
|
| 6 |
pipeline_tag: text-classification
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 7 |
---
|
| 8 |
|
| 9 |
-
|
| 10 |
-
# Indo Spam Chatbot
|
| 11 |
|
| 12 |
## Model Overview
|
| 13 |
|
| 14 |
-
**
|
| 15 |
-
|
| 16 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 17 |
|
| 18 |
-
|
| 19 |
-
- Offensive and abusive words
|
| 20 |
-
- Profane language
|
| 21 |
-
- Gibberish words and numbers
|
| 22 |
-
- Spam links
|
| 23 |
-
- And more
|
| 24 |
|
| 25 |
-
|
| 26 |
-
|
| 27 |
```
|
| 28 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 29 |
```
|
| 30 |
-
|
|
|
|
|
|
|
| 31 |
```python
|
| 32 |
from transformers import AutoTokenizer, AutoModelForSequenceClassification
|
| 33 |
import torch
|
| 34 |
|
| 35 |
-
|
| 36 |
-
|
| 37 |
-
|
| 38 |
-
|
| 39 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 40 |
|
| 41 |
-
#
|
| 42 |
-
tokenizer =
|
| 43 |
-
model = AutoModelForSequenceClassification.from_pretrained('kasyfilalbar/indo-spam-chatbot', device_map = "auto")
|
| 44 |
|
| 45 |
-
|
| 46 |
-
|
|
|
|
|
|
|
|
|
|
| 47 |
|
| 48 |
-
|
| 49 |
-
|
| 50 |
-
|
| 51 |
-
|
| 52 |
-
|
|
|
|
|
|
|
|
|
|
| 53 |
|
| 54 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 55 |
```
|
| 56 |
|
| 57 |
-
##
|
| 58 |
-
|
| 59 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
---
|
| 2 |
language:
|
| 3 |
+
- id
|
| 4 |
base_model:
|
| 5 |
+
- google/gemma-2-2b
|
| 6 |
pipeline_tag: text-classification
|
| 7 |
+
library_name: transformers
|
| 8 |
+
tags:
|
| 9 |
+
- spam-detection
|
| 10 |
+
- text-classification
|
| 11 |
+
- indonesian
|
| 12 |
+
- chatbot
|
| 13 |
+
- security
|
| 14 |
---
|
| 15 |
|
| 16 |
+
# Indonesian Spam Detection Model
|
|
|
|
| 17 |
|
| 18 |
## Model Overview
|
| 19 |
|
| 20 |
+
**Indonesian Spam Detection Model** is a fine-tuned spam detection model based on the **Gemma 2 2B** architecture. This model is specifically designed for identifying spam messages in Indonesian text, particularly for WhatsApp chatbot interactions. It has been fine-tuned using a comprehensive dataset of 40,000 spam messages collected over a year.
|
| 21 |
+
|
| 22 |
+
### Labels
|
| 23 |
+
|
| 24 |
+
The model classifies text into two categories:
|
| 25 |
+
|
| 26 |
+
- **0**: Non-spam (legitimate message)
|
| 27 |
+
- **1**: Spam (unwanted/malicious message)
|
| 28 |
+
|
| 29 |
+
### Detection Capabilities
|
| 30 |
+
|
| 31 |
+
The model can effectively detect various types of spam including:
|
| 32 |
+
|
| 33 |
+
- Offensive and abusive language
|
| 34 |
+
- Profane content
|
| 35 |
+
- Gibberish text and random characters
|
| 36 |
+
- Suspicious links and URLs
|
| 37 |
+
- Promotional spam
|
| 38 |
+
- Fraudulent messages
|
| 39 |
+
|
| 40 |
+
## Use this Model
|
| 41 |
+
|
| 42 |
+
### Installation
|
| 43 |
|
| 44 |
+
First, install the required dependencies:
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 45 |
|
| 46 |
+
```bash
|
| 47 |
+
pip install transformers torch
|
| 48 |
```
|
| 49 |
+
|
| 50 |
+
### Quick Start
|
| 51 |
+
|
| 52 |
+
```python
|
| 53 |
+
from transformers import AutoTokenizer, AutoModelForSequenceClassification
|
| 54 |
+
import torch
|
| 55 |
+
|
| 56 |
+
# Load model and tokenizer
|
| 57 |
+
model_name = "nahiar/spam-analysis"
|
| 58 |
+
tokenizer = AutoTokenizer.from_pretrained(model_name)
|
| 59 |
+
model = AutoModelForSequenceClassification.from_pretrained(model_name)
|
| 60 |
+
|
| 61 |
+
# Example texts to classify
|
| 62 |
+
texts = [
|
| 63 |
+
"Halo, bagaimana kabar Anda hari ini?", # Non-spam
|
| 64 |
+
"MENANG JUTAAN RUPIAH! Klik link ini sekarang: http://suspicious-link.com", # Spam
|
| 65 |
+
"adsfwcasdfad12345", # Spam (gibberish)
|
| 66 |
+
"Terima kasih atas informasinya" # Non-spam
|
| 67 |
+
]
|
| 68 |
+
|
| 69 |
+
# Tokenize and predict
|
| 70 |
+
for text in texts:
|
| 71 |
+
inputs = tokenizer(text, return_tensors="pt", padding=True, truncation=True, max_length=512)
|
| 72 |
+
|
| 73 |
+
with torch.no_grad():
|
| 74 |
+
outputs = model(**inputs)
|
| 75 |
+
prediction = torch.nn.functional.softmax(outputs.logits, dim=-1)
|
| 76 |
+
predicted_class = torch.argmax(prediction, dim=1).item()
|
| 77 |
+
confidence = torch.max(prediction, dim=1)[0].item()
|
| 78 |
+
|
| 79 |
+
label = "Spam" if predicted_class == 1 else "Non-spam"
|
| 80 |
+
print(f"Text: {text}")
|
| 81 |
+
print(f"Prediction: {label} (confidence: {confidence:.4f})")
|
| 82 |
+
print("-" * 50)
|
| 83 |
```
|
| 84 |
+
|
| 85 |
+
### Batch Processing
|
| 86 |
+
|
| 87 |
```python
|
| 88 |
from transformers import AutoTokenizer, AutoModelForSequenceClassification
|
| 89 |
import torch
|
| 90 |
|
| 91 |
+
def classify_spam_batch(texts, model_name="nahiar/spam-analysis"):
|
| 92 |
+
"""
|
| 93 |
+
Classify multiple texts for spam detection
|
| 94 |
+
|
| 95 |
+
Args:
|
| 96 |
+
texts (list): List of texts to classify
|
| 97 |
+
model_name (str): Hugging Face model name
|
| 98 |
+
|
| 99 |
+
Returns:
|
| 100 |
+
list: List of predictions with confidence scores
|
| 101 |
+
"""
|
| 102 |
+
tokenizer = AutoTokenizer.from_pretrained(model_name)
|
| 103 |
+
model = AutoModelForSequenceClassification.from_pretrained(model_name)
|
| 104 |
|
| 105 |
+
# Tokenize all texts
|
| 106 |
+
inputs = tokenizer(texts, return_tensors="pt", padding=True, truncation=True, max_length=512)
|
|
|
|
| 107 |
|
| 108 |
+
with torch.no_grad():
|
| 109 |
+
outputs = model(**inputs)
|
| 110 |
+
predictions = torch.nn.functional.softmax(outputs.logits, dim=-1)
|
| 111 |
+
predicted_classes = torch.argmax(predictions, dim=1)
|
| 112 |
+
confidences = torch.max(predictions, dim=1)[0]
|
| 113 |
|
| 114 |
+
results = []
|
| 115 |
+
for i, text in enumerate(texts):
|
| 116 |
+
results.append({
|
| 117 |
+
'text': text,
|
| 118 |
+
'is_spam': bool(predicted_classes[i].item()),
|
| 119 |
+
'confidence': confidences[i].item(),
|
| 120 |
+
'label': 'Spam' if predicted_classes[i].item() == 1 else 'Non-spam'
|
| 121 |
+
})
|
| 122 |
|
| 123 |
+
return results
|
| 124 |
+
|
| 125 |
+
# Example usage
|
| 126 |
+
texts = [
|
| 127 |
+
"Selamat pagi, semoga harimu menyenangkan",
|
| 128 |
+
"URGENT!!! Dapatkan uang 10 juta hanya dengan klik link ini",
|
| 129 |
+
"Terima kasih sudah membantu kemarin"
|
| 130 |
+
]
|
| 131 |
+
|
| 132 |
+
results = classify_spam_batch(texts)
|
| 133 |
+
for result in results:
|
| 134 |
+
print(f"Text: {result['text']}")
|
| 135 |
+
print(f"Label: {result['label']} (Confidence: {result['confidence']:.4f})")
|
| 136 |
+
print()
|
| 137 |
```
|
| 138 |
|
| 139 |
+
## Model Performance
|
| 140 |
+
|
| 141 |
+
This model has been trained on a diverse dataset of Indonesian text messages and demonstrates strong performance in distinguishing between spam and legitimate messages across various contexts including:
|
| 142 |
+
|
| 143 |
+
- WhatsApp chatbot interactions
|
| 144 |
+
- SMS messages
|
| 145 |
+
- Social media content
|
| 146 |
+
- Customer service communications
|
| 147 |
+
|
| 148 |
+
## Limitations
|
| 149 |
+
|
| 150 |
+
- The model is primarily trained on Indonesian language text
|
| 151 |
+
- Performance may vary with very short messages (< 10 characters)
|
| 152 |
+
- Context-dependent spam (messages that are spam only in specific contexts) may be challenging
|
| 153 |
+
|
| 154 |
+
## Repository
|
| 155 |
+
|
| 156 |
+
For more information about the training process and code implementation, visit:
|
| 157 |
+
|
| 158 |
+
[https://github.com/nahiar/spam-analysis](https://github.com/nahiar/spam-analysis)
|
| 159 |
+
|
| 160 |
+
## Citation
|
| 161 |
+
|
| 162 |
+
If you use this model in your research or applications, please cite:
|
| 163 |
+
|
| 164 |
+
```bibtex
|
| 165 |
+
@misc{spam-analysis-indo,
|
| 166 |
+
title={Indonesian Spam Detection Model},
|
| 167 |
+
author={Nahiar},
|
| 168 |
+
year={2025},
|
| 169 |
+
publisher={Hugging Face},
|
| 170 |
+
url={https://huggingface.co/nahiar/spam-analysis}
|
| 171 |
+
}
|
| 172 |
+
```
|