# -*- coding: utf-8 -*- import gensim.models.word2vec as word2vec import gensim.models.doc2vec as doc2vec import gensim import logging # word2vec Text8 的训练 def train_save_model(): # logging.basicConfig(format='%(asctime)s : %(levelname)s :%(message)',level=logging.INFO) # 加载预料 sentences = word2vec.Text8Corpus('text8') model = word2vec.Word2Vec(sentences, size=200) model.save('text2020.model') # 加载模型 def load_model(): model = word2vec.Word2Vec.load('text2020.model') # simi = model.similar_by_vector('women', 'men') # print(simi) #print(model.most_similar('man')) print(model['learn']) # 执行代码 #load_model() if __name__ == '__main__': #train_save_model() load_model()
word2vec实现的代码
最新推荐文章于 2024-09-08 21:29:34 发布