Search code examples
pythontensorflowkeras

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


Solution

  • 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.