Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -36,13 +36,13 @@ def answer_question(prompt):
|
|
36 |
return generated_answer
|
37 |
|
38 |
def calculate_similarity(word, other_words, model, threshold=0.5):
|
39 |
-
|
40 |
-
|
41 |
-
|
42 |
-
|
43 |
-
|
44 |
-
|
45 |
-
|
46 |
|
47 |
|
48 |
def highlight_words_within_cluster(sentences, model, exclude_words):
|
|
|
36 |
return generated_answer
|
37 |
|
38 |
def calculate_similarity(word, other_words, model, threshold=0.5):
|
39 |
+
embeddings_word = model.encode([word])
|
40 |
+
embeddings_other_words = model.encode(other_words)
|
41 |
+
for i, embedding in enumerate(embeddings_other_words):
|
42 |
+
similarity = 1 - scipy.spatial.distance.cosine(embeddings_word[0], embedding)
|
43 |
+
if similarity > threshold and similarity < 0.85:
|
44 |
+
return i, similarity
|
45 |
+
return None, None
|
46 |
|
47 |
|
48 |
def highlight_words_within_cluster(sentences, model, exclude_words):
|