Monday, 24 January 2022

huggingface transformers RuntimeError: No module named 'tensorflow.python.keras.engine.keras_tensor'

I am looking at this workbook which comes from huggingface course. I dont have internet access from my python environment but I could download files and save them in python environment. I copied all file from this folder and saved it in the folder bert-base-uncased/. I renamed some of the files to match what is in the above folder

I have below packages

tensorflow.__version__
'2.2.0'

keras.__version__
'2.4.3'

Then I installed transformers

!pip install datasets transformers[sentencepiece]
checkpoint = "bert-base-uncased/"
from transformers import TFAutoModelForSequenceClassification



Successfully installed datasets-1.17.0 dill-0.3.4 fsspec-2022.1.0 huggingface-hub-0.4.0 multiprocess-0.70.12.2 pyarrow-6.0.1 sacremoses-0.0.47 sentencepiece-0.1.96 tokenizers-0.10.3 transformers-4.15.0 xxhash-2.0.2

all the files are available

#files from https://huggingface.co/bert-base-uncased/tree/main
import os
cwd = os.getcwd()
print (cwd)
os.listdir('bert-base-uncased/')

['gitattributes',
 'vocab.txt',
 'tokenizer_config.json',
 'tokenizer.json',
 'README.md',
 '.dominokeep',
 'config.json',
 'tf_model.h5',
 'flax_model.msgpack',
 'rust_model.ot',
 'pytorch_model.bin']

But I still get the below error. I don't get this error when I run the same code using google colab

model = TFAutoModelForSequenceClassification.from_pretrained('bert-base-uncased/', num_labels=2)

print ("----------------")
print (type(model))
print ("----------------")

RuntimeError: Failed to import transformers.models.bert.modeling_tf_bert because of the following error (look up to see its traceback):
No module named 'tensorflow.python.keras.engine.keras_tensor'


from huggingface transformers RuntimeError: No module named 'tensorflow.python.keras.engine.keras_tensor'

No comments:

Post a Comment