hacpdsae2023 commited on
Commit
6517c43
·
1 Parent(s): f1aa832

adapt code to one sentence list

Browse files

move to one sentence and created cosine similarity matrix

Files changed (1) hide show
  1. app.py +8 -14
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
- # Two lists of sentences
14
- sentences1 = ['The cat sits outside',
15
- 'A man is playing guitar',
16
- 'The new movie is awesome']
17
 
18
- sentences2 = ['The dog plays in the garden',
19
- 'A woman watches TV',
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(embeddings1, embeddings2)
28
 
29
  #Output the pairs with their score
30
- for i in range(len(sentences1)):
31
- st.write("{} \t\t {} \t\t Score: {:.4f}".format(sentences1[i], sentences2[i], cosine_scores[i][i]))
 
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
  #-------------------------------------------------------------