joehare commited on
Commit
e16d5a9
·
1 Parent(s): c0b1790

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +22 -0
app.py ADDED
@@ -0,0 +1,22 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from sentence_transformers import SentenceTransformer, util
2
+ model = SentenceTransformer('all-MiniLM-L6-v2')
3
+
4
+ # Two lists of sentences
5
+ sentences1 = ['The cat sits outside',
6
+ 'A man is playing guitar',
7
+ 'The new movie is awesome']
8
+
9
+ sentences2 = ['The dog plays in the garden',
10
+ 'A woman watches TV',
11
+ 'The new movie is so great']
12
+
13
+ #Compute embedding for both lists
14
+ embeddings1 = model.encode(sentences1, convert_to_tensor=True)
15
+ embeddings2 = model.encode(sentences2, convert_to_tensor=True)
16
+
17
+ #Compute cosine-similarities
18
+ cosine_scores = util.cos_sim(embeddings1, embeddings2)
19
+
20
+ #Output the pairs with their score
21
+ for i in range(len(sentences1)):
22
+ print("{} \t\t {} \t\t Score: {:.4f}".format(sentences1[i], sentences2[i], cosine_scores[i][i]))