Sentiment Analysis at Scale: NLP Pipelines with Hugging Face and NestJS
How to deploy Hugging Face Transformer models behind a NestJS microservice to classify customer sentiment from social media feeds in real-time.
Sentiment Analysis at Scale: NLP Pipelines with Hugging Face and NestJS
Understanding customer sentiment helps brands react to crises before they escalate. Here is how we built a real-time sentiment classification pipeline.
1. Model Selection
We use the distilbert-base-uncased-fined-tuned-sst-2-english model from Hugging Face for fast inference:
pythonfrom transformers import pipeline classifier = pipeline("sentiment-analysis", model="distilbert-base-uncased-finetuned-sst-2-english") result = classifier("This product is amazing!") # [{'label': 'POSITIVE', 'score': 0.9998}]
2. NestJS Microservice Gateway
The NestJS backend queues incoming social media mentions and dispatches them to the Python inference service:
typescript@Injectable() export class SentimentService { async classify(text: string): Promise<SentimentResult> { const response = await this.httpService.post('http://ml-service:5000/predict', { text }); return response.data; } }
3. Real-Time Feed with Socket.IO
Classified results are pushed to connected dashboards via Socket.IO, showing live sentiment scores color-coded as green (positive), yellow (neutral), or red (negative).
Summary
By separating the ML inference layer from the API gateway, the system scales independently and processes thousands of mentions per minute.