-
Notifications
You must be signed in to change notification settings - Fork 4
Home
Installation Install 🤗 Transformers for whichever deep learning library you’re working with, setup your cache, and optionally configure 🤗 Transformers to run offline.
🤗 Transformers is tested on Python 3.6+, PyTorch 1.1.0+, TensorFlow 2.0+, and Flax. Follow the installation instructions below for the deep learning library you are using:
- PyTorch installation instructions.
- TensorFlow 2.0 installation instructions.
- Flax installation instructions.
Install with pip You should install 🤗 Transformers in a virtual environment. If you’re unfamiliar with Python virtual environments, take a look at this guide. A virtual environment makes it easier to manage different projects, and avoid compatibility issues between dependencies.
Start by creating a virtual environment in your project directory:
python -m venv .env
Activate the virtual environment. On Linux and MacOs:
source .env/bin/activate
Activate Virtual environment on Windows
.env/Scripts/activate
Now you’re ready to install 🤗 Transformers with the following command:
pip install transformers
For CPU-support only, you can conveniently install 🤗 Transformers and a deep learning library in one line. For example, install 🤗
Transformers and PyTorch with:
pip install transformers[torch]
🤗 Transformers and TensorFlow 2.0:
pip install transformers[tf-cpu]
🤗 Transformers and Flax:
pip install transformers[flax]
Finally, check if 🤗 Transformers has been properly installed by running the following command. It will download a pre-trained model:
python -c "from transformers import pipeline; print(pipeline('sentiment-analysis')('we love you'))"
Then print out the label and score:
Copied [{'label': 'POSITIVE', 'score': 0.9998704791069031}]