Comparing Text using Word Vectors


  • Word vectors try to represent meaning of words
  • Words which appear in similar context have similar vectors

This will require training word vectors based on a huge corpus of data.

We can use pretrained word vectors using the glove algorithm, Spacy library in python makes it easy to work with.

word vectors tpically have a lenth of few hundreds elements dimensions for word vectors

first pass the string to the nlp object

Using token we iterate over and try to print first few dimensions of the vector

actual values dont matter; what matters is how similar they are to other words

  • Direction of vectors matters
  • “Distance” between words = angle between the vectors
  • Cosine similarity
    • 1: If vectors point in the same direction
    • 0: If they are perpendicular
    • -1: If they point in opposite directions

In [5]: doc.similarity(nlp(“dog”))

Out[5]: 0.80168555173294953

Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s