我的环境是通过Pycharm创建的,包含以下软件包:tensorflow==1.13.0rc1,CUDA = 11 以及相应的cudn。但是运行 https://github.com/keras-team/keras-io/blob/master/examples/nlp/semantic_similarity_with_bert.py 文件的第1行到第269行,并执行print(f”Strategy: {strategy}”)和model.summary()后,报告了以下错误:
2021-08-29 00:16:22.311887: I tensorflow/core/platform/cpu_feature_guard.cc:141] 您的CPU支持的指令集与此TensorFlow二进制文件的编译不匹配:AVX2WARNING:tensorflow:在`tf.distribute.Strategy`中的所有设备并非TensorFlow可见。Traceback (most recent call last): File "D:/.../PycharmProjects/.../Semantic Similarity with BERT.py", line 190, in <module> bert_model = transformers.TFBertModel.from_pretrained("bert-base-uncased")AttributeError: module 'transformers' has no attribute 'TFBertModel'
回答:
Tensorflow 2.6.0 可以正常工作
pip install transformerspip install tensorflow from transformers import BertModel, TFBertModel