Skip to content

Instantly share code, notes, and snippets.

@Hilal-Urun
Created May 9, 2022 15:14
Show Gist options
  • Save Hilal-Urun/41d39c1b13199d933182477fd6fe1697 to your computer and use it in GitHub Desktop.
Save Hilal-Urun/41d39c1b13199d933182477fd6fe1697 to your computer and use it in GitHub Desktop.
senetence-transformers
#!pip install sentence-transformers==2.2.0
from sentence_transformers import SentenceTransformer, util
model = SentenceTransformer("sentence-transformers/all-mpnet-base-v2")
#fbInterests func takes 2 arrays which are contain interests of google and fb and returs a similarty dict with accuracy scores
def fbInterests(google, fb):
sims={}
for g in google:
for f in fb :
g_embedding = model.encode(g)
f_embedding = model.encode(f)
tensor = util.pytorch_cos_sim(f_embedding, g_embedding)
result = tensor.numpy()[0][0]
sims[g]=[f,result]
return sims
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment