# -*- coding: utf-8 -*- import gensim # 导入模型 model = gensim.models.KeyedVectors.load_word2vec_format(‘vectors.bin‘, binary=True) # 得到两组词的相似度 list1 = [u‘核能‘] list2 = [u‘电能‘] list3 = [u‘电力‘] list_sim1 = model.n_similarity(list1, list2) print list_sim1 list_sim2 = model.n_similarity(list2, list3) print list_sim2, ‘\n‘ # 得到一组词中最无关的词 list4 = [u‘汽车‘, u‘火车‘, u‘飞机‘, u‘北京‘] print model.doesnt_match(list4) print ‘\n‘ # 得到与一个词最相关的若干词及相似程度 result = model.most_similar(u‘脱水工艺‘) for each in result: print each[0] , each[1]
时间: 2024-10-06 15:17:32