tensorflow 无法在macOS上导入transformers.models.bert.modeling_tf_bert?

vc9ivgsu  于 2023-04-21  发布在  Mac
关注(0)|答案(1)|浏览(364)

由于标题是自我描述的,我无法通过以下代码从transformers包导入BertTokenizerTFBertModel类:

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)

因此,我得到以下错误:

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'

下面是我的软件栈:

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.我已经在GitHub的transformers仓库上发布了这个问题。

x33g5p2x

x33g5p2x1#

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)

试试这个!它对我很有效。

相关问题