Spaces:
Runtime error
Runtime error
Upload app.py
Browse files
app.py
CHANGED
@@ -14,12 +14,18 @@ def cosine_similarity(x,y):
|
|
14 |
|
15 |
|
16 |
# Function to Load Glove Embeddings
|
17 |
-
def load_glove_embeddings(glove_path="Data/embeddings.pkl"):
|
18 |
|
19 |
-
|
20 |
-
|
21 |
-
|
22 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
23 |
|
24 |
# Get Averaged Glove Embedding of a sentence
|
25 |
def averaged_glove_embeddings(sentence, embeddings_dict):
|
@@ -33,8 +39,7 @@ def averaged_glove_embeddings(sentence, embeddings_dict):
|
|
33 |
|
34 |
return glove_embedding/max(count_words,1)
|
35 |
|
36 |
-
|
37 |
-
glove_embeddings = load_glove_embeddings()
|
38 |
|
39 |
# Gold standard words to search from
|
40 |
gold_words = ["flower","mountain","tree","car","building"]
|
@@ -45,6 +50,8 @@ st.title("Search Based Retrieval Demo")
|
|
45 |
st.subheader("Pass in an input word or even a sentence (e.g. jasmine or mount adams)")
|
46 |
text_search = st.text_input("", value="")
|
47 |
|
|
|
|
|
48 |
|
49 |
# Find closest word to an input word
|
50 |
if text_search:
|
|
|
14 |
|
15 |
|
16 |
# Function to Load Glove Embeddings
|
|
|
17 |
|
18 |
+
def load_glove_embeddings(file):
|
19 |
+
print("Loading Glove Model")
|
20 |
+
glove_model = {}
|
21 |
+
with open(file, 'r', encoding='utf-8') as f:
|
22 |
+
for line in f:
|
23 |
+
values = line.split()
|
24 |
+
word = values[0]
|
25 |
+
vector = np.asarray(values[1:], dtype='float32')
|
26 |
+
glove_model[word] = vector
|
27 |
+
print("Loaded {} words".format(len(glove_model)))
|
28 |
+
return glove_model
|
29 |
|
30 |
# Get Averaged Glove Embedding of a sentence
|
31 |
def averaged_glove_embeddings(sentence, embeddings_dict):
|
|
|
39 |
|
40 |
return glove_embedding/max(count_words,1)
|
41 |
|
42 |
+
|
|
|
43 |
|
44 |
# Gold standard words to search from
|
45 |
gold_words = ["flower","mountain","tree","car","building"]
|
|
|
50 |
st.subheader("Pass in an input word or even a sentence (e.g. jasmine or mount adams)")
|
51 |
text_search = st.text_input("", value="")
|
52 |
|
53 |
+
# Load glove embeddings
|
54 |
+
glove_embeddings = load_glove_embeddings('glove.6B.50d.txt')
|
55 |
|
56 |
# Find closest word to an input word
|
57 |
if text_search:
|