直接上代码吧,word2vec
# test
from gensim.models.word2vec import Word2Vec
txt_file = open('data.txt')
sentences = []
line = txt_file.readline()
while line:
sentence = line.split(' ')
sentences.append(sentence)
line = txt_file.readline()
model = Word2Vec(sentences, size=100, window=5, min_count=5, workers=1)
model.save('model_word2vec.model')
model_use = Word2Vec.load('model_word2vec.model')
xx = model_use.wv.vocab
# print(model_use.wv.vocab)
print('hel')
print(model_use.most_similar('nice'))
print(model_use.wv.similarity('nice', 'great'))
各种参数详解:
https://www.cnblogs.com/pinard/p/7278324.html
模型的一些其他使用:
https://blog.youkuaiyun.com/qq_19707521/article/details/79169826
自己在使用中:
from gensim.models import W