Spaces:
Runtime error
Runtime error
isaiahkabraham
commited on
Commit
•
5b03b2e
1
Parent(s):
b14bd1a
Create app.py
Browse files
app.py
ADDED
@@ -0,0 +1,26 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
from transformers.utils import logging
|
2 |
+
logging.set_verbosity_error()
|
3 |
+
from sentence_transformers import SentenceTransformer
|
4 |
+
model = SentenceTransformer("all-MiniLM-L6-v2")
|
5 |
+
sentences1 = ['The cat sits outside',
|
6 |
+
'A man is playing guitar',
|
7 |
+
'The movies are awesome']
|
8 |
+
embeddings1 = model.encode(sentences1, convert_to_tensor=True)
|
9 |
+
sentences2 = ['The dog plays in the garden',
|
10 |
+
'A woman watches TV',
|
11 |
+
'The new movie is so great']
|
12 |
+
embeddings2 = model.encode(sentences2,
|
13 |
+
convert_to_tensor=True)
|
14 |
+
print(embeddings2)
|
15 |
+
|
16 |
+
from sentence_transformers import util
|
17 |
+
cosine_scores = util.cos_sim(embeddings1,embeddings2)
|
18 |
+
|
19 |
+
print(cosine_scores)
|
20 |
+
|
21 |
+
for i in range(len(sentences1)):
|
22 |
+
print("{} \t\t {} \t\t Score: {:.4f}".format(sentences1[i],
|
23 |
+
sentences2[i],
|
24 |
+
cosine_scores[i][i]))
|
25 |
+
|
26 |
+
|