Downloads · 30 days
0
Dheerajsahi/hf-summarization-pipeline
hf-summarization-pipeline is a machine learning model from Dheerajsahi. Use it for the machine learning task on the model card, and read the license before you ship it in a product.
This project demonstrates how to use the Hugging Face Pipeline API to load a pre-trained summarization model and generate summaries from example text.
Downloads · 30 days
0
Access
Public
Updated Dec 22, 2025
Repo size
—
Likes
0
Public
Click a slice to open those files.
.py14.8 KB · 77%
From the Hugging Face model README
This project demonstrates how to use the Hugging Face Pipeline API to load a pre-trained summarization model and generate summaries from example text.
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 pipeline API, which provides a simple interface for:
Examples: Tested the model on multiple example texts covering different topics:
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) decodingsummarization_pipeline.py: Main script demonstrating the pipeline APIREADME.md: This filepip install transformers torch
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
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'])
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 versionSimply change the model parameter in the pipeline:
summarizer = pipeline("summarization", model="google/pegasus-xsum")
device=-1 to device=0 in the pipeline