NLP计算词相关关系之word2vec

import gensim

inp='D:\python_noweightpathway\TIA\TIAxmmc.txt'
outp1 = 'D:\python_noweightpathway\TIA\model'
outp2 = 'D:\python_noweightpathway\TIA\vector'
sentences=[]
#读取数据生成sentences
file=open(u'D:\python_noweightpathway\TIA\TIAxmmc.txt',encoding='utf-8')
sentences = gensim.models.word2vec.LineSentence(file)
model = gensim.models.Word2Vec(sentences, size=100, window=6, min_count=5, workers=8)
model.save(outp1)

读取模型

# -*- coding: utf-8 -*-
# <nbformat>3.0</nbformat>

import gensim
# 导入模型
model = gensim.models.Word2Vec.load("D:\python_noweightpathway\TIA\model")
print(model.wv.most_similar(positive=['瑞舒伐他汀钙片']))

你可能感兴趣的:(NLP计算词相关关系之word2vec)