How to calculate the sentence similarity using word2vec model of gensim with python

后端 未结 14 1321
一向
一向 2020-11-28 00:31

According to the Gensim Word2Vec, I can use the word2vec model in gensim package to calculate the similarity between 2 words.

e.g.

trained_model.simi         


        
14条回答
  •  日久生厌
    2020-11-28 01:16

    There is a function from the documentation taking a list of words and comparing their similarities.

    s1 = 'This room is dirty'
    s2 = 'dirty and disgusting room' #corrected variable name
    
    distance = model.wv.n_similarity(s1.lower().split(), s2.lower().split())
    

提交回复
热议问题