Skip to main content

Compute Word Mover's Distance using any type of Word Embedding model

Project description

Word Mover's Distance

In this package you will find the implementation of Word Mover's Distance for a generic Word Embeddings model.

I largely reused code available in the gensim library, in particular the wmdistance function, making it more general so that it can be used with other Word Embeddings models, such as GloVe.

You can find a real-world usage of this package in my news summariser repository, where I use Word Mover's distance for finding the most similar sentences in a given news article.

Basic usage

Import the library:

import word_embedding.model as model

Initialise a Word Embedding object

You can pass the path where the model is stored:

model = model.WordEmbedding(model_fn="/path/where/my/model/is/stored.txt")

or you can pass the model itself, previously loaded (assuming your model is a dictionary, whose keys are the various words and its values the vector representation of the various words):

model = model.WordEmbedding(model=my_word_embedding_model)

Compute Word Mover's distance

s1 = 'Obama speaks to the media in Chicago'.lower().split()
s2 = 'The president spoke to the press in Chicago'.lower().split()
wmdistance = model.wmdistance(s1, s2)
1.8119693993679309

Remember that the wmdistance(s1, s2) method expects two List[str] as input!

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

word_mover_distance-0.0.1.tar.gz (3.4 kB view hashes)

Uploaded Source

Built Distribution

word_mover_distance-0.0.1-py3-none-any.whl (4.5 kB view hashes)

Uploaded Python 3

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page