Project Overview
The system combines TF-IDF-based text classification, real-time SocketIO moderation, and YouTube comment analysis into an end-to-end NLP workflow for automated sentiment analysis and moderation assistance.
Project Objectives
Build a three-class text classification system
Analyze YouTube comments and summarize sentiment trends.
Implement rule-based chatroom moderation assistance via SocketIO
Package Flask interfaces with smoke-tested CI and documented deployment limits
Evaluate all three labels with Macro F1 alongside accuracy
System Design
NLP & Classifier Engine
- •Lowercasing & punctuation removal
- •Alphanumeric token extraction
- •TF-IDF unigram & bigram features
- •LinearSVC model serving
Real-time Moderation
- •SocketIO connection events
- •VADER sentiment evaluation
- •Phrase-replacement rule match
- •Polite wording suggestions
YouTube Boundary
- •YouTube downloader integration
- •Inference batch orchestration
- •Sentiment-style distribution reporting
- •Individual comment highlight logs
Deployment & CI
- •Flask web interface
- •pytest unit & route coverage
- •GitHub Actions smoke checks
- •Render deployment profile
Data Flow Steps
User Input
User submits raw text comment, YouTube URL, or chat message
Preprocessing
Lowercase text -> remove URLs, tags, and non-alphabetic noise
TF-IDF Feature Engineering
Map cleaned unigrams & bigrams into a 5,000-dimensional vocabulary space
LinearSVC Classifier
Generate sentiment prediction using a trained LinearSVC model.
Moderation Engine
Evaluate connection states and flag VADER/rule-based matches
Suggestion Generator
Suggest polite phrase-replacements for flagged aggressive logs
Flask API
Lightweight serving layer returning JSON scores
Dashboard
Visualize predictions, sentiment distributions, moderation signals, and analysis summaries.
Moderation Simulator
Run the pipeline simulation on the left to see TF-IDF vector mapping and classification results.
Model Evaluation Results
The sentiment classification system is evaluated on holdout sets to verify label accuracy and performance consistency.
Performance verified on holdout data split.
API Design
REST API endpoints and Socket.IO real-time event interfaces
| Method | Endpoint | Responsibility |
|---|---|---|
| POST | /analyze | Accepts a YouTube URL, fetches public comments asynchronously using youtube_comment_downloader, and returns a job ID |
| GET | /analyze/status/<job_id> | Returns the status, progress, and sentiment classification results of a running analysis job |
| WS EVENT | send_message | Socket.IO event receiving real-time chat messages to verify toxicity |
| WS EVENT | receive_message | Socket.IO event broadcasting message results with optional polite alternatives |
Error Analysis
Sarcasm and irony frequently reduce classification accuracy.
Context-independent predictions may misclassify ambiguous comments.
Neutral comments are harder to distinguish from mild negative sentiment.
Rule-based moderation complements statistical predictions to reduce false positives.
Key Decisions
TF-IDF + LinearSVC over deep learning
The sparse linear pipeline keeps inference lightweight and avoids a GPU dependency for the three-class text task
SocketIO for chatroom
Real-time bidirectional communication enables live message interception and rewriting without page reload
YouTube comment integration
Exercises batch inference on fetched comments while keeping the classifier output visible for human interpretation
Macro F1 alongside accuracy
Macro averaging gives each of the three sentiment-style labels equal weight and exposes class-specific weakness
Visual Showcase










Engineering Challenges
Handling class imbalance across positive, neutral, and negative labels
Hate speech comments represent less than 5% of the dataset, causing the model to over-predict neutral labels.
Tuned hyperparameters and stratified train-test splits during feature transformation.
Improved prediction precision and recall across minority classes.
Reducing false positives in moderation recommendations
Sarcasm or mild words flagged as toxic could lead to unnecessary user censorship.
Layered a secondary rule-based filter that cross-references machine learning predictions against a custom semantic whitelist.
Reduced false positive moderation flags, protecting normal user discussion.
Designing lightweight inference without GPU dependencies
Deploying deep learning transformers (like BERT) requires expensive GPU hosting, making the project cost-prohibitive.
Optimized a TF-IDF vectorizer + LinearSVC pipeline and pickled the model into a serialized model artifact.
Achieved fast CPU-only inference times, enabling low-cost deployment on standard cloud instances.
Managing noisy YouTube comment text and preprocessing pipelines
Emojis, slang, HTML tags, and typos degraded TF-IDF vocabulary match rates and predictions.
Designed a regex-based text normalization pipeline that cleans HTML, parses common abbreviations, and stems tokens.
Enhanced feature overlap, raising overall prediction accuracy.
Balancing moderation sensitivity against user experience
Binary pass/fail filters do not capture gray areas of toxicity, frustrating users.
Layered VADER sentiment scores alongside machine learning classification to establish severity levels.
Smooth transition from automated checks to human-in-the-loop validation.
Boundaries & Learnings
Limitations
- •The 6,424 records are the test split; the training CSV source and license remain unverified
- •Positive, neutral, and negative labels are not direct hate-speech or protected-group abuse labels
- •No context window — classifies each message independently
- •Fetched-comment availability depends on an unofficial downloader and upstream platform changes
- •Chatroom suggestions use VADER, phrase rules, and term replacement rather than semantic rewriting
- •No multilingual support — English only
- •Predictions must not be the sole basis for moderation or enforcement decisions
Key Learnings
- •End-to-end NLP pipeline from raw text to Flask interfaces
- •Real-time SocketIO architecture for live moderation
- •Evaluation discipline — Macro F1 over raw accuracy
- •Integrating fetched YouTube comments into batch inference workflows
- •Deployment constraints and smoke-tested CI
- •Balancing inference speed vs model complexity