This project demonstrates an end-to-end Machine Learning + MLOps workflow for sentiment analysis, covering model training, experiment tracking, and model serving using FastAPI.
The goal is to build a production-style ML service that can be trained offline and served online via a REST API.
- Train a sentiment analysis model
- Track experiments using MLflow
- Save trained models locally
- Serve predictions using FastAPI
- REST API for real-time inference
- Clean, scalable project structure (
src/based)
SENTIMENT-MLOPS/ βββ src/ β βββ train.py # Model training logic β βββ predict.py # Model loading and inference β βββ api.py # FastAPI application β βββ init.py βββ data/ # Local datasets (ignored in git) βββ models/ # Trained models (ignored in git) βββ mlruns/ # MLflow experiments (ignored in git) βββ requirements.txt # Python dependencies βββ .gitignore βββ README.md
git clone https://github.com/OLAS05/sentiment-mlops.git
cd sentiment-mlops
2οΈβ£ Create and activate virtual environment
python -m venv .venv
source .venv/bin/activate # Linux / Mac
.venv\Scripts\activate # Windows
3οΈβ£ Install dependencies
pip install -r requirements.txt
π§ Model Training
Run the training script:
python src/train.py
This will:
Train the sentiment model
Log experiments to MLflow
Save the trained model locally
To view MLflow UI:
mlflow ui
Open: http://localhost:5000
π Run the API Server
Start the FastAPI app:
uvicorn src.api:app --host 0.0.0.0 --port 8000
Health Check
GET /
Prediction Endpoint
POST /predict
Sample Request
{
"texts": ["I love this product!", "This is terrible"]
}
Sample Response
[
{"label": "POSITIVE", "score": 0.99},
{"label": "NEGATIVE", "score": 0.98}
]
π οΈ Tech Stack
Python
FastAPI
Hugging Face Transformers
PyTorch
MLflow
Uvicorn