← Back to labs
Case study · NLP engineering

CommentSense

A multilingual NLP demo with a feedback-driven retrain pipeline. Sentiment analysis and text classification in English, Serbian, and German — built with scikit-learn and served via FastAPI.

3languages
6categories
HybridML + lexicon
Activefeedback loop
The problem

Understand product reviews in any language

Product reviews come in many languages, but most NLP tools only support English. CommentSense fills the gap for English, Serbian, and German — detecting both the language and the sentiment correctly, even without diacritics. A feedback loop lets the model improve from real user input.

Architecture

Five phases, two layers

Phase 1

Multilingual lexicons

Built sentiment and classification lexicons for English, Serbian, and German from scratch. Each language has 40+ positive and negative words, intensifiers, and negations.

  • Zero dependencies — pure Python dictionaries
  • Negation window handling ('nije dobar' = negative)
  • Intensifier boost ('very good' scores higher than 'good')
  • Auto-detect language from text content
Phase 2

TF-IDF + Logistic Regression

Trained a machine learning model on synthetic data generated from the lexicons. Uses TF-IDF vectorization with Logistic Regression for sentiment and text classification.

  • Synthetic training data with negation patterns and templates
  • TF-IDF with ngram_range=(1,2) for phrase awareness
  • Logistic Regression with balanced training per class
  • Hybrid approach: ML model with lexicon fallback below 0.85 confidence
Phase 3

FastAPI service

Deployed as part of the najdiavto-ml FastAPI service on Railway. Four NLP endpoints serving both sentiment analysis and text classification.

  • POST /api/nlp/sentiment — sentiment with per-class probabilities
  • POST /api/nlp/classify — text classification into 6 categories
  • POST /api/nlp/analyze — combined analysis in one call
  • POST /api/nlp/retrain — retrain models from human feedback
Phase 4

Feedback loop

Every prediction gets a thumbs-up/down rating that saves to MongoDB. A retrain endpoint pulls verified feedback and merges it with synthetic data to continuously improve model accuracy.

  • Thumbs up/down widget blocks further analysis until rated
  • Feedback stored in MongoDB via Node.js backend
  • Verified (thumbs-up) data weighted 3x in retraining
  • POST /api/nlp/retrain triggers full pipeline
Phase 5

React UI

A clean, modern React frontend deployed on Vercel. Supports real-time input, sample texts, language selection, and visual confidence bars.

  • React 18 + TypeScript + Vite
  • Cartoon theme (archived) / Modern professional theme (current)
  • Sample texts for quick testing in all 3 languages
  • Keyboard shortcuts: ⌘+Enter / Ctrl+Enter
Stack

Tools used

Pythonscikit-learnFastAPIReactTypeScriptMongoDBDockerVercel