Σ
λ
[]

Comment Sentiment & Moderation Assistant

Three-class text classification system with a YouTube comment-analysis interface and a separate rule-based SocketIO chatroom assistant. The classifier reports 78.50% accuracy and 0.7832 Macro F1 on a 6,424-record holdout.

Flaskscikit-learnNLPSocketIOTF-IDF
SYSTEM METRICS & ABSTRACTION LAYERS
Backend Layer
Flask API Layer
Real-Time Pipe
SocketIO Real-Time Pipe
ML Classifier
TF-IDF + LinearSVC
Deployment
Render Production
CI/CD Pipeline
GitHub Actions
01 / Challenge

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.

02 / Goals

Project Objectives

01

Build a three-class text classification system

02

Analyze YouTube comments and summarize sentiment trends.

03

Implement rule-based chatroom moderation assistance via SocketIO

04

Package Flask interfaces with smoke-tested CI and documented deployment limits

05

Evaluate all three labels with Macro F1 alongside accuracy

03 / Architecture

System Design

User Comment
Raw text submitted to analyzer or chatroom
Text Preprocessing
Lowercasing, punctuation & noise removal
TF-IDF Vectorization
Unigram & bigram 5,000-feature mapping
LinearSVC Prediction
Lightweight inference for label assignment
VADER & Phrase Rules
Interception & flagging checks
Polite Suggestion Engine
Alternative term-replacement output

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
04 / Pipeline

Data Flow Steps

01

User Input

User submits raw text comment, YouTube URL, or chat message

02

Preprocessing

Lowercase text -> remove URLs, tags, and non-alphabetic noise

03

TF-IDF Feature Engineering

Map cleaned unigrams & bigrams into a 5,000-dimensional vocabulary space

04

LinearSVC Classifier

Generate sentiment prediction using a trained LinearSVC model.

05

Moderation Engine

Evaluate connection states and flag VADER/rule-based matches

06

Suggestion Generator

Suggest polite phrase-replacements for flagged aggressive logs

07

Flask API

Lightweight serving layer returning JSON scores

08

Dashboard

Visualize predictions, sentiment distributions, moderation signals, and analysis summaries.

05 / Simulator

Moderation Simulator

1
Input
2
Clean
3
TF-IDF
4
Model
5
Rules
6
Output
»

Run the pipeline simulation on the left to see TF-IDF vector mapping and classification results.

06 / Benchmarks

Model Evaluation Results

The sentiment classification system is evaluated on holdout sets to verify label accuracy and performance consistency.

0.00%
Accuracy
0.0000
Macro F1
0
Test Records
0
Classes
CPU
Inference
scikit-learn
Framework

Performance verified on holdout data split.

07 / Endpoints

API Design

REST API endpoints and Socket.IO real-time event interfaces

MethodEndpointResponsibility
POST/analyzeAccepts 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 EVENTsend_messageSocket.IO event receiving real-time chat messages to verify toxicity
WS EVENTreceive_messageSocket.IO event broadcasting message results with optional polite alternatives
08 / Evaluation

Error Analysis

01

Sarcasm and irony frequently reduce classification accuracy.

02

Context-independent predictions may misclassify ambiguous comments.

03

Neutral comments are harder to distinguish from mild negative sentiment.

04

Rule-based moderation complements statistical predictions to reduce false positives.

09 / Rationale

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

10 / Screenshots

Visual Showcase

YouTube Home
fig.01 — YouTube URL input for comment analysisYOUTUBE
YouTube Results
fig.02 — Per-comment sentiment labels and derived risk indicatorsYOUTUBE
Full Results
fig.03 — Full comment analysis reportYOUTUBE
Comment List
fig.04 — Classified comment list with highlightsRESULTS
Insights Panel
fig.05 — Sentiment distribution and derived risk summaryINSIGHTS
Scans
fig.06 — Scan history and batch resultsINSIGHTS
Chatroom Home
fig.07 — Rule-based chatroom assistant entry screenCHATROOM
Chatroom Result
fig.08 — Rule-based message flagging in the chatroomCHATROOM
Chatroom Moderation
fig.09 — Suggested alternative wording from phrase rulesCHATROOM
Polite Conversion
fig.10 — Rule-based term-replacement outputCHATROOM
11 / Complexity

Engineering Challenges

01

Handling class imbalance across positive, neutral, and negative labels

Problem

Hate speech comments represent less than 5% of the dataset, causing the model to over-predict neutral labels.

Solution

Tuned hyperparameters and stratified train-test splits during feature transformation.

Result

Improved prediction precision and recall across minority classes.

02

Reducing false positives in moderation recommendations

Problem

Sarcasm or mild words flagged as toxic could lead to unnecessary user censorship.

Solution

Layered a secondary rule-based filter that cross-references machine learning predictions against a custom semantic whitelist.

Result

Reduced false positive moderation flags, protecting normal user discussion.

03

Designing lightweight inference without GPU dependencies

Problem

Deploying deep learning transformers (like BERT) requires expensive GPU hosting, making the project cost-prohibitive.

Solution

Optimized a TF-IDF vectorizer + LinearSVC pipeline and pickled the model into a serialized model artifact.

Result

Achieved fast CPU-only inference times, enabling low-cost deployment on standard cloud instances.

04

Managing noisy YouTube comment text and preprocessing pipelines

Problem

Emojis, slang, HTML tags, and typos degraded TF-IDF vocabulary match rates and predictions.

Solution

Designed a regex-based text normalization pipeline that cleans HTML, parses common abbreviations, and stems tokens.

Result

Enhanced feature overlap, raising overall prediction accuracy.

05

Balancing moderation sensitivity against user experience

Problem

Binary pass/fail filters do not capture gray areas of toxicity, frustrating users.

Solution

Layered VADER sentiment scores alongside machine learning classification to establish severity levels.

Result

Smooth transition from automated checks to human-in-the-loop validation.

12 / Limits & Takeaways

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