A comprehensive MLOps pipeline for news classification using transformer models, featuring model training, ONNX optimization, FastAPI deployment, and Airflow-based ETL processes.
├── airflow/
│ └── dags/ # Airflow DAG definitions
├── api/ # FastAPI application
├── data/ # AG News dataset
├── modeling/
│ ├── traditional/ # RNN and LSTM models
│ └── transformers/ # ELECTRA and DistilBERT implementations
├── electra_trainer/ # Trained ELECTRA model
├── electra_onnx/ # ONNX-optimized ELECTRA model
├── distilbert_trainer/ # Trained DistilBERT model
├── distilbert_onnx/ # ONNX-optimized DistilBERT model
├── docker-compose.yml # Docker services configuration
├── Dockerfile # API service container definition
├── onnx_maker.py # ONNX conversion utility
├── pyproject.toml # Poetry dependencies
└── README.md
- Model Training: Implementation of both traditional (RNN, LSTM) and transformer-based (ELECTRA, DistilBERT) models
- Model Tracking: Integration with MLflow and DagsHub for experiment tracking
- Model Optimization: ONNX runtime optimization for improved inference performance
- API Service: FastAPI-based REST API for model serving
- ETL Pipeline: Airflow-based pipeline for news scraping, processing, and classification
- Containerization: Docker-based deployment with proper service orchestration
- Python 3.11+
- Docker and Docker Compose
- Poetry for dependency management
- PostgreSQL (for Airflow metadata)
- Clone the repository:
git clone <repository-url>
cd mlops-nlp- Install dependencies using Poetry:
poetry install- Build and start the Docker services:
docker-compose up --buildThe project supports multiple model architectures:
- Traditional approaches (RNN, LSTM) in
modeling/traditional/ - Transformer models (ELECTRA, DistilBERT) in
modeling/transformers/ - Model optimization using ONNX Runtime via
onnx_maker.py
The API service (api/app.py) provides:
- Text classification endpoint at
/predict - Health check endpoint at
/health - ONNX Runtime inference for optimized performance
The ETL pipeline (airflow/dags/) performs:
- News scraping from BBC RSS feeds
- Text preprocessing and cleaning
- Model inference using the API service
- Storage in PostgreSQL database
Make predictions using the API:
curl -X POST "http://localhost:8000/predict" \
-H "Content-Type: application/json" \
-d '{"text": "Your news text here"}'Response format:
{
"label": "Category",
"confidence": 0.95
}The ETL pipeline includes the following tasks:
- News scraping from BBC RSS
- Text cleaning and preprocessing
- Model prediction via API
- Database storage
- CSV backup creation
Access the Airflow UI at http://localhost:8080 with default credentials:
- Username: airflow
- Password: airflow
- Export requirements from Poetry:
poetry export --without-hashes --dev -f requirements.txt > requirements.txt- Run the API locally:
poetry run python api/app.py- Run Airflow locally:
poetry run airflow standaloneRequired environment variables:
AIRFLOW_UID: Airflow user IDPOETRY_VERSION: Poetry version for Docker build_AIRFLOW_WWW_USER_USERNAME: Airflow web UI username_AIRFLOW_WWW_USER_PASSWORD: Airflow web UI password
- API logs are stored in the
loggingdirectory - Airflow logs are available in
airflow/logs - Model training metrics are tracked in MLflow/DagsHub

