写个predict给我写不会了
pytorch吧
全部回复
仅看楼主
level 3
def predict(text, sent_attn_model, text_field, label_field, cuda_flag):
这里text_field和label_field都是用torchtext.data.Field创建的对象,但是在调用text_field的preprocess方法和vocab时报错了,但报的是module 'torch' has no attribute,而不是torchtext相关的报错。
text = [[text_field.vocab.stoi[x] for x in text]]
AttributeError: module 'torch' has no attribute 'vocab'
以及
text = text_field.preprocess(text)
AttributeError: module 'torch' has no attribute 'preprocess'
2023年04月05日 07点04分 1
level 3
查了一下源文件,Field.preprocess()是一个类方法,没有别的杂七杂八的问题,而Field.vocab是在Field.build_vocab()中创建的,但是我确实已经调用过build_vocab()了。
2023年04月05日 08点04分 2
level 3
2023年04月05日 08点04分 3
level 8
可以查询一下这个torchtext要求对应的torch版本。
2023年04月05日 08点04分 4
我之前有另一个模型也是用到了torchtext,而且能顺利跑通,唯独这个报错。
2023年04月05日 10点04分
level 11
field已经不赞成使用并且被移到legacy里面了[小乖]
2023年04月05日 08点04分 5
我的torchtext是专门安装的老版本,因为之前跑别的模型有用到,我这个predict就是仿写的那一个模型的,但是那个模型能跑,这个就报错。
2023年04月05日 10点04分
@◎御坂雷丘◎ 应该还是某些细节的地方有问题
2023年04月05日 11点04分
@sealed_ss 人麻了,把原型的predict复制过来再改改就直接没这个报错了,我真想给这torch一拳。
2023年04月05日 12点04分
2023年04月05日 12点04分
1