A comprehensive MLOps project for sentiment analysis of movie reviews using Apache Spark MapReduce and machine learning.
This project implements a complete MapReduce + ML pipeline for predicting movie review sentiment:
- MapReduce Processing: Single-pass feature extraction with word counts and TF-IDF
- Machine Learning: Naive Bayes, Logistic Regression, and Random Forest classifiers
- MLOps: MLflow tracking, model versioning, and evaluation metrics
- Scalability: Apache Spark for distributed processing
MMS/
├── config/ # Configuration files
│ └── config.yaml # Main configuration
├── src/ # Source code
│ ├── config/ # Configuration management
│ ├── data/ # Data loading utilities
│ ├── processing/ # MapReduce processing
│ ├── models/ # Model training and evaluation
│ └── utils/ # Utility functions
├── scripts/ # Executable scripts
│ ├── train.py # Training script
│ ├── predict.py # Prediction script
│ └── evaluate.py # Evaluation script
├── tests/ # Unit tests
├── docker/ # Docker configuration
├── data/ # Data directory
├── models/ # Trained models
├── logs/ # Log files
├── artifacts/ # Model artifacts
└── mlruns/ # MLflow tracking
# Clone the repository
git clone <repository-url>
cd MMS
# Install dependencies
make install
# Setup project directories
make setupPlace your movie review datasets in the data/ directory:
train.csv- Training datatest.csv- Test dataunsupervised.csv- Additional unsupervised data
# Train with default settings
make train
# Train with cross-validation
make train-cv
# Train specific algorithm
python scripts/train.py --algorithm logistic_regression# Train LSTM model
make train-lstm
# Train Transformer model
make train-transformer
# Train BERT model
make train-bert
# Train any PyTorch model
python scripts/train_pytorch.py --model-type lstm# Train both Spark and PyTorch models and compare
make train-hybrid
# Custom hybrid training
python scripts/train_hybrid.py --spark-algorithm naive_bayes --pytorch-model bert --compare# Predict single text
make predict
# Batch prediction
python scripts/predict.py --model-path models/naive_bayes_model --input-file data/test.csv --output-file predictions.csv# Predict with PyTorch model
make predict-pytorch
# Custom PyTorch prediction
python scripts/predict_pytorch.py --model-path models/pytorch_lstm_model.pth --model-type lstm --text "This movie is great!"# Evaluate model
make evaluateEdit config/config.yaml to customize:
- Data paths: Raw and processed data locations
- Spark settings: Memory, cores, and other Spark configurations
- Text processing: Stopwords, vocabulary size, feature extraction
- Model parameters: Algorithm, hyperparameters, cross-validation
- MLOps settings: MLflow tracking, logging, and artifacts
# Build Docker image
make docker-build
# Run with Docker Compose
make docker-run- Spark UI: http://localhost:4040
- MLflow UI: http://localhost:5000
# Run all tests
make test
# Run tests with coverage
make test-coverage- Map Phase: Tokenize text → emit (word, 1) pairs
- Reduce Phase: Aggregate word counts → build vocabulary
- Feature Engineering: TF-IDF + bag-of-words extraction
- Model Training: Spark MLlib algorithms
- Data Preprocessing: Text cleaning and tokenization
- Vocabulary Building: Word-to-index mapping
- Model Architecture: LSTM/Transformer/BERT networks
- Training: Gradient descent with early stopping
- Best of Both Worlds: Spark for data processing + PyTorch for deep learning
- Performance Comparison: Side-by-side evaluation of different approaches
- Flexibility: Choose the best model for your specific use case
- Naive Bayes: Fast and effective for text classification
- Logistic Regression: Linear model with good interpretability
- Random Forest: Ensemble method for robust predictions
- LSTM: Long Short-Term Memory networks for sequence modeling
- Transformer: Self-attention based architecture for text understanding
- BERT: Pre-trained transformer model for state-of-the-art performance
- MLflow Integration: Experiment tracking and model versioning
- Comprehensive Logging: Structured logging with different levels
- Model Evaluation: Multiple metrics (accuracy, precision, recall, F1, AUC)
- Cross-Validation: Hyperparameter tuning with k-fold CV
- Artifact Management: Model and data versioning
- Experiment runs and parameters
- Model performance metrics
- Artifact storage and versioning
- Structured logging to files and console
- Different log levels (DEBUG, INFO, WARNING, ERROR)
- Performance and error tracking
# Format code
make format
# Type checking
make type-check- Create new modules in
src/ - Add corresponding tests in
tests/ - Update configuration in
config/config.yaml - Add CLI options in scripts
python scripts/train.py \
--algorithm naive_bayes \
--cross-validate \
--log-level DEBUGpython scripts/predict.py \
--model-path models/naive_bayes_model \
--input-file data/new_reviews.csv \
--output-file results/predictions.csvpython scripts/evaluate.py \
--model-path models/naive_bayes_model \
--test-file data/test.csv- Fork the repository
- Create a feature branch
- Make your changes
- Add tests for new functionality
- Run the test suite
- Submit a pull request
This project is licensed under the MIT License - see the LICENSE file for details.
- Apache Spark for distributed processing
- MLflow for MLOps capabilities
- The movie review dataset providers
- The open-source community for excellent tools and libraries



