RuntimeError: Failed to import transformers.models.bert.modeling_tf_bert due to 'No module named keras.engine'

Hi everyone,

I’m working on a Named Entity Recognition (NER) model using BERT with CRF, but I’ve encountered an issue while importing the necessary modules. Specifically, I’m getting the following error:

vbnet

import numpy as np

import pandas as pd

import tensorflow as tf

import tensorflow_addons as tfa

from transformers import BertTokenizer, TFBertForTokenClassification

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

Here are the versions of the libraries I am using:

keras==2.13.1

tensorflow==2.13.0

transformers==4.26.0

tensorflow-addons==0.22.0

I’ve tried reinstalling the libraries and checking the compatibility, but the issue persists. Has anyone encountered a similar problem or could provide any guidance on how to resolve this?

Thank you in advance for your help!

can I know are you using the same code of NER as used in NLP specialisation?

this error could be probably because the keras version you are working might not be compatible with transformer model you are trying to import.