Spaces:
Runtime error
Runtime error
Fix errors for unknown words and lowercase expression
Browse files
app.py
CHANGED
@@ -44,7 +44,11 @@ all_vectors = np.array(df["embeddings"].to_list())
|
|
44 |
|
45 |
|
46 |
def word_to_vectors(word):
|
47 |
-
|
|
|
|
|
|
|
|
|
48 |
|
49 |
|
50 |
def expression_to_vectors(input):
|
@@ -55,6 +59,7 @@ def get_results(expression):
|
|
55 |
if len(expression) < 1:
|
56 |
raise gr.Error("Please provide an expression.")
|
57 |
|
|
|
58 |
vectors = expression_to_vectors(expression)
|
59 |
similarity_scores = cosine_similarity([vectors], all_vectors)[0]
|
60 |
top_indices = np.argsort(similarity_scores)[::-1]
|
|
|
44 |
|
45 |
|
46 |
def word_to_vectors(word):
|
47 |
+
result = df.loc[df["word"] == word].embeddings.to_numpy()
|
48 |
+
if len(result) < 1:
|
49 |
+
raise gr.Error("Word not found in the dictionary.")
|
50 |
+
else:
|
51 |
+
return result[0]
|
52 |
|
53 |
|
54 |
def expression_to_vectors(input):
|
|
|
59 |
if len(expression) < 1:
|
60 |
raise gr.Error("Please provide an expression.")
|
61 |
|
62 |
+
expression = expression.lower()
|
63 |
vectors = expression_to_vectors(expression)
|
64 |
similarity_scores = cosine_similarity([vectors], all_vectors)[0]
|
65 |
top_indices = np.argsort(similarity_scores)[::-1]
|