本文整理汇总了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
示例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']
示例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']