0 votes
in NLP using Python by
How to check word similarity using the spacy package?

1 Answer

0 votes
by
To find out the similarity among words, we use word similarity. We evaluate the similarity with the help of a number that lies between 0 and 1. We use the spacy library to implement the technique of word similarity.

  import spacy

  nlp = spacy.load('en_core_web_md')

  print("Enter the words")

  input_words = input()

  tokens = nlp(input_words)

  for i in tokens:

  print(i.text, i.has_vector, i.vector_norm, i.is_oov)

  token_1, token_2 = tokens[0], tokens[1]

  print("Similarity between words:", token_1.similarity(token_2))

Output:

  hot  True 5.6898586 False

  cold True6.5396233 False

  Similarity: 0.597265

This means that the similarity between the words ‘hot’ and ‘cold’ is just 59 percent.
...