首页 > 解决方案 > 错误:即使将 tensorflow 导入为 tensorflow.compat.v1 后,模块“tensorflow”也没有属性“gfile”

问题描述

我已经阅读了这个问题的解决方案,其中 tensorflow 版本更改为 1.14 对人们有用。我想知道是否有任何其他解决方案而不进行版本更改。我正在使用 Jupyter 工作,并且正在运行使用 2.4.1 版的程序。我试图避免版本更改的其他原因是,一旦我将其更改为 1.14,还有其他功能(如句子和其他功能)会产生后续错误。

我正在尝试使用来自 github 的代码运行 BERT 模型。 https://github.com/google-research/bert

错误在 tokenization.py 函数中

~\bert\tokenization.py in load_vocab(vocab_file)
123   """Loads a vocabulary file into a dictionary."""
124   vocab = collections.OrderedDict()
125   index = 0
126   with tf.io.gfile.GFile(vocab_file, "r") as reader:

AttributeError:模块“tensorflow”没有属性“gfile”

任何建议都非常感谢!

更新:即使我不使用 tf.io.gfile.GFile 并尝试使用“with open(json_file, 'r') as reader:”,奇怪的是我得到了同样的错误。这很奇怪。

 \bert\modeling.py in from_json_file(cls, json_file)
 91   def from_json_file(cls, json_file):
 92     """Constructs a `BertConfig` from a json file of 
 parameters."""
 93     print(cls)
 94     print(json_file)
 95     with open(json_file, 'r') as reader:

AttributeError:模块“tensorflow”没有属性“gfile”。如果您看到我完全看不到的东西,请告诉我。

标签: pythontensorflownlptensorflow2.0bert-language-model

解决方案


推荐阅读