Skip to content

Instantly share code, notes, and snippets.

@hamletbatista
Last active June 21, 2019 11:12
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save hamletbatista/21363a710a516e05289e04337e3561f7 to your computer and use it in GitHub Desktop.
Save hamletbatista/21363a710a516e05289e04337e3561f7 to your computer and use it in GitHub Desktop.
#python -m spacy download en_core_web_lg
import spacy
nlp = spacy.load('en_core_web_lg')
tokens = nlp(u'hotel resort car bike')
#comparing 4 words
for token1 in tokens:
for token2 in tokens:
print(token1.text, token2.text, token1.similarity(token2))
#output
#hotel hotel 1.0
#hotel resort 0.68411607
#hotel car 0.3968005
#hotel bike 0.24491112
#resort hotel 0.68411607
#resort resort 1.0
#resort car 0.25520992
#resort bike 0.2034203
#car hotel 0.3968005
#car resort 0.25520992
#car car 1.0
#car bike 0.5357731
#bike hotel 0.24491112
#bike resort 0.2034203
#bike car 0.5357731
#bike bike 1.0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment