Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed bug with LexRank's power iteration #194

Merged
merged 4 commits into from
Aug 11, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions sumy/summarizers/lex_rank.py
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,7 @@ def power_method(matrix, epsilon):

while lambda_val > epsilon:
next_p = numpy.dot(transposed_matrix, p_vector)
next_p /= numpy.linalg.norm(next_p)
lambda_val = numpy.linalg.norm(numpy.subtract(next_p, p_vector))
p_vector = next_p

Expand Down
13 changes: 13 additions & 0 deletions tests/test_summarizers/test_lex_rank.py
Original file line number Diff line number Diff line change
Expand Up @@ -169,3 +169,16 @@ def test_power_method_should_return_different_scores_for_sentences():
scores = LexRankSummarizer.power_method(matrix, LexRankSummarizer.epsilon)

assert len(frozenset(scores.tolist())) > 1

def test_power_method_should_return_finite():
"""See https://github.com/miso-belica/sumy/issues/187"""
matrix = numpy.array([
[0.1, 0.2, 0.3, 0.6, 0.9],
[0.45, 0, 0.3, 0.6, 0],
[0.5, 0.6, 0.3, 1, 0.9],
[0.7, 0, 0, 0.6, 0],
[0.5, 0.123, 0, 0.111, 0.9],
])
scores = LexRankSummarizer.power_method(matrix, LexRankSummarizer.epsilon)

assert all(numpy.isfinite(scores))
Loading