Created
May 9, 2022 15:14
-
-
Save Hilal-Urun/41d39c1b13199d933182477fd6fe1697 to your computer and use it in GitHub Desktop.
senetence-transformers
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
#!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