Views
No views yet
1from transformers import pipeline
2
3# The easiest way to use the model
4classifier = pipeline("text-classification",
5 model="nahiar/spam-detection-bert-v3",
6 tokenizer="nahiar/spam-detection-bert-v3")
7
8# Test with text
9texts = [
10 "lacak hp hilang by no hp / imei lacak penipu/scammer/tabrak lari/terror/revengeporn sadap / hack / pulihkan akun",
11 "Senin, 21 Juli 2025, Samapta Polsek Ngaglik melaksanakan patroli stasioner balong jalan palagan donoharjo",
12 "Mari berkontribusi terhadap gerakan rakyat dengan membeli baju ini seharga Rp 160.000. Hubungi kami melalui WA 08977472296"
13]
14
15results = classifier(texts)
16for text, result in zip(texts, results):
17 print(f"Text: {text}")
18 print(f"Result: {result['label']} (confidence: {result['score']:.4f})")
19 print("---")| Metric | HAM | SPAM | Overall |
|---|---|---|---|
| Precision | 98% | 77% | 95% |
| Recall | 96% | 85% | 95% |
| F1-Score | 97% | 81% | 95% |
| Overall Accuracy | - | - | 95% |
0: "HAM" (not spam)
1: "SPAM" (spam)1import torch
2from transformers import AutoTokenizer, AutoModelForSequenceClassification
3
4# Load model and tokenizer
5tokenizer = AutoTokenizer.from_pretrained("nahiar/spam-detection-bert-v3")
6model = AutoModelForSequenceClassification.from_pretrained("nahiar/spam-detection-bert-v3")
7
8def predict_spam(text):
9 inputs = tokenizer(text, return_tensors="pt", padding=True, truncation=True)
10 outputs = model(**inputs)
11 probs = torch.softmax(outputs.logits, dim=1)
12 predicted_label = torch.argmax(probs, dim=1).item()
13 confidence = probs[0][predicted_label].item()
14 label_map = {0: "HAM", 1: "SPAM"}
15 return label_map[predicted_label], confidence
16
17# Test
18text = "Dapatkan uang dengan mudah! Klik link ini sekarang!"
19result, confidence = predict_spam(text)
20print(f"Prediksi: {result} (Confidence: {confidence:.4f})")1@misc{nahiar_spam_detection_bert,
2 title={Indonesian Spam Detection BERT},
3 author={Raihan Hidayatullah Djunaedi},
4 year={2025},
5 url={https://huggingface.co/nahiar/spam-detection-bert-v3}
6}