Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -6,14 +6,20 @@ from sentence_transformers import SentenceTransformer, util
|
|
6 |
model = SentenceTransformer('all-MiniLM-L6-v2')
|
7 |
|
8 |
# Two lists of sentences
|
9 |
-
sentences1 = ['
|
10 |
-
'
|
11 |
-
'The new movie is awesome'
|
|
|
12 |
|
13 |
sentences2 = ['The dog plays in the garden',
|
14 |
'A woman watches TV',
|
15 |
'The new movie is so great']
|
16 |
|
|
|
|
|
|
|
|
|
|
|
17 |
#Compute embedding for both lists
|
18 |
embeddings1 = model.encode(sentences1, convert_to_tensor=True)
|
19 |
embeddings2 = model.encode(sentences2, convert_to_tensor=True)
|
@@ -21,10 +27,12 @@ embeddings2 = model.encode(sentences2, convert_to_tensor=True)
|
|
21 |
#Compute cosine-similarities
|
22 |
cosine_scores = util.cos_sim(embeddings1, embeddings2)
|
23 |
|
|
|
|
|
24 |
(col1, col2, score_col)= st.columns(3)
|
25 |
-
col1.header("
|
26 |
-
col2.header("
|
27 |
-
score_col.header("
|
28 |
#Output the pairs with their score
|
29 |
for i in range(len(sentences1)):
|
30 |
#st.text("{} \t\t {} \t\t Score: {:.4f}".format(sentences1[i], sentences2[i], cosine_scores[i][i]))
|
|
|
6 |
model = SentenceTransformer('all-MiniLM-L6-v2')
|
7 |
|
8 |
# Two lists of sentences
|
9 |
+
sentences1 = ['A man is playing guitar',
|
10 |
+
'The cat sits outside',
|
11 |
+
'The new movie is awesome',
|
12 |
+
'I do not have a match']
|
13 |
|
14 |
sentences2 = ['The dog plays in the garden',
|
15 |
'A woman watches TV',
|
16 |
'The new movie is so great']
|
17 |
|
18 |
+
st.text("When you have two arrays of sentences, you can compare them. Inspect these two unlabeled arrays")
|
19 |
+
|
20 |
+
st.text(sentences1)
|
21 |
+
st.text(sentences2)
|
22 |
+
|
23 |
#Compute embedding for both lists
|
24 |
embeddings1 = model.encode(sentences1, convert_to_tensor=True)
|
25 |
embeddings2 = model.encode(sentences2, convert_to_tensor=True)
|
|
|
27 |
#Compute cosine-similarities
|
28 |
cosine_scores = util.cos_sim(embeddings1, embeddings2)
|
29 |
|
30 |
+
st.text("Computing which pairs are most similar")
|
31 |
+
|
32 |
(col1, col2, score_col)= st.columns(3)
|
33 |
+
col1.header("Left Token")
|
34 |
+
col2.header("Right Token")
|
35 |
+
score_col.header("Score")
|
36 |
#Output the pairs with their score
|
37 |
for i in range(len(sentences1)):
|
38 |
#st.text("{} \t\t {} \t\t Score: {:.4f}".format(sentences1[i], sentences2[i], cosine_scores[i][i]))
|