# -*- 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]