为什么Gensim doc2vec给出AttributeError:'list'对象没有属性'words'? [英] Why Gensim doc2vec give AttributeError: 'list' object has no attribute 'words'?

查看:344
本文介绍了为什么Gensim doc2vec给出AttributeError:'list'对象没有属性'words'?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试通过使用以下代码来尝试gensim doc2vec.据我从教程了解,它应该可以工作.但是,它给出了 AttributeError:'list'对象没有属性'words'.

I am trying to experiment gensim doc2vec, by using following code. As far as I understand from tutorials, it should work. However it gives AttributeError: 'list' object has no attribute 'words'.

from gensim.models.doc2vec import LabeledSentence, Doc2Vec
document = LabeledSentence(words=['some', 'words', 'here'], tags=['SENT_1']) 
model = Doc2Vec(document, size = 100, window = 300, min_count = 10, workers=4)

那我做错了什么?请帮忙.谢谢你.我正在使用python 3.5和gensim 0.12.4

So what did I do wrong? Any help please. Thank you. I am using python 3.5 and gensim 0.12.4

推荐答案

gensim.models.doc2vec的输入应该是LabeledSentence上的 iterator (例如列表对象).试试:

Input to gensim.models.doc2vec should be an iterator over the LabeledSentence (say a list object). Try:

model = Doc2Vec([document], size = 100, window = 1, min_count = 1, workers=1)

我减小了windowmin_count的大小,以便它们对于给定的输入有意义.如果还没有的话,还可以通过 Doc2Vec 上的这篇不错的教程来学习.

I have reduced the window size, and min_count so that they make sense for the given input. Also go through this nice tutorial on Doc2Vec, if you haven't already.

这篇关于为什么Gensim doc2vec给出AttributeError:'list'对象没有属性'words'?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆