当前位置: 首页>>代码示例>>Python>>正文


Python Doc2Vec.load_word2vec_format方法代码示例

本文整理汇总了Python中gensim.models.Doc2Vec.load_word2vec_format方法的典型用法代码示例。如果您正苦于以下问题:Python Doc2Vec.load_word2vec_format方法的具体用法?Python Doc2Vec.load_word2vec_format怎么用?Python Doc2Vec.load_word2vec_format使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在gensim.models.Doc2Vec的用法示例。


在下文中一共展示了Doc2Vec.load_word2vec_format方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: load_from_w2v

# 需要导入模块: from gensim.models import Doc2Vec [as 别名]
# 或者: from gensim.models.Doc2Vec import load_word2vec_format [as 别名]
 def load_from_w2v(self, filename):
     """
     This loads a pretrained Word2Vec file into this Doc2Vec class.
     """
     model_w2v = Doc2Vec.load_word2vec_format(filename, binary=False)
     self._vocab_from = Word2Vec._vocab_from
     self._prepare_sentences = model_w2v._prepare_sentences
     for attr in dir(model_w2v):
         if attr == '__dict__':
             continue
         if attr in dir(self) and callable(getattr(model_w2v, attr)):
             continue
         try:
             setattr(self, attr, getattr(model_w2v, attr))
         except AttributeError:
             continue
开发者ID:Chaojiayuan,项目名称:Document2Vec,代码行数:18,代码来源:document2vec.py

示例2: Word2Vec

# 需要导入模块: from gensim.models import Doc2Vec [as 别名]
# 或者: from gensim.models.Doc2Vec import load_word2vec_format [as 别名]
    :return:
    """
    model = Word2Vec(sentences=document,min_count=1)
    return model


full_corpus = []

for i in negids:
    full_corpus.extend(movie_reviews.sents(i))

for i in posids:
    full_corpus.extend((movie_reviews.sents(i)))

print len(full_corpus)

print full_corpus[0]

print full_corpus[1]

print full_corpus[0][0]

model = word2vec(full_corpus,size=50)
print model['bad']
print model['good']
pickle.dump(model,open('full_corpus_w2v.p','wb'))

model.save_word2vec_format('full_corpus.vec')
model2 = Doc2Vec.load_word2vec_format('full_corpus.vec')
model3['i love this so much']
开发者ID:sjayakum,项目名称:sentiment-analysis,代码行数:32,代码来源:BuildWord2Vec.py

示例3: Word2Vec

# 需要导入模块: from gensim.models import Doc2Vec [as 别名]
# 或者: from gensim.models.Doc2Vec import load_word2vec_format [as 别名]
    :param document: It is a list of tokenized sentences
                    Example : [ ['first', 'sentence'],['second','sentence']]
    :return:
    """
    model = Word2Vec(sentences=document,min_count=1)
    return model


full_corpus = []

for i in negids:
    full_corpus.extend(movie_reviews.sents(i))

for i in posids:
    full_corpus.extend((movie_reviews.sents(i)))

print len(full_corpus)

print full_corpus[0]

print full_corpus[1]

print full_corpus[0][0]

model = word2vec(full_corpus)
print model['bad']
print model['good']
#pickle.dump(model,open('full_corpus_w2v.p','wb'))
model2 = Doc2Vec.load_word2vec_format('full_corpus_w2v.p')
model2['i love this so much']
开发者ID:sjayakum,项目名称:sentiment-analysis,代码行数:32,代码来源:BuildSent2Vec.py


注:本文中的gensim.models.Doc2Vec.load_word2vec_format方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。