Hugging Face Transformers

Tools & Infrastructure 💻 Python ⚖️ Apache-2.0 🟢 Actively maintained
164.8k stars

Transformers is a model-definition framework for state-of-the-art machine learning with text, vision, audio, video, and multimodal models, supporting both inference and training. It provides a unified API to use thousands of pretrained models from the Hugging Face Hub, simplifying integration across frameworks. It is for developers and researchers who need easy access to cutting-edge models.

Getting Started With Hugging Face in 15 Minutes | Transformers, Pipeline, Tokenizer, Models

🎬 Getting Started With Hugging Face in 15 Minutes | Transformers, Pipeline, Tokenizer, Models · AssemblyAI

✨ Key features

  • Unified API for inference and training across modalities.
  • Access to 1M+ pretrained model checkpoints on the Hub.
  • Supports PyTorch, JAX, and TF2.0 frameworks.
  • High-level Pipeline API for quick inference.
  • Model definitions compatible with many training and inference tools.
  • Easy customization and model sharing.

🎯 Use cases

  • Text generation, summarization, translation, and classification.
  • Image classification, object detection, and segmentation.
  • Automatic speech recognition and text-to-speech.
  • Visual question answering and multimodal chat.
  • Rapid prototyping with state-of-the-art models.

📦 Installation

🧰 Requirements: Python 3.10+ and PyTorch 2.5+ are required.

Create and activate a virtual environment (venv or uv)
python -m venv .my-env
source .my-env/bin/activate
or with uv
uv venv .my-env
source .my-env/bin/activate
Install Transformers with PyTorch
pip install "transformers[torch]"
or with uv
uv pip install "transformers[torch]"

For the latest source version:

git clone https://github.com/huggingface/transformers.git
cd transformers
pip install '.[torch]'
or with uv
uv pip install '.[torch]'

🚀 Usage

from transformers import pipeline

# Text generation
pipe = pipeline(task="text-generation", model="Qwen/Qwen2.5-1.5B")
pipe("the secret to baking a really good cake is ")

# Chat with a model
chat = [
    {"role": "system", "content": "You are a sassy, wise-cracking robot as imagined by Hollywood circa 1986."},
    {"role": "user", "content": "Hey, can you tell me any fun things to do in New York?"}
]
pipe = pipeline(task="text-generation", model="meta-llama/Meta-Llama-3-8B-Instruct", dtype=torch.bfloat16, device_map="auto")
response = pipe(chat, max_new_tokens=512)
print(response[0]["generated_text"][-1]["content"])

⚠️ Good to know

The library is not a modular toolbox of building blocks; model code is not refactored with extra abstractions, and example scripts may require adaptation for specific use cases.

❓ FAQ

What Python and PyTorch versions are required?

Transformers works with Python 3.10+ and PyTorch 2.5+.

How can I install Transformers?

You can install via pip or uv with pip install "transformers[torch]" or uv pip install "transformers[torch]" after creating a virtual environment.

What is the Pipeline API?

The Pipeline is a high-level inference class that supports text, audio, vision, and multimodal tasks, handling preprocessing and returning outputs.

Can I use models with different frameworks?

Yes, Transformers supports PyTorch, JAX, and TF2.0, and you can move a single model between these frameworks.

📊 Repository

Stars★ 164,809
Forks🍴 34,444
Open issues🐛 2,380
Last commit🕒 Sep 4, 2026
Created📅 Oct 2018
Language💻 Python
License⚖️ Apache-2.0

🤖 Overview, features, install steps and FAQ were generated from the project's README on Sep 4, 2026. Always check the original source before running commands.