Home > other >  How to import Transformers with Tensorflow
How to import Transformers with Tensorflow

Time:12-26

After installing Transformers using

pip install Transformers

I get version 4.25.1 , but when I try to import Transformer by

from tensorflow.keras.layers import Transformer
# or
from tensorflow.keras.layers.experimental  import Transformer

I get this error:

ImportError: cannot import name 'Transformer' from 'tensorflow.keras.layers'

I am using Tenserflow 2.10 and python 3.7.

CodePudding user response:

Since you have installed Transformers directly you would have to directly import transformers, as in

import transformers 

CodePudding user response:

please try to update to TenserFlow 2.4.0 at least. Apparently your current version doesn't have the Transformer class

CodePudding user response:

The Transformer layer is a relatively new addition to TensorFlow and was introduced in TensorFlow 2.4.

To use the Transformer layer, you will need to upgrade to a newer version of TensorFlow. You can do this by running the following command:

pip install tensorflow --upgrade

Once you have installed the latest version of TensorFlow, you should be able to import the Transformer layer using the following import statement:

from tensorflow.keras.layers import Transformer

Hope this helps!

  • Related