YAML Metadata Warning:empty or missing yaml metadata in repo card
Check out the documentation for more information.
Summarization Pipeline Project
This project demonstrates how to use the Hugging Face Pipeline API to load a pre-trained summarization model and generate summaries from example text.
What Was Done
Model Selection: Used
facebook/bart-large-cnn, a pre-trained BART (Bidirectional and Auto-Regressive Transformers) model that was fine-tuned on the CNN/DailyMail dataset for abstractive summarization.Pipeline API: Leveraged Hugging Face's
pipelineAPI, which provides a simple interface for:- Loading pre-trained models
- Handling tokenization automatically
- Running inference with minimal code
Examples: Tested the model on multiple example texts covering different topics:
- Artificial intelligence and machine learning
- Climate change
- The Renaissance period
- A longer article-style text
Configuration: Used parameters to control summary length:
max_length: Maximum number of tokens in the summarymin_length: Minimum number of tokens in the summarydo_sample: Set to False for deterministic (greedy) decoding
Files
summarization_pipeline.py: Main script demonstrating the pipeline APIREADME.md: This file
Usage
Installation
pip install transformers torch
Running the Scripts
Option 1: Simple version (recommended, avoids dependency issues)
python simple_summarization.py
Option 2: Pipeline API version
python summarization_pipeline.py
Note: May have dependency issues in some environments. See SETUP_GUIDE.md
Option 3: Using Inference API
pip install requests
python summarization_api.py
Using in Your Own Code
from transformers import pipeline
# Load the summarization pipeline
summarizer = pipeline("summarization", model="facebook/bart-large-cnn")
# Summarize text
text = "Your long article or text here..."
summary = summarizer(text, max_length=100, min_length=30)
print(summary[0]['summary_text'])
Model Information
- Model: facebook/bart-large-cnn
- Task: Abstractive Summarization
- Training Data: CNN/DailyMail dataset
- Architecture: BART (Bidirectional and Auto-Regressive Transformers)
Alternative Models
You can easily switch to other pre-trained summarization models:
google/pegasus-xsum: Trained on XSum datasett5-small: General-purpose T5 modelsshleifer/distilbart-cnn-12-6: Smaller, faster version
Simply change the model parameter in the pipeline:
summarizer = pipeline("summarization", model="google/pegasus-xsum")
Notes
- The model requires significant memory (the large BART model is ~1.6GB)
- For GPU acceleration, change
device=-1todevice=0in the pipeline - The first run will download the model, which may take some time