Installation
This guide provides instructions for installing the Transformers library. Make sure you have a compatible Python version (3.6+) before proceeding.
With pip
Transformers can be installed using pip as follows:
pip install transformers
With conda
Transformers can be installed using conda as follows:
conda install -c huggingface transformers
From source
To install Transformers from source, follow these steps:
git clone https://github.com/huggingface/transformers.git
cd transformers
pip install -e .
Additional dependencies
Depending on your use case, you might want to install additional dependencies:
- TensorFlow 2.0
- PyTorch
- Flax
You can install Transformers with these extra dependencies using:
pip install transformers[tf-cpu] # TensorFlow
pip install transformers[torch] # PyTorch
pip install transformers[flax] # Flax
Verifying the installation
To verify that Transformers is installed correctly, you can run the following Python code:
from transformers import pipeline
classifier = pipeline("sentiment-analysis")
result = classifier("I love Transformers!")
print(result)
If the installation was successful, you should see output similar to:
[{'label': 'POSITIVE', 'score': 0.9998}]