Spaces:
Runtime error
Runtime error
Commit
·
2f5a8f1
1
Parent(s):
9c7a582
Update app.py
Browse files
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 |
-
#
|
26 |
-
|
27 |
-
|
28 |
-
|
29 |
-
|
|
|
|
|
|
|
|
|
|
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.")
|