Skip to content

Commit

Permalink
TextRank: compute ranks for only half of the symmetric matrix
Browse files Browse the repository at this point in the history
  • Loading branch information
miso-belica committed Feb 23, 2020
1 parent c09847c commit b9211ae
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions sumy/summarizers/text_rank.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,11 @@ def _create_matrix(self, document):
weights = numpy.zeros((sentences_count, sentences_count))

for i, words_i in enumerate(sentences_as_words):
for j, words_j in enumerate(sentences_as_words):
weights[i, j] = self._rate_sentences_edge(words_i, words_j)
for j in range(i, sentences_count):
rating = self._rate_sentences_edge(words_i, sentences_as_words[j])
weights[i, j] = rating
weights[j, i] = rating

weights /= (weights.sum(axis=1)[:, numpy.newaxis] + self._ZERO_DIVISION_PREVENTION)

# In the original paper, the probability of randomly moving to any of the vertices
Expand Down

0 comments on commit b9211ae

Please sign in to comment.