Created
August 24, 2020 21:33
-
-
Save purva91/64d586edbecf4bf1f68913e1e6293009 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| !pip3 install --upgrade tensorflow-gpu | |
| # Install TF-Hub. | |
| !pip3 install tensorflow-hub |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import tensorflow as tf | |
| import tensorflow_hub as hub | |
| import numpy as np |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| module_url = "https://tfhub.dev/google/universal-sentence-encoder/4" | |
| model = hub.load(module_url) | |
| print ("module %s loaded" % module_url) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| sentence_embeddings = model(sentences) | |
| query = "I had pizza and pasta" | |
| query_vec = model([query])[0] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| for sent in sentences: | |
| sim = cosine(query_vec, model([sent])[0]) | |
| print("Sentence = ", sent, "; similarity = ", sim) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment