我一直在试着玩预先训练好的模特儿。在协作模板中,所有内容都处于默认状态,使用torch.hub.load()
从huggingface/pytorch-transformers
到bert-base-uncased
作为“模型”
代码示例
import torch
model = torch.hub.load('huggingface/pytorch-transformers', 'model', 'bert-base-uncased') # Download model and configuration from S3 and cache.
我遇到了这个错误
Using cache found in /root/.cache/torch/hub/huggingface_pytorch-transformers_master
---------------------------------------------------------------------------
ValueError Traceback (most recent call last)
<ipython-input-19-ad22a1a34951> in <module>()
1 import torch
----> 2 model = torch.hub.load('huggingface/pytorch-transformers', 'model', 'somethingelse') # Download model and configuration from S3 and cache.
3 model = torch.hub.load('huggingface/pytorch-transformers', 'model', './test/bert_model/') # E.g. model was saved using `save_pretrained('./test/saved_model/')`
4 model = torch.hub.load('huggingface/pytorch-transformers', 'model', 'bert-base-uncased', output_attentions=True) # Update configuration during loading
5 assert model.config.output_attentions == True
13 frames
/usr/local/lib/python3.6/dist-packages/tensorflow/python/keras/utils/generic_utils.py in decorator(arg)
177 raise ValueError(
178 '%s has already been registered to %s' %
--> 179 (registered_name, _GLOBAL_CUSTOM_OBJECTS[registered_name]))
180
181 if arg in _GLOBAL_CUSTOM_NAMES:
ValueError: Custom>TFBertMainLayer has already been registered to <class 'src.transformers.modeling_tf_bert.TFBertMainLayer'>
我真的不明白发生了什么
如果您只想使用PyTorch版本的transformer,为了解决这个问题,您可以从您的环境中卸载TensorFlow,或者在transformer的源代码中注释掉init.py中的TensorFlow部分:)
相关问题 更多 >
编程相关推荐