File tree Expand file tree Collapse file tree 2 files changed +10
-10
lines changed Expand file tree Collapse file tree 2 files changed +10
-10
lines changed Original file line number Diff line number Diff line change @@ -82,6 +82,7 @@ def bm25(
82
82
for word , score in sim_list
83
83
if score > 0.7 and word not in query
84
84
]
85
+ sim_count = len (sim_weight_list )
85
86
86
87
# Search terms to look up tf and idf for
87
88
search_terms = set (query ).union (set (map (lambda x : x [0 ], sim_weight_list )))
@@ -158,7 +159,7 @@ def bm25(
158
159
159
160
score += (
160
161
weight
161
- / 3
162
+ / sim_count
162
163
* (
163
164
idf_val
164
165
* (tf_val * (k1 + 1 ))
Original file line number Diff line number Diff line change 3
3
4
4
model = None
5
5
6
+ try :
7
+ model = gensim .models .KeyedVectors .load ("./glove-wiki-gigaword-100.model" )
8
+ except FileNotFoundError :
9
+ print ("Model not found, downloading..." )
10
+ model = api .load ("glove-wiki-gigaword-100" )
11
+ model .save ("glove-wiki-gigaword-100.model" )
12
+ print ("Model downloaded and saved" )
13
+
6
14
7
15
def most_similar (word : str , topn = 7 ) -> list :
8
16
"""Uses GloVe embeddings to find the most similar words to the given word.
@@ -16,16 +24,7 @@ def most_similar(word: str, topn=7) -> list:
16
24
"""
17
25
18
26
global model
19
- if model is None :
20
- try :
21
- model = gensim .models .KeyedVectors .load ("./glove-wiki-gigaword-100.model" )
22
- except FileNotFoundError :
23
- print ("Model not found, downloading..." )
24
- model = api .load ("glove-wiki-gigaword-100" )
25
- model .save ("glove-wiki-gigaword-100.model" )
26
- print ("Model downloaded and saved" )
27
27
try :
28
-
29
28
most_sim = model .most_similar (word , topn = topn )
30
29
# print(f"Most similar words to {word}: {most_sim}")
31
30
return most_sim
You can’t perform that action at this time.
0 commit comments