【发布时间】: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