doc2vec 利用gensim 生成文档向量

利用gensim 直接生成文档向量

    
    def gen_d2v_corpus(self, lines):

        with open("./data/ques2_result.txt", "wb") as fw:
            for line in lines:
                fw.write(" ".join(jieba.lcut(line)) + "\n")

        sents = doc2vec.TaggedLineDocument("./data/ques2_result.txt")
        model = doc2vec.Doc2Vec(sents, size = 50, window = 5, alpha = 0.015)
        model.train(sents)

        corpus = model.docvecs
        np.save("./output/d2v.corpus.npy", corpus)

        return np.asarray(corpus)

 

posted on 2016-05-30 22:17  星空守望者--jkmiao  阅读(5321)  评论(2编辑  收藏  举报