1

Currently I am using transformers(3.0.2) and python(3.7.3) which encountered the below error:

cannot import name 'TFBertForQuestionAnswering' from 'transformers'

from transformers import BertTokenizer, TFBertForQuestionAnswering

model = TFBertForQuestionAnswering.from_pretrained('bert-base-cased')
f = open(model_path, "wb")
pickle.dump(model, f)

How do resolve this issue?

Max Luwang
  • 69
  • 2
  • 10
  • 3
    Do you have TensorFlow installed? If not, try `pip install tensorflow`. If yes, try importing `TFBertForQuestionAnswering` in the interactive Python shell. It may give you a more detailed error message than you get when running your script. – CrazyChucky Jul 15 '20 at 05:24

2 Answers2

1

Upgrade your TensorFlow library. It works fine with 2.3.1. version.

Filip Ibl
  • 557
  • 5
  • 8
0

Some TensorFlow components are only available when you have TensorFlow2 installed. Make sure you have the required version for the environment you are working on!

apex77
  • 1
  • 1
  • 1
    To make your answer more useful, add a code snippet or explain how to how the original poster may check the version. Perhaps you could edit your answer and expand how to install the most recent packages. Welcome to S/O! – DannyDannyDanny Apr 20 '21 at 11:28