【发布时间】:2016-07-07 12:41:04
【问题描述】:
我使用MySentences 类从目录中的所有文件中提取句子,并使用这些句子来训练 word2vec 模型。
我的数据集未标记。
class MySentences(object):
def __init__(self, dirname):
self.dirname = dirname
def __iter__(self):
for fname in os.listdir(self.dirname):
for line in open(os.path.join(self.dirname, fname)):
yield line.split()
sentences = MySentences('sentences')
model = gensim.models.Word2Vec(sentences)
现在我想用那个类来制作一个 doc2vec 模型。我阅读了Doc2Vec 参考页。 Doc2Vec()函数获取句子作为参数,但它不接受上述句子变量并返回错误:
AttributeError: 'list' object has no attribute 'words'
有什么问题?该参数的正确类型是什么?
更新:
我认为,未标记的数据是问题所在。看来 doc2vec 需要标记数据。
【问题讨论】:
-
以上代码运行为我找到! python 2.7 和 gensim 0.12
-
你是对的。我想用那个类来制作一个 doc2vec 模型。
标签: python text-mining gensim word2vec doc2vec