Transforming Text into Insightful Sentiment Analysis
This project implements a complete MLOps pipeline for sentiment analysis that transforms social media texts into insights. The system classifies text into positive, negative, or neutral sentiment using state-of-the-art transformer models with production monitoring infrastructure.
The project was developed through four distinct phases, each building upon the previous to create a comprehensive MLOps ecosystem:
Phase 1: Foundation & Model Integration
- Core sentiment analysis API with RoBERTa model
- Basic evaluation framework and health monitoring
- RESTful endpoints for single and batch predictions
Phase 2: Infrastructure & Monitoring
- Complete containerized stack with Docker Compose
- Real-time metrics collection with Prometheus
- Professional dashboards with Grafana
- Production monitoring infrastructure
Phase 3: CI/CD & Automation
- Automated testing pipeline with GitHub Actions
- Model fine-tuning with PEFT/LoRA techniques
- Multi-platform deployment (HuggingFace Spaces, DockerHub)
- MLflow experiment tracking integration
Phase 4: Advanced MLOps Features
- Apache Airflow workflow orchestration
- Automated model evaluation scheduling
- Statistical data drift detection
- Production alerting and quality assurance
The system follows microservices architecture principles with containerized components that can scale independently.
MLOps-First Approach: This project includes comprehensive monitoring, automated testing, and deployment pipelines that are often missing in academic projects.
Event-Driven Monitoring: The system uses Prometheus metrics collection with real-time alerting, enabling proactive issue detection rather than reactive troubleshooting.
Infrastructure as Code: All components are defined in Docker Compose with version-controlled configurations, ensuring reproducible deployments across environments.
Modular Design: Each component (API, monitoring, workflows) is independently deployable and scalable.
Base Model Selection: Chose cardiffnlp/twitter-roberta-base-sentiment-latest for its proven performance on social media text and robust pre-training on Twitter data.
Fine-tuning Strategy: Implemented PEFT (Parameter Efficient Fine-Tuning) with LoRA (Low-Rank Adaptation) for efficient model customization:
- Efficiency: Only ~0.1% of parameters are trainable
- Quality: Maintains base model performance while adapting to specific domains
- Resource Optimization: Reduces training time and computational requirements
Model Registry: Integrated HuggingFace Hub for model versioning and distribution, enabling easy model updates and rollbacks.
For hands-on testing and model evaluation, see MLOps_project_ProfAI.md
Design: Built with API-first approach to ensure the model is accessible and production-ready.
Endpoint Architecture:
- Prediction Endpoints: Single and batch sentiment analysis with confidence scores
- Evaluation Endpoints: Automated model assessment on multiple datasets
- Admin Endpoints: Health checks, metrics exposure, and system monitoring
- Monitoring Integration: Built-in Prometheus metrics collection
Performance Optimizations: Implemented request batching, model caching, and asynchronous processing to handle production loads efficiently.
For API testing and usage examples, see MLOps_project_ProfAI.md
Multi-Service Architecture: Designed with Docker Compose orchestrating four core services:
- Sentiment API: FastAPI application with model inference
- Prometheus: Time-series metrics collection and storage
- Grafana: Professional dashboards and visualization
- PostgreSQL: Metadata storage for workflow management
Scalability Considerations: Services are designed to scale horizontally with load balancing support and resource isolation.
Production Readiness: Includes health checks, graceful shutdowns, and persistent data volumes for production deployment.
For infrastructure setup and scaling, see MLOps_project_ProfAI.md
Three-Tier Pipeline Strategy:
- Continuous Integration: Automated testing, code quality checks, and Docker builds
- Continuous Deployment: Multi-platform deployment to HuggingFace Spaces and container registries
- Quality Assurance: Pylint code analysis and comprehensive test coverage
Testing Framework: Comprehensive test suite including:
- Unit Tests: Model functionality and data processing validation
- Integration Tests: End-to-end API testing and dataset integration
For CI/CD pipeline details and manual triggers, see MLOps_project_ProfAI.md
Automated MLOps Workflows: Implemented two critical DAGs for production operations:
Model Evaluation DAG: Scheduled hourly assessment of model performance across multiple datasets with automated metric recording and comparison reporting.
Data Drift Detection DAG: Statistical analysis using Kolmogorov-Smirnov tests to detect distribution changes in input data, with configurable alerting thresholds.
Production Monitoring: Integrated workflow results with Prometheus metrics for unified observability across the entire system.
For workflow configuration and monitoring, see MLOps_project_ProfAI.md
The system implements multi-layered metrics collection covering all aspects of the MLOps lifecycle:
Prediction Metrics:
sentiment_predictions_total: Counter tracking predictions by sentiment classificationsentiment_prediction_latency_seconds: Histogram of response times with percentile analysissentiment_text_length: Distribution of input text lengths for pattern analysissentiment_confidence: Model confidence score distributions for quality assessment
Model Performance Metrics:
model_accuracy: Accuracy scores by model, dataset, and evaluation splitmodel_f1,model_precision,model_recall: Comprehensive performance metrics with class-level granularitymodel_confusion_matrix: Detailed classification performance analysis
System Health Metrics:
- API response times, error rates, and throughput
- Container resource utilization and system health indicators
- Data drift detection scores and alert frequencies
Three Grafana Dashboards provide comprehensive system observability:
1. Sentiment Analysis Dashboard
- Real-time Prediction Monitoring: Live charts showing prediction volume and sentiment distribution
- Performance Tracking: Response time percentiles and throughput analysis
- Quality Metrics: Confidence score distributions and text length analysis
2. Model Performance Dashboard
- Latency Analysis: Detailed response time breakdowns
- Throughput Metrics: Request volume patterns and capacity utilization
- Error Tracking: Failed prediction analysis and system reliability metrics
3. Model Evaluation Metrics Dashboard
- Multi-Model Comparison: Side-by-side performance analysis of base vs fine-tuned models
- Dataset-Specific Performance: Evaluation results across TweetEval and Amazon Reviews datasets
- Class-Level Analysis: Precision, recall, and F1 scores for positive, negative, and neutral classifications
- Confusion Matrix Visualization: Detailed classification performance heatmaps
For dashboard access and configuration, see MLOps_project_ProfAI.md
For complete setup instructions, testing procedures, and hands-on exploration of all system features, please refer to our comprehensive guide:
The guide includes step-by-step instructions for:
- Local development setup and API testing
- Docker Compose deployment with full monitoring stack
- CI/CD pipeline configuration and deployment automation
- Advanced workflow orchestration and monitoring setup
Planned Enhancement: Integration with RapidAPI to create a more realistic production monitoring system that simulates real-world API usage patterns.
Implementation Strategy:
- Real-time Data Ingestion: Connect to Twitter/social media APIs via RapidAPI for live sentiment analysis
- Production Traffic Simulation: Generate realistic user behavior patterns and load testing scenarios
- Enhanced Monitoring: Track API usage metrics, rate limiting, and third-party service dependencies
Technical Implementation: The system is already designed with microservices architecture that can easily accommodate external API integrations through the existing FastAPI framework and Prometheus monitoring stack.