Skinish
Skinish

Reputation: 65

Word Mover's Distance in Python

I am trying to calculate the similarity of 2 texts using WMD. I have tried to use the following code in Python 3, using gensim:

word2vec_model = gensim.models.KeyedVectors.load_word2vec_format('GoogleNews-vectors-negative300.bin', binary=True)
word2vec_model.init_sims(replace=True) # normalizes vectors
distance = word2vec_model.wmdistance("string 1", "string 2")  # Compute WMD as normal.

However, I don't think this is returning me the right value. How should I do this in python?

Upvotes: 3

Views: 4741

Answers (1)

Hironsan
Hironsan

Reputation: 685

Please split string:

distance = word2vec_model.wmdistance("string 1".split(), "string 2".split())
>>> 0.4114476676950455

Arguments need to be list of strings.

Upvotes: 5

Related Questions