SpamShield: High-Performance Multilingual Spam & Category Detection
Production-grade, ultra-low-latency multilingual spam detection and 6-category classification suite powered by ONNX Runtime.
Overview • Model Variants • Benchmarks • Quickstart • Categories • NSFW Scanner
📋 Overview
SpamShield is an industrial-strength moderation engine built for real-time chat environments (Telegram, Discord, web applications). It couples dual-tier text analysis with computer vision media verification:
- Binary ONNX Classifier: High-precision detection of spam vs. legitimate (ham) messages.
- Category ONNX Classifier: Multi-class categorization across 6 distinct spam threats.
- NSFW Vision Model: Embedded computer vision ONNX classifier for explicit media scanning.
✨ Key Advantages
- ⚡ Sub-5ms Inference: Native ONNX graph execution with zero heavy transformer overhead.
- 🔤 Unicode & Homoglyph Resilient: Built-in NFKD normalization, leetspeak decoding, character repetition suppression, and Cyrillic/Greek homoglyph transliteration.
- 🎯 Three Tuned Variants: Select between Lite, Flash (default), and Edge depending on your throughput and accuracy requirements.
- 🛡️ Zero External API Dependency: Runs completely on CPU / offline with minimal RAM footprint (<20MB).
🚀 Model Variants
| Variant | Target Use Case | Binary ONNX Size | Feature Vocabulary | Target Precision |
|---|---|---|---|---|
Lite | Low-memory servers, mobile/embedded bots, edge devices | ~273 KB | 5,000 Word + 2,500 Char | 98.50% |
Flash (Recommended) | General high-traffic group moderation & balanced workload | ~706 KB | 12,000 Word + 7,000 Char | 98.20% |
Edge | Enterprise moderation, high-depth conversational analysis | ~1.28 MB | 22,000 Word + 12,000 Char | 98.13% |
📊 Performance & Benchmarks
Evaluated on global multi-lingual test sets across English, German, Russian, Spanish, Hinglish, Hindi, and Arabic.
| Metric | Lite | Flash | Edge |
|---|---|---|---|
| Binary Accuracy | 95.85% | 97.17% | 97.60% |
| Spam Precision | 98.50% | 98.20% | 98.13% |
| Recall | 93.36% | 96.28% | 97.20% |
| F1 Score | 0.9587 | 0.9723 | 0.9766 |
| Optimal Spam Threshold | 0.6719 | 0.5452 | 0.4818 |
| Average Inference Latency | ~1.5 ms | ~3.2 ms | ~4.8 ms |
🏷️ Detection Categories
The category model classifies flagged messages into 6 distinct vectors:
- 🎣
phishing— Fake login portals, credential harvesters, spoofed domain links. - 💼
job_scams— Fake freelance/remote hiring scams, task-based pay scams, upfront deposit requests. - 🪙
crypto— Airdrop drainers, wallet seed requests, fake trading bots, pump-and-dump signals. - 🔞
adult— NSFW text, escort services, explicit solicitations, illicit media links. - 📢
marketing— Unsolicited bulk promotion, channel cross-spam, aggressive affiliate links. - 🎁
giveaway— Fake lottery rewards, gift card scams, social media reward manipulation.
💻 Quickstart
1. Installation
pip install onnxruntime numpy
2. Basic Inference (Python)
import numpy as np
import onnxruntime as ort
# Load binary classifier (e.g. Flash variant)
binary_session = ort.InferenceSession("Flash/binary_model.onnx", providers=["CPUExecutionProvider"])
category_session = ort.InferenceSession("Flash/category_model.onnx", providers=["CPUExecutionProvider"])
def classify_message(text: str):
# Pass text array to ONNX string input
input_data = np.array([[text]], dtype=object)
# 1. Binary classification
input_name = binary_session.get_inputs()[0].name
outputs = binary_session.run(None, {input_name: input_data})
spam_prob = float(outputs[1][0][1]) if len(outputs) > 1 else float(outputs[0][0])
is_spam = spam_prob >= 0.5452 # Flash threshold
# 2. Category classification if spam
category = "ham"
if is_spam:
cat_input_name = category_session.get_inputs()[0].name
cat_outputs = category_session.run(None, {cat_input_name: input_data})
category = str(cat_outputs[0][0])
return {"is_spam": is_spam, "spam_probability": spam_prob, "category": category}
# Test sample
result = classify_message("Claim 5000 USDT reward immediately by connecting your wallet here: http://fake-airdrop.xyz")
print(result)
# {'is_spam': True, 'spam_probability': 0.987, 'category': 'crypto'}
🖼️ NSFW Image Scanner
The repository also includes an ONNX computer vision model in nsfw/ for scanning image attachments:
- Architecture: MobileNet/EfficientNet vision backbone exported to ONNX Runtime.
- Input: Preprocessed 224x224 RGB image tensors.
- Output: Softmax probabilities across
Safevs.NSFW.
🔗 Dataset
- AbhinavMaurya/SpamShield-Datasets — Training corpus and benchmark splits.
📜 License
This model suite and codebase are released under the MIT License.