Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
sj29-innovate committed Jan 8, 2018
1 parent 80dc13d commit 848e5ee
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions gensim/summarization/bm25.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,12 +78,14 @@ def __init__(self, corpus):
self.f = []
self.df = {}
self.idf = {}
self.doc_length = []
self.initialize()

def initialize(self):
"""Calculates frequencies of terms in documents and in corpus. Also computes inverse document frequencies."""
for document in self.corpus:
frequencies = {}
doc_length.append(len(document))
for word in document:
if word not in frequencies:
frequencies[word] = 0
Expand Down Expand Up @@ -121,9 +123,8 @@ def get_score(self, document, index, average_idf):
if word not in self.f[index]:
continue
idf = self.idf[word] if self.idf[word] >= 0 else EPSILON * average_idf
doc_length = len(self.corpus[index])
score += (idf * self.f[index][word] * (PARAM_K1 + 1)
/ (self.f[index][word] + PARAM_K1 * (1 - PARAM_B + PARAM_B * doc_length / self.avgdl)))
/ (self.f[index][word] + PARAM_K1 * (1 - PARAM_B + PARAM_B * doc_length[index] / self.avgdl)))
return score

def get_scores(self, document, average_idf):
Expand Down

0 comments on commit 848e5ee

Please sign in to comment.