A FastAPI microservice for analyzing user comments in real-time.
It generates actionable signals such as intent, sentiment, toxicity, and spam detection, designed for moderation systems and social platforms.
- Multilingual Support (English + Hinglish)
- Intent Detection (question, appreciation, complaint, spam)
- Sentiment Analysis (positive, neutral, negative)
- Toxicity Detection
- Spam Detection (Hybrid System)
- Rule-based + ML-based scoring
- Optimized for CPU (16GB systems)
- Async + Threaded inference for speed
- LRU Cache for repeated queries
- Batch Processing Support
+------------------+
| Input Comment |
+--------+---------+
|
v
+----------------------+
| Preprocessing |
+----------------------+
|
+---------+---------+
| |
v v
+----------------+ +----------------------+
| Rule Engine | | ML Models |
| (Spam Signals) | | Intent, Sentiment, |
| | | Toxicity |
+--------+-------+ +----------+-----------+
| |
+----------+-----------+
v
+----------------------+
| Final Aggregation |
+----------------------+
|
v
+----------------------+
| API Response (JSON) |
+----------------------+
The pipeline combines:
Detects:
- Links (even obfuscated)
- Handles (
@username) - Call-to-actions (DM, join, etc.)
- Scam keywords (earn money, crypto, etc.)
- Adult content
- Phone numbers
| Task | Model |
|---|---|
| Intent | MoritzLaurer/multilingual-MiniLMv2-L6-mnli-xnli |
| Sentiment | finiteautomata/bertweet-base-sentiment-analysis |
| Toxicity | unitary/multilingual-toxic-xlm-roberta |
| Spam | mrm8488/bert-tiny-finetuned-sms-spam-detection |
POST /analyze
Request:
{
"text": "This video is amazing bro!"
}Response:
{
"intent": "appreciation",
"intent_confidence": 0.91,
"labels": [
{"label": "appreciation", "score": 0.91}
],
"sentiment": "positive",
"sentiment_confidence": 0.95,
"toxicity": 0.01,
"is_spam": false
}POST /analyze-batch
Request:
[
{"text": "Nice video!"},
{"text": "Earn money fast click here"}
]- LRU Cache: (2048 entries) for repeated comments
- ThreadPoolExecutor: (4 workers) for heavy inference
- CPU-only execution: (
device = -1) - Async API: FastAPI async endpoints
42.63% (8557 / 20071)
Note: The previous model used was
cardiffnlp/twitter-xlm-roberta-base-sentiment. We are not strictly benchmarking against the original model, but it serves as a useful reference point. The newer model —finiteautomata/bertweet-base-sentiment-analysis— is more specialized for social media text and is expected to perform better.
It is particularly stronger in handling:
- Slang
- Abbreviations
- Mixed language (Hinglish)
Comparisons:
- Previous Model (
cardiffnlp/twitter-xlm-roberta-base-sentiment):
RAW MODEL REPORT Accuracy:29.85% (2029/6797)| Time:16.95s(0.0025s per comment) - Current Model (
finiteautomata/bertweet-base-sentiment-analysis):
RAW MODEL REPORT Accuracy:76.93% (5229/6797)| Time:16.44s(0.0024s per comment)
77.81% (15617 / 20071)
77.17% (15489 / 20071)
- Total Time:
3411.46 seconds - Average:
~0.17 secondsper comment
- positive → neutral: 3930
- neutral → negative: 1758
- positive → negative: 830
- negative → neutral: 474
- neutral → positive: 453
- toxic (1) → non-toxic (0): 321
- non-toxic (0) → toxic (1): 153
- spam (1) → not spam (0): 375
- not spam (0) → spam (1): 227
Sentiment accuracy appears lower due to a design decision in the pipeline:
When a comment is confidently classified as spam, the system skips all ML models and directly returns:
if spam_result["is_spam"]:
return {
"intent": "spam",
"intent_confidence": 1.0,
"labels": [{"label": "spam", "score": 1.0}],
"sentiment": "neutral",
"sentiment_confidence": 1.0,
"toxicity": 0.0,
"is_spam": True
}Note: For now we didn't have any data to test the accuracy of intent. We are currently building a suitable dataset for that, we apologize for that.
We have currently hosted this at Hugging Face. You can too just make a space and add the app.py, Dockerfile, and requirements.txt.
🔗 Hugging Face Link: lalit-narayan/youtube-comment-analyzer
- Better Hinglish fine-tuning
- GPU acceleration
- Dashboard UI
- Streaming inference