SpamDetection is a production-oriented TensorFlow project for Russian spam-risk detection in text messages. It combines deep-learning training with practical inference interfaces, so you can go from model idea to usable anti-spam signal fast.
It includes:
- Model training (
train.py) - CLI inference (
predict.py) - HTTP API inference (
server.py)
Pretrained artifacts are already in the repository, so you can run real predictions right away.
python3.9 -m venv .venv
source .venv/bin/activate
pip install -r requirements.txt
python predict.py "ваше сообщение"The model outputs a risk_score in the range [0, 1]:
0= low spam risk1= high spam risk
In CLI mode (predict.py), this score is mapped to:
<= 0.3→safe(✅ Безопасно)0.3 < score <= 0.7→suspicious(⚠️ Сомнительно)> 0.7→high_risk(🚨 Высокий риск)
/home/runner/work/SpamDetection/SpamDetection/train.py— train/evaluate model and save artifacts/home/runner/work/SpamDetection/SpamDetection/predict.py— run single-message prediction from CLI/home/runner/work/SpamDetection/SpamDetection/server.py— Flask API (/analyze,/health)/home/runner/work/SpamDetection/SpamDetection/requirements.txt— Python dependencies/home/runner/work/SpamDetection/SpamDetection/spam_classifier_tensorflow.keras— trained model/home/runner/work/SpamDetection/SpamDetection/tokenizer_tensorflow.pickle— trained tokenizer
train.py loads:
hf://datasets/darkQibit/russian-spam-detection/processed_combined.parquet
Expected columns:
message(text)label(binary target)
- Keras
Tokenizer(num_words=5000, oov_token="<unk>") - Sequence padding/truncation to
maxlen=150(post mode)
Architecture:
Embedding(5000, 128)LSTM(64, dropout=0.2, recurrent_dropout=0.2)Dropout(0.5)Dense(1, activation="sigmoid")
Training setup:
train_test_split(test_size=0.2, random_state=42)batch_size=32- up to
10epochs - early stopping on validation loss (
patience=3)
Artifacts produced:
spam_classifier_tensorflow.kerastokenizer_tensorflow.pickle
python predict.py "хочешь взять долги и кредиты без процентов"Example output:
--- Результат анализа ---
Сообщение: 'хочешь взять долги и кредиты без процентов'
Оценка риска: 0.5812 (58.12%)
Уровень угрозы: ⚠️ Сомнительно (требуется проверка)
-------------------------
python train.pypython server.pyServer address:
- host:
0.0.0.0 - port:
7503
curl http://127.0.0.1:7503/healthResponse:
{"status":"ok"}curl -X POST http://127.0.0.1:7503/analyze \
-H "Content-Type: application/json" \
-d '{"message":"хочешь взять долги и кредиты без процентов"}'Response:
{"risk_score":0.5811898708343506}Validation behavior:
- non-JSON body →
400 - missing
messagefield →400 - non-string
message→400 - internal prediction error →
500
- Optimized for Russian-language spam patterns; quality may degrade on other domains/languages.
- Output is a model score, not a guaranteed fraud verdict.
- Thresholds in
predict.pyare heuristic and may need recalibration for your use case.