Eren-Yu 2022-11-05 10:52 采纳率: 0%
浏览 604
已结题

'Vocab' object has no attribute 'stoi'

TypeError: init() got an unexpected keyword argument 'min_freq'
刚开始运行报错如上,根据网络查询需要将Vocab改为vocab,于是:
return Vocab.Vocab(counter, min_freq=5)
改为:return Vocab.vocab(counter, min_freq=5)
将大小写改变后该错误确实消失,但出现了新的问题:
AttributeError: 'Vocab' object has no attribute 'stoi'
该错误对应的代码是:
features = torch.tensor([pad([vocab.stoi[word] for word in words]) for words in tokenized_data])
在网络查询求解多次未能找到解决方法,求众位多多指点一下

  • 写回答

3条回答 默认 最新

  • Jackyin0720 2022-11-05 12:15
    关注

    AttributeError: 'Vocab' object has no attribute 'stoi'
    AttributeError:“Vocab”对象没有属性“stoi”

    我觉得你应该看看这篇博文,【stod/stoi 函数基本用法及与atof函数的对比】这个报错很有可能是vocab.stoi[word]错了,参考链接:https://blog.csdn.net/qq_45949701/article/details/121310639

    评论

报告相同问题?

问题事件

  • 已结题 (查看结题原因) 11月8日
  • 修改了问题 11月5日
  • 创建了问题 11月5日