【Pytorch】解决Fan in and fan out can not be computed for tensor with fewer than 2 dimensions

Dear 丶 2022-10-23 00:49 162阅读 0赞

问题

使用TEXT.build_vocab时报错Fan in and fan out can not be computed for tensor with fewer than 2 dimensions

vectors.unk_init = init.xavier_uniform_ # 没有命中的token的初始化方式
TEXT.build_vocab(train, min_freq=5, vectors=vectors)

原因是torchtext版本太高,不支持一维的词向量,仅仅支持二维以上的

解决

(1)方法一
是torchtext的版本问题,更换torchtext版本为0.2.3 问题解决

pip install torchtext==0.2.3

(2)方法二
在torchtext的vocab.py中的Vectors类里修改一行源码

发表评论

表情:
评论列表 (有 0 条评论,162人围观)

还没有评论,来说两句吧...

相关阅读