首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >AttributeError:模块'torch‘没有属性'_six’。Pytorch中的Bert模型

AttributeError:模块'torch‘没有属性'_six’。Pytorch中的Bert模型
EN

Stack Overflow用户
提问于 2019-05-21 23:41:21
回答 2查看 7K关注 0票数 9

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

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

代码语言:javascript
运行
复制
import torch
from pytorch_pretrained_bert import BertTokenizer, BertModel, BertForMaskedLM
# Load pre-trained model (weights)
model = BertModel.from_pretrained('bert-base-uncased')
model.eval()
代码语言:javascript
运行
复制
~/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'
EN

回答 2

Stack Overflow用户

发布于 2019-08-29 17:34:47

在jupyter笔记本中,只需重新启动内核就可以正常工作。

票数 9
EN

Stack Overflow用户

发布于 2019-06-06 12:57:02

我在macOS上也遇到了同样的问题,正如马克提到的,在重启我的mac之后,它工作得很好!

票数 3
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/56241856

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档