emiliosheinz commited on
Commit
2f5a8f1
·
1 Parent(s): 9c7a582

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +9 -5
app.py CHANGED
@@ -22,8 +22,12 @@ if sentence1 and sentence2:
22
  with torch.no_grad():
23
  embeddings = model(input_ids['input_ids'], attention_mask=input_ids['attention_mask'])[0]
24
 
25
- # calculate the cosine similarity between the embeddings
26
- similarity = torch.nn.functional.cosine_similarity(embeddings[0], embeddings[1]).item()
27
-
28
- # display the predicted similarity to the user
29
- st.write("Similarity score between the sentences:", similarity)
 
 
 
 
 
22
  with torch.no_grad():
23
  embeddings = model(input_ids['input_ids'], attention_mask=input_ids['attention_mask'])[0]
24
 
25
+ # check if both sentences have embeddings
26
+ if embeddings.shape[0] == 2:
27
+ # calculate the cosine similarity between the embeddings
28
+ similarity = torch.nn.functional.cosine_similarity(embeddings[0], embeddings[1]).item()
29
+
30
+ # display the predicted similarity to the user
31
+ st.write("Similarity score between the sentences:", similarity)
32
+ else:
33
+ st.write("Unable to calculate similarity.")