Created
February 9, 2023 15:48
-
-
Save qaixerabbas/84b1172ca25c7f987e669044647e442f 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
from sentence_transformers import SentenceTransformer, util | |
import time | |
model = SentenceTransformer("all-MiniLM-L6-v2") | |
# Two lists of sentences | |
sentences1 = [ | |
"I want to know about financial advice about car loan.", | |
] | |
sentences2 = [ | |
"How to get car loan financial advice", | |
] | |
t1 = time.time() | |
# Compute embedding | |
embeddings1 = model.encode(sentences1, convert_to_tensor=True) | |
embeddings2 = model.encode(sentences2, convert_to_tensor=True) | |
# cosine-similarities | |
cosine_scores = util.cos_sim(embeddings1, embeddings2) | |
pt_cosine = util.pytorch_cos_sim(embeddings1, embeddings2) | |
t2 = time.time() | |
print(f"contextual similarity: {cosine_scores}, with time {t2 - t1} seconds") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment