Skip to content

Commit 5bd04a5

Browse files
committed
Merge remote-tracking branch 'refs/remotes/origin/master'
2 parents f112601 + 70ed725 commit 5bd04a5

File tree

2 files changed

+10
-10
lines changed

2 files changed

+10
-10
lines changed

engine/rank.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,7 @@ def bm25(
8282
for word, score in sim_list
8383
if score > 0.7 and word not in query
8484
]
85+
sim_count = len(sim_weight_list)
8586

8687
# Search terms to look up tf and idf for
8788
search_terms = set(query).union(set(map(lambda x: x[0], sim_weight_list)))
@@ -158,7 +159,7 @@ def bm25(
158159

159160
score += (
160161
weight
161-
/ 3
162+
/ sim_count
162163
* (
163164
idf_val
164165
* (tf_val * (k1 + 1))

engine/similarity.py

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,14 @@
33

44
model = None
55

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+
614

715
def most_similar(word: str, topn=7) -> list:
816
"""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:
1624
"""
1725

1826
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")
2727
try:
28-
2928
most_sim = model.most_similar(word, topn=topn)
3029
# print(f"Most similar words to {word}: {most_sim}")
3130
return most_sim

0 commit comments

Comments
 (0)