Browse by type
<img src="https://raw.githubusercontent.com/huggingface/transformers/master/docs/source/imgs/transformers_logo_name.png" width="400"/>
<a href="https://circleci.com/gh/huggingface/transformers">
<img alt="Build" src="https://img.shields.io/circleci/build/github/huggingface/transformers/master">
</a>
<a href="https://github.com/huggingface/transformers/blob/master/LICENSE">
<img alt="GitHub" src="https://img.shields.io/github/license/huggingface/transformers.svg?color=blue">
</a>
<a href="https://huggingface.co/transformers/index.html">
<img alt="Documentation" src="https://img.shields.io/website/http/huggingface.co/transformers/index.html.svg?down_color=red&down_message=offline&up_message=online">
</a>
<a href="https://github.com/huggingface/transformers/releases">
<img alt="GitHub release" src="https://img.shields.io/github/release/huggingface/transformers.svg">
</a>
🤗 Transformers (formerly known as pytorch-transformers and pytorch-pretrained-bert) provides state-of-the-art general-purpose architectures (BERT, GPT-2, RoBERTa, XLM, DistilBert, XLNet, T5, CTRL...) for Natural Language Understanding (NLU) and Natural Language Generation (NLG) with over thousands of pretrained models in 100+ languages and deep interoperability between PyTorch & TensorFlow 2.0.
State-of-the-art NLP for everyone - Deep learning researchers - Hands-on practitioners - AI/ML/NLP teachers and educators
Lower compute costs, smaller carbon footprint - Researchers can share trained models instead of always retraining - Practitioners can reduce compute time and production costs - Dozens of architectures with over 1,000 pretrained models, some in more than 100 languages
Choose the right framework for every part of a model's lifetime - Train state-of-the-art models in 3 lines of code - Deep interoperability between TensorFlow 2.0 and PyTorch models - Move a single model between TF2.0/PyTorch frameworks at will - Seamlessly pick the right framework for training, evaluation, production
| Section | Description |
|---|---|
| Installation | How to install the package |
| Model architectures | Architectures (with pretrained weights) |
| Online demo | Experimenting with this repo’s text generation capabilities |
| Quick tour: Usage | Tokenizers & models usage: Bert and GPT-2 |
| Quick tour: TF 2.0 and PyTorch | Train a TF 2.0 model in 10 lines of code, load it in PyTorch |
| Quick tour: pipelines | Using Pipelines: Wrapper around tokenizer and models to use finetuned models |
| Quick tour: Fine-tuning/usage scripts | Using provided scripts: GLUE, SQuAD and Text generation |
| Quick tour: Share your models | Upload and share your fine-tuned models with the community |
| Migrating from pytorch-transformers to transformers | Migrating your code from pytorch-transformers to transformers |
| Migrating from pytorch-pretrained-bert to pytorch-transformers | Migrating your code from pytorch-pretrained-bert to transformers |
| Documentation | Full API documentation and more |
This repo is tested on Python 3.6+, PyTorch 1.0.0+ (PyTorch 1.3.1+ for examples) and TensorFlow 2.0.
You should install 🤗 Transformers in a virtual environment. If you're unfamiliar with Python virtual environments, check out the user guide.
Create a virtual environment with the version of Python you're going to use and activate it.
Now, if you want to use 🤗 Transformers, you can install it with pip. If you'd like to play with the examples, you must install it from source.
First you need to install one of, or both, TensorFlow 2.0 and PyTorch. Please refer to TensorFlow installation page and/or PyTorch installation page regarding the specific install command for your platform.
When TensorFlow 2.0 and/or PyTorch has been installed, 🤗 Transformers can be installed using pip as follows:
pip install transformers
Here also, you first need to install one of, or both, TensorFlow 2.0 and PyTorch. Please refer to TensorFlow installation page and/or PyTorch installation page regarding the specific install command for your platform.
When TensorFlow 2.0 and/or PyTorch has been installed, you can install from source by cloning the repository and running:
git clone https://github.com/huggingface/transformers
cd transformers
pip install .
When you update the repository, you should upgrade the transformers installation and its dependencies as follows:
git pull
pip install --upgrade .
Examples are included in the repository but are not shipped with the library.
Therefore, in order to run the latest versions of the examples, you need to install from source, as described above.
Look at the README for how to run examples.
A series of tests are included for the library and for some example scripts. Library tests can be found in the tests folder and examples tests in the examples folder.
Depending on which framework is installed (TensorFlow 2.0 and/or PyTorch), the irrelevant tests will be skipped. Ensure that both frameworks are installed if you want to execute all tests.
Here's the easiest way to run tests for the library:
pip install -e ".[testing]"
make test
and for the examples:
pip install -e ".[testing]"
pip install -r examples/requirements.txt
make test-examples
For details, refer to the contributing guide.
You should check out our swift-coreml-transformers repo.
It contains a set of tools to convert PyTorch or TensorFlow 2.0 trained Transformer models (currently contains GPT-2, DistilGPT-2, BERT, and DistilBERT) to CoreML models that run on iOS devices.
At some point in the future, you'll be able to seamlessly move from pre-training or fine-tuning models to productizing them in CoreML, or prototype a model or an app in CoreML then research its hyperparameters or architecture from TensorFlow 2.0 and/or PyTorch. Super exciting!
🤗 Transformers currently provides the following NLU/NLG architectures:
$ claude mcp add transformers \
-- python -m otcore.mcp_server <graph>