RuntimeError: Failed to import transformers.models.roberta.modeling_tf_roberta because of the following error (look up to see its traceback): No module named 'keras.engine'
Hi,I wrote very small code :from transformers import pipelinemodel_id = “cardiffnlp/twitter-roberta-base-sentiment-latest”sentiment_pipe = pipeline(“sentiment-analysis”, model=model_id)print(sentiment_pipe(‘We hope you dont hate it’))ERROR- RuntimeError: Failed to import transformers.models.roberta.modeling_tf_roberta because of the following error (look up to see its traceback):No module named ‘keras.engine’I tried to install tensorflow == 2.10 but its not present
2023-12-12T03:16:34Z
Issue here:File ~\AppData\Local\anaconda3\Lib\site-packages\transformers\modeling_tf_utils.py:6968 from keras import backend as K—> 69 from keras.engine import data_adapter70 from keras.engine.keras_tensor import KerasTensorModuleNotFoundError: No module named ‘keras.engine’Solutions:  change the line 69 and 70 to ‘from tensorflow.python.keras.engine import data_adapter’ and ‘from tensorflow.python.keras.engine.keras_tensor import KerasTensor’
2023-12-12T06:26:32Z
Thanks alot for the help
2024-03-29T00:04:48Z
https://discuss.huggingface.co/t/cant-find-keras-engine/77743/3https://discuss.huggingface.co/t/cant-find-keras-engine/77743/3Guys but the “facebook/roberta-hate-speech-dynabench-r4-target” is a Pytorch model, isn’t it?I get to make it work with pytorch specifying the framework like this:sentiment_pipe = pipeline("sentiment-analysis", 
                          model=toxicity_model_name, #toxicity_model,tokenizer=toxicity_tokenizer,
                          framework="pt",
                          device=device)But latter I get the same error from the evaluator. Any ideas?
2024-04-01T14:14:42Z
I think you have a problem importing the keras.engine module. Try installing tensorflow version 2.10 if you can’t find it. Also make sure that you have all the dependencies and environment configured correctly to work with the transformers library.
2024-04-05T04:03:43Z
Thanks, I solve it modifying an internal transformer library file that was importing de tensorflow/keras model in a different Way.Still I continue with the doubt because as you can see there is a parameter for the framework filled with pytorch and also All the Notebook what’s working with pytorch even the other Transformers models from hugging face are working also in pytorch so why is this One trying to import or using this module in tensorflow?