【问题标题】:huggingface transformers RuntimeError: No module named 'tensorflow.python.keras.engine.keras_tensor'拥抱脸变压器运行时错误:没有名为“tensorflow.python.keras.engine.keras_tensor”的模块
【发布时间】:2022-01-23 05:30:53
【问题描述】:

我正在查看来自huggingface 课程的workbook。我的 python 环境无法访问互联网,但我可以下载文件并将它们保存在 python 环境中。我从这个folder 复制了所有文件并将其保存在文件夹bert-base-uncased/ 中。我重命名了一些文件以匹配上述文件夹中的内容

我有以下包

tensorflow.__version__
'2.2.0'

keras.__version__
'2.4.3'

然后我安装了变压器

!pip install datasets transformers[sentencepiece]
checkpoint = "bert-base-uncased/"
from transformers import TFAutoModelForSequenceClassification



Successfully installed datasets-1.17.0 dill-0.3.4 fsspec-2022.1.0 huggingface-hub-0.4.0 multiprocess-0.70.12.2 pyarrow-6.0.1 sacremoses-0.0.47 sentencepiece-0.1.96 tokenizers-0.10.3 transformers-4.15.0 xxhash-2.0.2

所有文件都可用

#files from https://huggingface.co/bert-base-uncased/tree/main
import os
cwd = os.getcwd()
print (cwd)
os.listdir('bert-base-uncased/')

['gitattributes',
 'vocab.txt',
 'tokenizer_config.json',
 'tokenizer.json',
 'README.md',
 '.dominokeep',
 'config.json',
 'tf_model.h5',
 'flax_model.msgpack',
 'rust_model.ot',
 'pytorch_model.bin']

但我仍然收到以下错误。当我使用 google colab 运行相同的代码时,我没有收到此错误

model = TFAutoModelForSequenceClassification.from_pretrained('bert-base-uncased/', num_labels=2)

print ("----------------")
print (type(model))
print ("----------------")

RuntimeError: Failed to import transformers.models.bert.modeling_tf_bert because of the following error (look up to see its traceback):
No module named 'tensorflow.python.keras.engine.keras_tensor'

【问题讨论】:

    标签: python huggingface-transformers transformer


    【解决方案1】:

    为了复制您的问题,我安装了 TensorFlow 2.2.0 版。
    然后我尝试导入有问题的模块:
    from tensorflow.python.keras.engine import keras_tensor

    产量importError

    意思是,TensorFlow 2.2.0 版没有转换器所需的模块 keras_tensor。

    然后我将 TensorFlow 更新到 2.7.0 版并尝试再次导入 keras_tensor 模块,一切正常。

    将 TensorFlow 更新到新版本应该可以解决您的问题。

    编辑
    挖掘一下 TensorFlow 的最低工作版本,我得到了 Transformers 的setup.py
    TensorFlow 的版本要求是 >= 2.3.0。

    【讨论】:

      猜你喜欢
      • 2022-06-28
      • 2021-09-15
      • 2020-06-17
      • 2021-12-12
      • 2021-02-25
      • 2021-08-16
      • 2021-02-16
      • 2021-11-24
      • 2020-07-22
      相关资源
      最近更新 更多