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
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:
| 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% |
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 |
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.pip install onnxruntime numpy
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'}
The repository also includes an ONNX computer vision model in nsfw/ for scanning image attachments:
Safe vs. NSFW.This model suite and codebase are released under the MIT License.
v001/openshield.onnx 6 MBEdge/category_model.onnx 3 MBFlash/category_model.onnx 1 MBEdge/binary_model.onnx 1 MBFlash/binary_model.onnx 705.7 kBLite/category_model.onnx 575.4 kBLite/binary_model.onnx 272.9 kBnsfw/model.onnx 80.2 kB