1

As the title is self-descriptive, I'm not able to import the BertTokenizer and TFBertModel classes from the transformers package through the following code:

from transformers import BertTokenizer, TFBertModel

tokenizer = BertTokenizer.from_pretrained(BERT_PATH)
model = TFBertModel.from_pretrained(BERT_PATH)
text = "Replace me by any text you'd like."
encoded_input = tokenizer(text, return_tensors='tf')
resp = model(encoded_input)
print(resp)

As a result, I'm getting the following error:

RuntimeError: Failed to import transformers.models.bert.modeling_tf_bert because of the following error (look up to see its traceback):
dlopen(/Users/tk/miniforge3/envs/QA-benchmark/lib/python3.10/site-packages/tensorflow-plugins/libmetal_plugin.dylib, 0x0006): symbol not found in flat namespace '_TF_GetInputPropertiesList'

Here is my software stack:

OS: macOS Ventura 13.3.1
Python: 3.10
TensorFlow: macOS-tensorflow 2.9.0
Transformers: 4.28.0
BERT model: uncased_L-12_H-768_A-12

p.s. I've already posted this issue on the GitHub repository of transformers.

talha06
  • 6,206
  • 21
  • 92
  • 147

1 Answers1

1
from transformers import BertTokenizer, TFBertModel, BertModel

model = BertModel.from_pretrained('bert-base-uncased')

tokenizer = BertTokenizer.from_pretrained(model)
model = TFBertModel.from_pretrained(model)
text = "Replace me by any text you'd like."
encoded_input = tokenizer(text, return_tensors='tf')
resp = model(encoded_input)
print(resp)

Try this! it works for me.

Chandan Gupta
  • 684
  • 4
  • 11
  • 1
    Many thanks for your comment - but, unfortunately still getting the same error. – talha06 Apr 20 '23 at 17:59
  • 1
    Thank you for contributing to the Stack Overflow community. This may be a correct answer, but it’d be really useful to provide additional explanation of your code so developers can understand your reasoning. This is especially useful for new developers who aren’t as familiar with the syntax or struggling to understand the concepts. **Would you kindly [edit] your answer to include additional details for the benefit of the community?** – Jeremy Caney Aug 14 '23 at 01:03