Spaces:
Runtime error
Runtime error
Commit
·
6517c43
1
Parent(s):
f1aa832
adapt code to one sentence list
Browse filesmove to one sentence and created cosine similarity matrix
app.py
CHANGED
@@ -10,25 +10,19 @@ st.write(dataset['train'][0])
|
|
10 |
from sentence_transformers import SentenceTransformer, util
|
11 |
model = SentenceTransformer('all-MiniLM-L6-v2')
|
12 |
|
13 |
-
#
|
14 |
-
|
15 |
-
'A man is playing guitar',
|
16 |
-
'The new movie is awesome']
|
17 |
|
18 |
-
|
19 |
-
|
20 |
-
'The new movie is so great']
|
21 |
-
|
22 |
-
#Compute embedding for both lists
|
23 |
-
embeddings1 = model.encode(sentences1, convert_to_tensor=True)
|
24 |
-
embeddings2 = model.encode(sentences2, convert_to_tensor=True)
|
25 |
|
26 |
#Compute cosine-similarities
|
27 |
-
cosine_scores = util.cos_sim(
|
28 |
|
29 |
#Output the pairs with their score
|
30 |
-
for i in range(len(
|
31 |
-
|
|
|
32 |
|
33 |
|
34 |
#-------------------------------------------------------------
|
|
|
10 |
from sentence_transformers import SentenceTransformer, util
|
11 |
model = SentenceTransformer('all-MiniLM-L6-v2')
|
12 |
|
13 |
+
# Sentences from the data set
|
14 |
+
sentences = dataset['train'][:10]
|
|
|
|
|
15 |
|
16 |
+
#Compute embedding
|
17 |
+
embeddings1 = model.encode(sentences, convert_to_tensor=True)
|
|
|
|
|
|
|
|
|
|
|
18 |
|
19 |
#Compute cosine-similarities
|
20 |
+
cosine_scores = util.cos_sim(embeddings, embeddings)
|
21 |
|
22 |
#Output the pairs with their score
|
23 |
+
for i in range(len(sentences)):
|
24 |
+
for j in range(i):
|
25 |
+
st.write("{} \t\t {} \t\t Score: {:.4f}".format(sentences[i], sentences[j], cosine_scores[i][j]))
|
26 |
|
27 |
|
28 |
#-------------------------------------------------------------
|