Skip to content

About

Sentiment Analyzer ML Pipeline: Data preprocessing, model training, and FastAPI model deployment

Topics

Resources

Stars

1 star

Watchers

0 watching

Forks

Latest commit

 

History

7 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Sentiment Analyzer

Demonstrating ML pipelines and model deployment.

Features

  • ✅ ML Pipeline: Data preprocessing, model training, evaluation, serialization
  • ✅ Model Deployment: FastAPI REST API for real-time inference
  • ✅ Interactive UI: Streamlit app with real-time sentiment analysis
  • ✅ Monitoring: Health checks, metrics logging, version tracking

UI Demo

Streamlit UI Demo

Quick Start

1. Setup Environment

cd ml-pipeline-demo
python -m venv venv
source venv/bin/activate  # On Windows: venv\Scripts\activate
pip install -r requirements.txt

2. Train the Model

cd src
python pipeline.py

3. Launch the Streamlit UI (Recommended)

cd src
streamlit run app.py

Opens at http://localhost:8501 with:

  • 🎯 Beautiful gradient UI
  • 📊 Real-time sentiment analysis
  • 📈 Analysis history tracking
  • 🎲 Quick example buttons

Output:

ML Pipeline Demo: Sentiment Classification
==========================================
Loaded 200 samples
Training Metrics:
  Accuracy:  0.9750
  Precision: 0.9756
  Recall:    0.9750
  F1 Score:  0.9750
Model saved to: models/v1

3. Start the API Server

python server.py

Server runs at http://localhost:8000

4. Test Predictions

# Health check
curl http://localhost:8000/api/v1/health

# Make prediction
curl -X POST http://localhost:8000/api/v1/predict \
  -H "Content-Type: application/json" \
  -d '{"texts": ["This product is amazing!", "Terrible experience."]}'

Project Structure

ml-pipeline-demo/
├── src/
│   ├── app.py           # Streamlit UI (recommended)
│   ├── pipeline.py      # ML pipeline (preprocessing, training, evaluation)
│   └── server.py        # FastAPI model deployment server
├── models/              # Trained model artifacts (auto-generated)
└── requirements.txt

ML Pipeline Components

1. Data Preprocessing

# TF-IDF vectorization with n-grams
vectorizer = TfidfVectorizer(
    max_features=5000,
    ngram_range=(1, 2),
    stop_words='english'
)

2. Model Training

# Logistic Regression with balanced classes
model = LogisticRegression(
    C=1.0,
    max_iter=1000,
    class_weight='balanced'
)

3. Evaluation Metrics

  • Accuracy, Precision, Recall, F1 Score
  • Classification report with per-class metrics

4. Model Serialization

  • model.joblib: Trained classifier
  • vectorizer.joblib: Fitted TF-IDF vectorizer
  • metadata.json: Training metrics and hyperparameters

API Endpoints

Endpoint Method Description
/ GET API info
/api/v1/health GET Health check with model metrics
/api/v1/predict POST Single/batch predictions
/docs GET Interactive API documentation

Skills Demonstrated

Skill Implementation
ML Pipelines pipeline.py - preprocessing, training, evaluation
Model Deployment server.py - FastAPI REST API with health checks
Model Monitoring Metrics logging, version tracking
Interactive UI app.py - Streamlit with session state
Python Best Practices Type hints, docstrings, modular design

License

MIT

About

Sentiment Analyzer ML Pipeline: Data preprocessing, model training, and FastAPI model deployment

Topics

Resources

Stars

1 star

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages