|
1 | 1 | # Installation |
2 | 2 |
|
3 | | -Transformers is tested on Python 3.6+ and PyTorch 1.1.0 |
| 3 | +🤗 Transformers is tested on Python 3.6+, and PyTorch 1.1.0+ or TensorFlow 2.0+. |
4 | 4 |
|
5 | | -## With pip |
| 5 | +You should install 🤗 Transformers in a [virtual environment](https://docs.python.org/3/library/venv.html). If you're |
| 6 | +unfamiliar with Python virtual environments, check out the [user guide](https://packaging.python.org/guides/installing-using-pip-and-virtual-environments/). Create a virtual environment with the version of Python you're going |
| 7 | +to use and activate it. |
6 | 8 |
|
7 | | -PyTorch Transformers can be installed using pip as follows: |
| 9 | +Now, if you want to use 🤗 Transformers, you can install it with pip. If you'd like to play with the examples, you |
| 10 | +must install it from source. |
8 | 11 |
|
9 | | -``` bash |
| 12 | +## Installation with pip |
| 13 | + |
| 14 | +First you need to install one of, or both, TensorFlow 2.0 and PyTorch. |
| 15 | +Please refer to [TensorFlow installation page](https://www.tensorflow.org/install/pip#tensorflow-2.0-rc-is-available) |
| 16 | +and/or [PyTorch installation page](https://pytorch.org/get-started/locally/#start-locally) regarding the specific |
| 17 | +install command for your platform. |
| 18 | + |
| 19 | +When TensorFlow 2.0 and/or PyTorch has been installed, 🤗 Transformers can be installed using pip as follows: |
| 20 | + |
| 21 | +```bash |
10 | 22 | pip install transformers |
11 | 23 | ``` |
12 | 24 |
|
13 | | -## From source |
| 25 | +Alternatively, for CPU-support only, you can install 🤗 Transformers and PyTorch in one line with |
| 26 | + |
| 27 | +```bash |
| 28 | +pip install transformers[torch] |
| 29 | +``` |
| 30 | + |
| 31 | +or 🤗 Transformers and TensorFlow 2.0 in one line with |
| 32 | + |
| 33 | +```bash |
| 34 | +pip install transformers[tf-cpu] |
| 35 | +``` |
| 36 | + |
| 37 | +To check 🤗 Transformers is properly installed, run the following command: |
| 38 | + |
| 39 | +```bash |
| 40 | +python -c "from transformers import pipeline; print(pipeline('sentiment-analysis')('I hate you'))" |
| 41 | +``` |
| 42 | + |
| 43 | +It should download a pretrained model then print something like |
| 44 | + |
| 45 | +```bash |
| 46 | +[{'label': 'NEGATIVE', 'score': 0.9991129040718079}] |
| 47 | +``` |
| 48 | + |
| 49 | +(Note that TensorFlow will print additional stuff before that last statement.) |
| 50 | + |
| 51 | +## Installing from source |
14 | 52 |
|
15 | | -To install from source, clone the repository and install with: |
| 53 | +To install from source, clone the repository and install with the following commands: |
16 | 54 |
|
17 | 55 | ``` bash |
18 | 56 | git clone https://github.com/huggingface/transformers.git |
19 | 57 | cd transformers |
20 | | -pip install . |
| 58 | +pip install -e . |
| 59 | +``` |
| 60 | + |
| 61 | +Again, you can run |
| 62 | + |
| 63 | +```bash |
| 64 | +python -c "from transformers import pipeline; print(pipeline('sentiment-analysis')('I hate you'))" |
21 | 65 | ``` |
22 | 66 |
|
| 67 | +to check 🤗 Transformers is properly installed. |
| 68 | + |
23 | 69 | ## Caching models |
24 | 70 |
|
25 | 71 | This library provides pretrained models that will be downloaded and cached locally. Unless you specify a location with |
26 | | -`cache_dir=...` when you use the `from_pretrained` method, these models will automatically be downloaded in the |
27 | | -folder given by the shell environment variable ``TRANSFORMERS_CACHE``. The default value for it will be the PyTorch |
| 72 | +`cache_dir=...` when you use methods like `from_pretrained`, these models will automatically be downloaded in the |
| 73 | +folder given by the shell environment variable ``TRANSFORMERS_CACHE``. The default value for it will be the PyTorch |
28 | 74 | cache home followed by ``/transformers/`` (even if you don't have PyTorch installed). This is (by order of priority): |
29 | 75 |
|
30 | 76 | * shell environment variable ``ENV_TORCH_HOME`` |
31 | 77 | * shell environment variable ``ENV_XDG_CACHE_HOME`` + ``/torch/`` |
32 | 78 | * default: ``~/.cache/torch/`` |
33 | 79 |
|
34 | | -So if you don't have any specific environment variable set, the cache directory will be at |
| 80 | +So if you don't have any specific environment variable set, the cache directory will be at |
35 | 81 | ``~/.cache/torch/transformers/``. |
36 | 82 |
|
37 | | -**Note:** If you have set a shell enviromnent variable for one of the predecessors of this library |
38 | | -(``PYTORCH_TRANSFORMERS_CACHE`` or ``PYTORCH_PRETRAINED_BERT_CACHE``), those will be used if there is no shell |
| 83 | +**Note:** If you have set a shell enviromnent variable for one of the predecessors of this library |
| 84 | +(``PYTORCH_TRANSFORMERS_CACHE`` or ``PYTORCH_PRETRAINED_BERT_CACHE``), those will be used if there is no shell |
39 | 85 | enviromnent variable for ``TRANSFORMERS_CACHE``. |
40 | 86 |
|
41 | | -## Tests |
42 | | - |
43 | | -An extensive test suite is included to test the library behavior and several examples. Library tests can be found in the [tests folder](https://github.com/huggingface/transformers/tree/master/tests) and examples tests in the [examples folder](https://github.com/huggingface/transformers/tree/master/examples). |
44 | | - |
45 | | -Refer to the [contributing guide](https://github.com/huggingface/transformers/blob/master/CONTRIBUTING.md#tests) for details about running tests. |
46 | | - |
47 | | -## OpenAI GPT original tokenization workflow |
48 | | - |
49 | | -If you want to reproduce the original tokenization process of the `OpenAI GPT` paper, you will need to install `ftfy` and `SpaCy`: |
50 | | - |
51 | | -``` bash |
52 | | -pip install spacy ftfy==4.4.3 |
53 | | -python -m spacy download en |
54 | | -``` |
55 | | - |
56 | | -If you don't install `ftfy` and `SpaCy`, the `OpenAI GPT` tokenizer will default to tokenize using BERT's `BasicTokenizer` followed by Byte-Pair Encoding (which should be fine for most usage, don't worry). |
57 | | - |
58 | | -## Note on model downloads (Continuous Integration or large-scale deployments) |
| 87 | +### Note on model downloads (Continuous Integration or large-scale deployments) |
59 | 88 |
|
60 | | -If you expect to be downloading large volumes of models (more than 1,000) from our hosted bucket (for instance through your CI setup, or a large-scale production deployment), please cache the model files on your end. It will be way faster, and cheaper. Feel free to contact us privately if you need any help. |
| 89 | +If you expect to be downloading large volumes of models (more than 1,000) from our hosted bucket (for instance through |
| 90 | +your CI setup, or a large-scale production deployment), please cache the model files on your end. It will be way |
| 91 | +faster, and cheaper. Feel free to contact us privately if you need any help. |
61 | 92 |
|
62 | 93 | ## Do you want to run a Transformer model on a mobile device? |
63 | 94 |
|
64 | 95 | You should check out our [swift-coreml-transformers](https://github.com/huggingface/swift-coreml-transformers) repo. |
65 | 96 |
|
66 | | -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. |
| 97 | +It contains a set of tools to convert PyTorch or TensorFlow 2.0 trained Transformer models (currently contains `GPT-2`, |
| 98 | +`DistilGPT-2`, `BERT`, and `DistilBERT`) to CoreML models that run on iOS devices. |
67 | 99 |
|
68 | | -At some point in the future, you'll be able to seamlessly move from pre-training or fine-tuning models in PyTorch to productizing them in CoreML, |
69 | | -or prototype a model or an app in CoreML then research its hyperparameters or architecture from PyTorch. Super exciting! |
| 100 | +At some point in the future, you'll be able to seamlessly move from pre-training or fine-tuning models in PyTorch or |
| 101 | +TensorFlow 2.0 to productizing them in CoreML, or prototype a model or an app in CoreML then research its |
| 102 | +hyperparameters or architecture from PyTorch or TensorFlow 2.0. Super exciting! |
0 commit comments