0

The following code when run gives the cosine distance between two words.

model.wv.distance('word1','word2')

How do I find the euclidean distance between two words? I am using gensim for word2vec implementation

1 Answers1

1

Usually the cosine-distance is preferred in this domain.

But if you needed euclidean distance, you can just request the raw vectors for each word, find the difference, and use a basic `numpy.linalg.norm' operation, as per this StackOverflow answer:

How can the Euclidean distance be calculated with NumPy?

Specifically:

import numpy as np
euc_dist = np.linalg.norm(model.wv['word1'] - model.wv['word2']))
gojomo
  • 52,260
  • 14
  • 86
  • 115
  • Thanks friend. I was comparing between cosine and Euclidean distances –  Aug 21 '19 at 06:13