belkarx
belkarx

Reputation: 252

No module named 'keras.saving.hdf5_format'

After pip3 installing tensorflow and the transformers library, I'm receiving the titular error when I try loading this

from transformers import pipeline
classifier = pipeline("text-classification",model='bhadresh-savani/distilbert-base-uncased-emotion')

The error traceback looks like:

RuntimeError: Failed to import transformers.models.distilbert.modeling_tf_distilbert because of the following error (look up to see its traceback):
No module named 'keras.saving.hdf5_format'

I have ensured keras got installed with transformers, so I'm not sure why it isn't working

Upvotes: 10

Views: 14497

Answers (2)

Mata Pata
Mata Pata

Reputation: 31

I confirm that:

pip install -U tensorflow==2.10 

fixes it and now e.g. this runs:

pytest -s
============================================================================ test session starts ============================================================================
platform linux -- Python 3.10.4, pytest-7.2.1, pluggy-1.0.0
rootdir: /home/codespace/Downloads
plugins: anyio-3.6.2, typeguard-2.13.3
collected 0 items                                                                                                                                                           

Upvotes: 3

Mohammad Ahmed
Mohammad Ahmed

Reputation: 1634

If you are using the latest version of TensorFlow and Keras then you have to try this code and you have got this error as shown below

RuntimeError: Failed to import transformers.models.distilbert.modeling_tf_distilbert because of the following error (look up to see its traceback):
No module named 'keras.saving.hdf5_format'

Now, expand this error traces as I have shown below

Click on the 14 frames

Now click on the 14 frames and select as shown below Click on modeling_tf_utils.py Now comment this line as shown in the picture below Comment this from keras.saving.hdf5_format import save_attributes_to_hdf5_group

Now, try this and your error will gone.

The problem is that this is in the older version of keras and you are using the latest version of keras. So, you can skip all these steps and go back to the older version and it will work eventually.

Upvotes: 13

Related Questions