Last active
May 5, 2022 22:01
-
-
Save YiLi225/e499818af01b8af87f2fa6836bfe8214 to your computer and use it in GitHub Desktop.
This file contains 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
# Install: !pip install sentence_transformers | |
from sentence_transformers import SentenceTransformer | |
model = SentenceTransformer('distilbert-base-nli-mean-tokens') | |
# sentences = [doc_set[9234], doc_set[9239], doc_set[1131966]] | |
sentence_embeddings = model.encode(sentences) | |
# Calculate cosine distance of the embeddings | |
from scipy.spatial import distance | |
print(1 - distance.cosine(sentence_embeddings[0], sentence_embeddings[1])) | |
print(1 - distance.cosine(sentence_embeddings[0], sentence_embeddings[2])) | |
print(1 - distance.cosine(sentence_embeddings[1], sentence_embeddings[2])) | |
sentences |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment