Installation

tf-ransformers is tested on Python 3.8+, and TensorFlow 2.7.1+.

You should install tf-ransformers 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 tf-transformers, you can install it with pip. If you’d like to play with the examples, you must install it from source.

Installation with pip

First you need to install TensorFlow 2.0 . Some in-place conversions require PyTorch, which depends on the model. Please refer to TensorFlow installation page, PyTorch installation page and/or regarding the specific install command for your platform.

When TensorFlow 2.7.1 (CPU or GPU) has been installed, tf-ransformers can be installed using pip as follows:

pip install tf-transformers

Editable install

If you want to constantly use the bleeding edge master version of the source code, or if you want to contribute to the library and need to test the changes in the code you’re making, you will need an editable install. This is done by cloning the repository and installing with the following commands:

First you need to install poetry

curl -sSL https://raw.githubusercontent.com/python-poetry/poetry/master/get-poetry.py | python -
git clone https://github.com/legacyai/tf-transformers.git
cd tf-transformers
poetry install

Caching models

This library provides pretrained models that will be downloaded and cached locally. Unless you specify a location with cache_dir=... when you use methods like from_pretrained, these models will automatically be downloaded in the tf_transformers_cache.

  • default: /tmp/tf_transformers_cache/ . /tmp in Ubuntu, might depends on the temp_dir in the machine.

Do you want to run a tf-ransformer model on a mobile device?

All models in tf-transformers completely support TFlite capbaility. Please checkout the tutorials for in-depth details.