Skip to content

HFTutorial is a Python project demonstrating text summarization using Hugging Face Transformers with the facebook/bart-large-cnn model.

License

Notifications You must be signed in to change notification settings

Someshdiwan/HFTutorial

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

HFTutorialA

A Python project demonstrating text summarization using Hugging Face Transformers and LangChain. This project leverages the facebook/bart-large-cnn model for summarization, with support for Apple Silicon (MPS) acceleration on macOS.


📑 Table of Contents


🚀 Overview

This project demonstrates how to:

  • Set up a Python environment
  • Install dependencies
  • Run a transformer-based summarization model (facebook/bart-large-cnn)

It supports Apple Silicon (M1/M2) acceleration via MPS (Metal Performance Shaders) with CPU fallback.


📋 Prerequisites

  • Python: 3.11 or 3.12 (⚠️ Python 3.13 may have compatibility issues)
  • Git: For cloning and managing the repository
  • PyCharm (optional): Recommended IDE
  • macOS: Instructions tailored for Apple Silicon (M1/M2)

⚙️ Setup Instructions

1. Create a Virtual Environment

# Create virtual environment with Python 3.11
python3.11 -m venv .venv

# Activate the environment
source .venv/bin/activate

# If Python 3.11 is not installed
brew install python@3.11

2. Install Requirements

# Install dependencies from requirements file
pip install -r Requirements.txt

Requirements.txt includes:

torch>=2.0.0
transformers>=4.45.2
huggingface_hub>=0.34.4

If outdated, install manually:

pip install torch transformers huggingface_hub

For Apple Silicon:

pip install torch torchvision torchaudio

3. Configure MPS (Apple Silicon) or CPU

PyTorch on M1/M2 automatically uses MPS if available, falling back to CPU. No CUDA is required on macOS.

Check PyTorch installation:

python -c "import torch; print(torch.__version__)"

4. Check MPS Availability

import torch
print(f"MPS Available: {torch.backends.mps.is_available()}")
print(f"Device: {'mps' if torch.backends.mps.is_available() else 'cpu'}")

✅ Expected output on M1/M2:

MPS Available: True
Device: mps

5. Run the Summarization Model

python Main.py

📝 Example Output

Input text (sample article):

The quick brown fox jumps over the lazy dog. The fox was fast and agile...

Output (summarized):

A fox quickly jumps over a lazy dog, showing agility and speed.

📂 Files in This Repository

  • Main.py – Summarization script using facebook/bart-large-cnn
  • Requirements.txt – Project dependencies
  • .gitignore – Ignores .venv/, .DS_Store, .idea/, etc.
  • HFT.txt – Optional project notes (can be removed)
  • README.md – Documentation

🛠 Troubleshooting

  • MPS not available? → Update PyTorch and macOS, or fallback to CPU.
  • Python version issues? → Use Python 3.11.
  • Dependencies conflict? → Recreate virtual environment and reinstall.

🤝 Contributing

Contributions are welcome! Fork this repo, make your changes, and open a pull request.


MIT License

Copyright (c) 2025 Somesh diwan

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.


About

HFTutorial is a Python project demonstrating text summarization using Hugging Face Transformers with the facebook/bart-large-cnn model.

Topics

Resources

License

Stars

Watchers

Forks

Languages