STABLE  ·  Case Study 06  ·  NLP / Machine Learning

SENTIMENT Analysis

A multi-class NLP sentiment engine that combines VADER lexicon scoring with a fine-tuned BERT classifier — trained on 50K+ reviews for nuanced 5-class emotion detection.

● STABLE V.1.5.0 Model Ready Python BERT NLP
93%
Accuracy
50K+
Samples
5
Classes

Binary Sentiment Isn't Enough

Simple positive/negative sentiment classification misses the nuance real businesses need. A review saying "The product is okay but the shipping was a disaster" carries mixed sentiment — binary classifiers collapse this to a single polarity and lose the signal entirely. Product teams need to know which dimension failed, not just that something did.

Off-the-shelf models also struggle with domain-specific language — technical jargon, industry slang, irony, and sarcasm that is perfectly legible to a human reader but systematically misclassified by generic pretrained models. The solution required both a richer label space (five classes) and a model that could adapt to the target domain through fine-tuning.

Hybrid Lexicon + Transformer Pipeline

The key insight is that VADER and BERT are complementary — VADER is fast and rule-based with strong baseline performance on explicit sentiment words, while BERT captures contextual meaning and long-range dependencies. Combining their outputs as a hybrid feature vector before the classification head outperforms either model alone.

Raw Review Text
Preprocessing
VADER Lexicon Score
+
BERT Tokenizer → Embeddings
Hybrid Feature Vector
Fine-tuned BERT Classifier
Very Negative
|
Negative
|
Neutral
|
Positive
|
Very Positive
Confidence Score + Class Label

The preprocessing stage handles tokenisation, lowercasing, emoji-to-text expansion, and noise removal. SMOTE oversampling and class-weighted loss address the severe class imbalance inherent in review datasets, where neutral reviews dominate by a factor of 3–4×.

Built With

🐍 Python 3.11 🤗 BERT (HuggingFace Transformers) 📖 VADER (NLTK) 🐼 Pandas 🔢 NumPy 📈 Plotly (Visualisation) ⚙️ Scikit-learn ⚡ CUDA / GPU Training 🤗 HuggingFace Hub

What It Achieved

What I'd Do Differently

Lesson 01

Hybrid beats pure BERT on mixed text

VADER alone fails on mixed and sarcastic inputs because it processes each token independently. The hybrid architecture was not an optimisation — it was a fundamental requirement to reach meaningful accuracy on the hard cases.

Lesson 02

Address class imbalance before training

Neutral reviews overwhelmingly dominate real-world datasets. Training without correction produced a model that predicted "Neutral" 60% of the time. SMOTE oversampling and per-class loss weighting were both needed to fix this.

Lesson 03

Domain-adaptive fine-tuning is non-negotiable

General BERT underperforms on industry-specific vocabulary. Even 2,000 in-domain fine-tuning steps significantly shifted the model's probability distributions for product jargon, brand names, and technical slang.

Lesson 04

Confidence scores matter more than labels

For downstream business use, a confidence score below a threshold is often more actionable than the class label itself. Building confidence-aware inference from the start — rather than retrofitting it — shapes better product decisions.

Interested in NLP engineering?

Check out the full model training pipeline on GitHub or get in touch to discuss applied ML projects.