Why Gensim doc2vec give AttributeError: 'list' object has no attribute 'words'?

China☆狼群 提交于 2019-12-09 09:34:14

问题


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)

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


回答1:


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)

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.



来源:https://stackoverflow.com/questions/36509957/why-gensim-doc2vec-give-attributeerror-list-object-has-no-attribute-words

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!