【问题标题】:AttributeError: module 'torch' has no attribute '_six'. Bert model in PytorchAttributeError:模块“火炬”没有属性“_six”。 Pytorch 中的 Bert 模型
【发布时间】:2019-05-21 15:41:21
【问题描述】:

我尝试在 pytorch 中使用 BertModel 类加载预训练模型。

我在torch下有_six.py,但它仍然显示模块'torch'没有属性'_six'

import torch
from pytorch_pretrained_bert import BertTokenizer, BertModel, BertForMaskedLM
# Load pre-trained model (weights)
model = BertModel.from_pretrained('bert-base-uncased')
model.eval()
~/anaconda3/lib/python3.7/site-packages/torch/nn/modules/module.py in __setattr__(self, name, value)
    551                                     .format(torch.typename(value), name))
    552                 modules[name] = value
--> 553             else:
    554                 buffers = self.__dict__.get('_buffers')
    555                 if buffers is not None and name in buffers:

~/anaconda3/lib/python3.7/site-packages/torch/nn/modules/module.py in register_parameter(self, name, param)
    140             raise KeyError("parameter name can't be empty string \"\"")
    141         elif hasattr(self, name) and name not in self._parameters:
--> 142             raise KeyError("attribute '{}' already exists".format(name))
    143 
    144         if param is None:

AttributeError: module 'torch' has no attribute '_six'

【问题讨论】:

    标签: python deep-learning nlp pytorch bert-language-model


    【解决方案1】:

    在 jupyter notebook 中,只需重新启动内核就可以正常工作

    【讨论】:

      【解决方案2】:

      我在 macOS 上也遇到了同样的问题,正如 Mark 所说,重新启动我的 mac 后它工作正常!

      【讨论】:

        猜你喜欢
        • 2018-10-10
        • 2018-04-29
        • 2023-04-04
        • 2021-05-13
        • 2021-12-23
        • 2018-11-19
        • 2021-11-14
        • 2020-02-09
        相关资源
        最近更新 更多