Views
No views yet
sms_spam, spam_mail, and mail_spam_ham_datasetpip install transformers torch1from transformers import RobertaTokenizer, RobertaForSequenceClassification
2import torch
3
4device = torch.device("cuda" if torch.cuda.is_available() else "cpu")
5
6model_name = "AventIQ-AI/roberta-spam-detection"
7model = RobertaForSequenceClassification.from_pretrained(model_name).to(device)
8tokenizer = RobertaTokenizer.from_pretrained(model_name)
9
10
11def predict(text):
12 inputs = tokenizer(text, return_tensors="pt", truncation=True, padding=True)
13
14 # Move input tensors to the same device as the model
15 inputs = {key: value.to(device) for key, value in inputs.items()}
16
17 with torch.no_grad():
18 outputs = model(**inputs)
19 logits = outputs.logits
20 predicted_class = torch.argmax(logits).item()
21
22 return "Spam" if predicted_class == 1 else "Ham"
23
24# Sample test messages
25input_text = "Congratulations! You have won a free iPhone. Click here to claim your prize."
26print(f"Prediction: {predict(input_text)}") # Expected output: Spam| Metric | Class 0 (Non-Spam) | Class 1 (Spam) | Macro Avg | Weighted Avg |
|---|---|---|---|---|
| Precision | 1.00 | 0.98 | 0.99 | 0.99 |
| Recall | 0.99 | 0.99 | 0.99 | 0.99 |
| F1-Score | 0.99 | 0.99 | 0.99 | 0.99 |
| Accuracy | 99% | 99% | 99% | 99% |
sms_spam, spam_mail, and mail_spam_ham_dataset dataset was used, containing both spam and ham (non-spam) examples..
├── model/ # Contains the quantized model files
├── tokenizer_config/ # Tokenizer configuration and vocabulary files
├── model.safetensors/ # Fine Tuned Model
├── README.md # Model documentation