How to Install Hugging Face Transformers (original) (raw)

Last Updated : 11 May, 2026

Hugging Face Transformers is a library used for building AI applications using pre-trained models, mainly for natural language processing. It supports easy integration and fine-tuning and is built on PyTorch and TensorFlow for efficient development.

Installation

1. Set Up Virtual Environment

python -m venv transformers-env

source transformers-env/bin/activate # For Linux / Mac

transformers-env\Scripts\activate # For Windows

2. Install PyTorch

To install PyTorch, visit the official PyTorch website and select the command based on your system, Python version and whether you want CPU or GPU support.

**For a typical CPU installation

pip install torch torchvision torchaudio

**For GPU (CUDA support – example for CUDA 12.1)

pip install torch torchvision torchaudio --index-url https://download.pytorch.org/whl/cu121

3. Installing Hugging Face Transformers

With your environment set up and either PyTorch or TensorFlow installed, you can now install the Hugging Face Transformers library.

pip install transformers

output

Installing Hugging face transformer

Verifying the Installation

To ensure that everything is installed correctly, you can run a simple test script. Create a Python script or open a Python interpreter and run

Python `

from transformers import pipeline

nlp = pipeline("sentiment-analysis")

result = nlp("I love using Hugging Face Transformers!") print(result)

`

**Output:

[{'label': 'POSITIVE', 'score': 0.9998}]

Applications

Limitations