Skip to content

Instantly share code, notes, and snippets.

@YiLi225
Last active May 5, 2022 22:01
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 YiLi225/e499818af01b8af87f2fa6836bfe8214 to your computer and use it in GitHub Desktop.
Save YiLi225/e499818af01b8af87f2fa6836bfe8214 to your computer and use it in GitHub Desktop.
# 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