Experiment 3 - Lab Practice II | MTech 2026
LSTM-based Sentiment Analysis System with MLOps Best Practices
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
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
# Create virtual environment
python -m venv .venv
# Activate (Windows)
.venv\Scripts\activate
# Install dependencies
pip install -r requirements.txtpython train.pyThis 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/
mlflow ui --backend-store-uri sqlite:///mlflow.dbOpen: http://127.0.0.1:5000
cd api
python app.pyEndpoints available at http://127.0.0.1:8000:
- API Docs: http://127.0.0.1:8000/docs
- Dashboard: http://127.0.0.1:8000/dashboard
- Health: http://127.0.0.1:8000/health
| 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)
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
- 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
| 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 |
# 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
}| Metric | Score |
|---|---|
| Accuracy | ~87% |
| Precision | ~86% |
| Recall | ~88% |
| F1 Score | ~87% |
| AUC-ROC | ~94% |
reports/sentiment_distribution.png- Class distribution bar chartreports/review_length_analysis.png- Word count histograms & box plotsreports/sentiment_pie_chart.png- Pie chart of sentiment ratioreports/confusion_matrix.png- Model confusion matrixreports/training_history.png- Accuracy & loss curvesreports/classification_report.txt- Detailed classification report
| 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 |
python train.pymlflow ui --backend-store-uri sqlite:///mlflow.dbcd api
python app.pyjupyter notebook notebooks/sentiment_training.ipynbKashyap Barad β Lab Practice II (2026)
Experiment 3: Sentiment Intelligence System for Product Review