| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
| Name | Name | Last commit date | ||
|---|---|---|---|---|
A complete end-to-end machine learning project for text summarization using the HuggingFace Pegasus model. This project demonstrates a production-ready ML pipeline with proper modular architecture, configuration management, , API deployment, and containerization.
This project provides a complete solution for summarizing conversational text. It fine-tunes Google's Pegasus model on the SAMSum dataset to generate concise summaries from dialogue. The entire system follows MLOps best practices, featuring a modular architectural design, comprehensive logging, a repeatable training pipeline, configuration management, and a deployed API for easy inference.
The pipeline processes conversational data and generates concise summaries, making it ideal for chat summarization, meeting notes, and dialogue analysis applications. This repository is designed to be both a functional application and a learning guide for building robust, production-level ML systems.
The project follows a modular, pipeline-based architecture that separates concerns, making it scalable, maintainable, and easy to debug.
Follow these steps to set up and run the project locally.
Before starting this project, ensure you have the following installed:
First, clone the repository and navigate to the project directory:
git clone https://github.com/GoJo-Rika/Text-Summarizer-Using-HuggingFace-Transformers.git
cd Text-Summarizer-Using-HuggingFace-TransformersWe recommend using uv, a fast, next-generation Python package manager.
Install uv on your system if you haven't already.
# On macOS and Linux
curl -LsSf https://astral.sh/uv/install.sh | sh
# On Windows
powershell -c "irm https://astral.sh/uv/install.ps1 | iex"Create a virtual environment and install dependencies with a single command:
uv syncThis command automatically creates a .venv folder and installs all required packages from requirements.txt.
Note: For a comprehensive guide on uv, check out this detailed tutorial: uv-tutorial-guide.
If you prefer to use the standard venv and pip:
Create and activate a virtual environment:
python -m venv venv
source venv/bin/activate # On Windows use: venv\Scripts\activateInstall the required dependencies:
pip install -r requirements.txt # Using uv: uv add -r requirements.txtCreate the necessary directory structure and empty files for the project using the following command:
python template.py # Using uv: uv run template.pyText-Summarizer/ ├── artifacts/ # Stores outputs: data, models, and metrics ├── config/ │ └── config.yaml # Static configuration (paths, model names) ├── logs/ # Application logs ├── research/ # Jupyter notebooks for experimentation ├── src/ │ └── text_summarizer/ │ ├── components/ # Core ML components logic for each pipeline stage │ │ ├── data_ingestion.py │ │ ├── data_transformation.py │ │ ├── model_trainer.py │ │ └── model_evaluation.py │ ├── config/ # Configuration manager logic │ │ └── configuration.py │ ├── entity/ # Custom data structures (dataclasses) and entities │ │ └── __init__.py │ ├── pipeline/ Orchestrates the ML workflow stages │ │ ├── stage_1_data_ingestion_pipeline.py │ │ ├── stage_2_data_transformation_pipeline.py │ │ ├── stage_3_model_trainer_pipeline.py │ │ ├── stage_4_model_evaluation_pipeline.py │ │ └── prediction_pipeline.py │ └── utils/ # Utility functions# Helper functions (e.g., reading YAML) │ └── common.py ├── app.py # FastAPI web application for prediction ├── main.py # Main script to run the training pipeline ├── params.yaml # Tunable hyperparameters for training ├── requirements.txt # Python dependencies └── Dockerfile # Docker containerization configuration for deployment
The project uses two separate YAML files for configuration, a common best practice.
Holds static configuration like file paths, artifact directories, and pre-trained model names. These rarely change.
data_ingestion:
source_URL: "https://github.com/GoJo-Rika/datasets/raw/refs/heads/main/summarizer-data.zip"
model_trainer:
model_ckpt: "google/pegasus-cnn_dailymail"Contains hyperparameters for model training (e.g., learning rate, batch size, epochs). This allows for easy tuning and experimentation without modifying the core application code.
TrainingArguments:
num_train_epochs: 1
per_device_train_batch_size: 1
gradient_accumulation_steps: 16To run the complete training pipeline from scratch, execute main.py:
python main.py # uv run main.pyThis command executes all four pipeline stages sequentially:
Note on Model Training: The model training stage in main.py is commented out by default to prevent accidental, resource-intensive retraining. To run a full training session, uncomment the relevant lines in main.py.
You can also run individual components for testing or debugging:
from src.text_summarizer.pipeline.stage_1_data_ingestion_pipeline import DataIngestionTrainingPipeline
# Run only data ingestion
pipeline = DataIngestionTrainingPipeline()
pipeline.initiate_data_ingestion()To start the web service for inference and serve the trained model via a REST API, run the app.py file::
python app.py # uv run app.pyThe server will start on http://localhost:8080 with automatic API documentation available at http://localhost:8080/docs.
Redirects to the interactive API documentation.
Triggers the complete training pipeline. Useful for retraining the model via an API call.
curl -X GET "http://localhost:8080/train"Generates a summary for the provided text.
curl -X POST "http://localhost:8080/predict?text=Your%20text%20to%20summarize%20here"Example:
curl -X POST "http://localhost:8080/predict?text=Alice%3A%20Hey%2C%20I%20can't%20make%20it%20to%20the%20meeting%20this%20afternoon.%20Bob%3A%20No%20problem!%20I'll%20send%20you%20the%20notes."The training pipeline consists of four distinct, reuseable stages:
Training Environment: The model training was performed on Google Colab's free tier using T4 GPU, achieving significant performance improvements over local CPU training. The complete training process took approximately 10 minutes per epoch, with the full pipeline validation taking around 40 minutes including model downloading and file transfers. The modular architecture proved particularly valuable during development, allowing individual pipeline stages to be tested locally before moving to GPU-accelerated training in the cloud environment.
Build and run the application in a Docker container:
# Build the Docker image
docker build -t text-summarizer .
# Run the container
docker run -p 8080:8080 text-summarizerFor production deployment, consider:
If you encounter out-of-memory errors:
If the model fails to load:
If the API server fails to start:
For device-specific issues:
To contribute to this project:
Note: This project is designed for educational and research purposes. For production use, consider additional security measures, monitoring, and scalability optimizations based on your specific requirements.
For questions or issues, please refer to the project's issue tracker or contact the maintainers.
| Back | FazBrowse Home | New Git URL |