描述:在调用transformers库中的与训练模型时,想使用tensorflow的模型但是会报ImportError,
,如:
model = TFBertForSequenceClassification.from_pretrained("bert-base-chinese")
model = AutoModelForMaskedLM.from_pretrained("bert-base-chinese", from_tf=True)
报错:TFBertForMaskedLM requires the TensorFlow library but it was not found in your environment. Checkout the instructions on the installation page: https://www.tensorflow.org/install and follow the ones the ones that match your environment.
尝试:参照ImportError: TFBertForSequenceClassification requires the TensorFlow library but it was not found_VirgilG72的博客-CSDN博客,尝试根据kaggle上的tensorflow和transformers版本进行匹配,如图,但是依旧报错。并且尝试更换transformer版本从4.5、4.8、4.30都无效。
解决:本人的tensorflow版本2.4.1,将transformers版本替换为3.4.0后问题解决,似乎3.4.0这个版本更稳定一些。