Get your prediction in 3 steps
This guide walks you through setting up the microservice and making your first emotion prediction request.Install dependencies
Create a virtual environment and install the required packages:
The installation includes PyTorch, Flask, NLTK, scikit-learn, and other ML libraries. This may take a few minutes.
Start the microservice
Run the Flask server to start accepting prediction requests:You should see output confirming the server is running:The service loads three pre-trained models on startup:
- Word embedding dictionary (
models/word_dict.json) - PyTorch neural network (
models/model_26_87.12.pth) - Emotion classifier (
models/emotion_classifier.model) - TF-IDF vectorizer (
models/vectorizer2.pickle)
Make your first prediction
Send a GET request to the The endpoint returns an HTML page with prediction results showing:
/textbased_emotion endpoint with your text:- Whether the text contains inappropriate language
- Emotion classification (Positive/Negative)
- Scores for all six toxicity categories (toxic, severe_toxic, obscene, threat, insult, identity_hate)
- Additional extracted entities (countries, people names, dates)
Understanding the response
The microservice processes your text through multiple stages:-
Text preprocessing (microservice.py:94-120)
- Converts to lowercase
- Expands contractions (“can’t” → “cannot”)
- Removes hyperlinks and special characters
- Applies lemmatization
-
Neural network inference (microservice.py:203-204)
- Converts cleaned text to word embeddings
- Passes through the 4-layer neural network
- Generates six probability scores
-
Toxicity classification (microservice.py:206-219)
- Applies 0.29 threshold to each score
- Returns “Yes”/“No” for each category
- Flags as inappropriate if all six categories are positive
-
Sentiment analysis (microservice.py:221-229)
- Vectorizes text using TF-IDF
- Classifies overall emotion as Positive or Negative
- Adjusts based on inappropriate content detection
The threshold value of 0.29 (microservice.py:206) balances precision and recall based on validation set performance.
Try different examples
Test the model with various text inputs:Next steps
Installation guide
Learn about detailed setup options and model file requirements
Model architecture
Dive deeper into the neural network design and training