【问题标题】:cannot import name 'TFBertForQuestionAnswering' from 'transformers'无法从“变压器”导入名称“TFBertForQuestionAnswering”
【发布时间】:2020-11-04 12:58:23
【问题描述】:

目前我正在使用变压器(3.0.2)和python(3.7.3),遇到以下错误:

无法从“变压器”导入名称“TFBertForQuestionAnswering”

from transformers import BertTokenizer, TFBertForQuestionAnswering

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

如何解决这个问题?

【问题讨论】:

  • 你安装了 TensorFlow 吗?如果没有,请尝试pip install tensorflow。如果是,请尝试在交互式 Python shell 中导入 TFBertForQuestionAnswering。它可能会为您提供比运行脚本时更详细的错误消息。

标签: python pip huggingface-transformers question-answering


【解决方案1】:

升级您的 TensorFlow 库。它适用于 2.3.1。版本。

【讨论】:

    【解决方案2】:

    某些 TensorFlow 组件仅在您安装了 TensorFlow2 后才可用。确保您拥有您正在使用的环境所需的版本!

    【讨论】:

    • 为了让您的答案更有用,请添加代码 sn-p 或说明原始发布者如何检查版本。也许您可以编辑您的答案并扩展如何安装最新的软件包。欢迎来到 S/O!
    猜你喜欢
    • 2021-01-14
    • 2020-11-18
    • 2022-06-24
    • 2021-06-09
    • 2021-06-13
    • 2021-06-28
    • 2020-09-06
    • 2021-12-07
    • 1970-01-01
    相关资源
    最近更新 更多