'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])
在网络查询求解多次未能找到解决方法,求众位多多指点一下

img

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

虚拟环境中的torchtext版本应用与使用的语句不匹配,将torchtext的版本应用为0.4.0,则上述原语句都可以正常使用,感谢大家的回答