Skip to content

kashyap1757/Sentiment-Intelligence-System

Repository files navigation

🧠 Sentiment Intelligence System

Experiment 3 - Lab Practice II | MTech 2026
LSTM-based Sentiment Analysis System with MLOps Best Practices


πŸ“‹ Project Overview

A comprehensive sentiment analysis system that classifies product/movie reviews as Positive or Negative using a Bidirectional LSTM deep learning model. The system includes:

  • Deep Learning Model: Bidirectional LSTM trained on 50,000 IMDB reviews
  • Interactive Dashboard: Real-time sentiment visualization with charts & analytics
  • REST API: FastAPI-based inference service with monitoring
  • MLOps Pipeline: MLflow experiment tracking, model versioning, and reproducible experiments

πŸ—οΈ Architecture

Sentiment-Intelligence-System/
β”œβ”€β”€ data/
β”‚   └── IMDB Dataset.csv           # Training dataset (50K reviews)
β”œβ”€β”€ models/
β”‚   β”œβ”€β”€ sentiment_lstm_model.h5    # Trained LSTM model
β”‚   └── tokenizer.pkl             # Fitted tokenizer
β”œβ”€β”€ notebooks/
β”‚   └── sentiment_training.ipynb   # Jupyter training notebook
β”œβ”€β”€ api/
β”‚   β”œβ”€β”€ app.py                    # FastAPI REST API
β”‚   └── predictions_log.csv       # Prediction history
β”œβ”€β”€ dashboard/
β”‚   └── index.html                # Interactive visualization dashboard
β”œβ”€β”€ reports/
β”‚   β”œβ”€β”€ sentiment_distribution.png
β”‚   β”œβ”€β”€ review_length_analysis.png
β”‚   β”œβ”€β”€ sentiment_pie_chart.png
β”‚   β”œβ”€β”€ confusion_matrix.png
β”‚   β”œβ”€β”€ training_history.png
β”‚   └── classification_report.txt
β”œβ”€β”€ train.py                      # Training script with MLflow
β”œβ”€β”€ requirements.txt              # Python dependencies
β”œβ”€β”€ mlflow.db                     # MLflow tracking database
└── README.md                     # This file

πŸš€ Quick Start

1. Setup Environment

# Create virtual environment
python -m venv .venv

# Activate (Windows)
.venv\Scripts\activate

# Install dependencies
pip install -r requirements.txt

2. Train the Model (with MLflow Tracking)

python train.py

This will:

  • Load and analyze the IMDB dataset
  • Generate data visualizations in reports/
  • Train a Bidirectional LSTM model
  • Log all hyperparameters, metrics, and artifacts to MLflow
  • Save the model and tokenizer to models/

3. View MLflow Experiment Dashboard

mlflow ui --backend-store-uri sqlite:///mlflow.db

Open: http://127.0.0.1:5000

4. Start the API Server

cd api
python app.py

Endpoints available at http://127.0.0.1:8000:


πŸ“Š Core Components

1. Deep Learning β€” LSTM Sentiment Classification

Parameter Value
Architecture Bidirectional LSTM
Vocab Size 10,000
Embedding Dim 128
LSTM Units 64
Dropout Rate 0.3
Max Sequence Len 200
Optimizer Adam
Loss Function Binary Crossentropy
Dataset IMDB (50K reviews)

Model Architecture:

Embedding (10000, 128) β†’ Bidirectional LSTM (64) β†’ Dropout (0.3)
β†’ Bidirectional LSTM (32) β†’ Dropout (0.3) β†’ Dense (64, ReLU)
β†’ Dropout (0.3) β†’ Dense (1, Sigmoid)

2. Data Visualization Dashboard

The interactive dashboard (http://127.0.0.1:8000/dashboard) includes:

  • πŸ“Š KPI Metrics: Total predictions, positive/negative counts, avg confidence
  • πŸ₯§ Sentiment Distribution: Doughnut chart showing positive vs negative ratio
  • πŸ“ˆ Confidence Trend: Line chart tracking confidence scores over time
  • πŸ“Š Confidence Histogram: Distribution of model confidence scores
  • πŸ’¬ Word Cloud: Most frequent words in analyzed reviews
  • πŸ“ Review Length Analysis: Word count distribution chart
  • πŸ“‹ Predictions Table: Recent prediction history with sentiment badges
  • πŸ” Live Prediction: Real-time review analysis input

3. MLOps β€” Experiment Tracking & Deployment

MLflow Integration

  • Experiment Tracking: All hyperparameters, metrics, and artifacts logged
  • Model Versioning: Models registered in MLflow Model Registry
  • Metric History: Per-epoch training/validation accuracy and loss
  • Artifact Storage: Visualizations, reports, and model files

REST API Features

Endpoint Method Description
/ GET API status & info
/health GET Model health check
/predict POST Single review prediction
/batch-predict POST Batch prediction
/predictions GET Prediction history
/analytics/summary GET Dashboard analytics data
/metrics GET API monitoring metrics
/docs GET Swagger API documentation
/dashboard GET Interactive visualization

API Usage Example

# Single prediction
curl -X POST http://127.0.0.1:8000/predict \
  -H "Content-Type: application/json" \
  -d '{"review": "This product is amazing and works perfectly!"}'

# Response:
{
  "timestamp": "2026-03-10T05:30:00",
  "review": "This product is amazing and works perfectly!",
  "sentiment": "Positive",
  "confidence": 0.9234,
  "review_length": 7,
  "latency_ms": 45.2
}

πŸ“ˆ Expected Outcomes

Model Performance

Metric Score
Accuracy ~87%
Precision ~86%
Recall ~88%
F1 Score ~87%
AUC-ROC ~94%

Generated Reports

  • reports/sentiment_distribution.png - Class distribution bar chart
  • reports/review_length_analysis.png - Word count histograms & box plots
  • reports/sentiment_pie_chart.png - Pie chart of sentiment ratio
  • reports/confusion_matrix.png - Model confusion matrix
  • reports/training_history.png - Accuracy & loss curves
  • reports/classification_report.txt - Detailed classification report

πŸ› οΈ Technology Stack

Component Technology
Deep Learning TensorFlow/Keras
Model Architecture Bidirectional LSTM
API Framework FastAPI
Experiment Tracking MLflow
Visualization Chart.js, Matplotlib, Seaborn
Data Processing Pandas, NumPy
NLP Preprocessing Keras Tokenizer
Dataset IMDB Movie Reviews

πŸ“ How to Run Each Component

Training with Experiment Tracking

python train.py

MLflow UI

mlflow ui --backend-store-uri sqlite:///mlflow.db

API + Dashboard

cd api
python app.py

Jupyter Notebook (Alternative Training)

jupyter notebook notebooks/sentiment_training.ipynb

πŸ‘¨β€πŸ’» Author

Kashyap Barad β€” Lab Practice II (2026)
Experiment 3: Sentiment Intelligence System for Product Review

About

A Python-based sentiment analysis system that processes text data to detect and classify emotional tone, enabling actionable insights from user feedback and social content.

Topics

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

No releases published

Packages

 
 
 

Contributors