We are currently solving the following issue within our repository. Here is the issue text:
--- BEGIN ISSUE ---
Error while summarizing text
Hi,

I've received the following error when trying to summarize the body of this news article:

https://www.theguardian.com/media/2016/jun/19/sun-times-brexit-in-out-shake-it-all-about

The error follows:

  File "/home/apps/comment_parser/venv/local/lib/python2.7/site-packages/gensim/summarization/summarizer.py", line 202, in summarize
    most_important_docs = summarize_corpus(corpus, ratio=ratio if word_count is None else 1)
  File "/home/apps/comment_parser/venv/local/lib/python2.7/site-packages/gensim/summarization/summarizer.py", line 161, in summarize_corpus
    pagerank_scores = _pagerank(graph)
  File "/home/apps/comment_parser/venv/local/lib/python2.7/site-packages/gensim/summarization/pagerank_weighted.py", line 24, in pagerank_weighted
    vals, vecs = eigs(pagerank_matrix.T, k=1)  # TODO raise an error if matrix has complex eigenvectors?
  File "/usr/lib/python2.7/dist-packages/scipy/sparse/linalg/eigen/arpack/arpack.py", line 1271, in eigs
    ncv, v0, maxiter, which, tol)
  File "/usr/lib/python2.7/dist-packages/scipy/sparse/linalg/eigen/arpack/arpack.py", line 685, in __init__
    raise ValueError("k must be less than ndim(A)-1, k=%d" % k)
ValueError: k must be less than ndim(A)-1, k=1

Regards,


--- END ISSUE ---

Below are some code segments, each from a relevant file. One or more of these files may contain bugs.
--- BEGIN FILES ---
Path: `gensim/summarization/pagerank_weighted.py`
Content:
```
1 #!/usr/bin/env python
2 # -*- coding: utf-8 -*-
3 #
4 # Licensed under the GNU LGPL v2.1 - http://www.gnu.org/licenses/lgpl.html
5 from numpy import empty as empty_matrix
6 from scipy.sparse import csr_matrix
7 from scipy.sparse.linalg import eigs
8 from six.moves import xrange
9 
10 try:
11     from numpy import VisibleDeprecationWarning
12     import warnings
13     warnings.filterwarnings("ignore", category=VisibleDeprecationWarning)
14 except ImportError:
15     pass
16 
17 
18 def pagerank_weighted(graph, damping=0.85):
19     adjacency_matrix = build_adjacency_matrix(graph)
20     probability_matrix = build_probability_matrix(graph)
21 
22     pagerank_matrix = damping * adjacency_matrix.todense() + (1 - damping) * probability_matrix
23 
24     vals, vecs = eigs(pagerank_matrix.T, k=1)  # TODO raise an error if matrix has complex eigenvectors?
25 
26     return process_results(graph, vecs.real)
27 
28 
29 def build_adjacency_matrix(graph):
30     row = []
31     col = []
32     data = []
33     nodes = graph.nodes()
34     length = len(nodes)
35 
36     for i in xrange(length):
37         current_node = nodes[i]
38         neighbors_sum = sum(graph.edge_weight((current_node, neighbor)) for neighbor in graph.neighbors(current_node))
39         for j in xrange(length):
40             edge_weight = float(graph.edge_weight((current_node, nodes[j])))
41             if i != j and edge_weight != 0.0:
42                 row.append(i)
43                 col.append(j)
44                 data.append(edge_weight / neighbors_sum)
45 
46     return csr_matrix((data, (row, col)), shape=(length, length))
47 
48 
49 def build_probability_matrix(graph):
50     dimension = len(graph.nodes())
51     matrix = empty_matrix((dimension, dimension))
52 
53     probability = 1.0 / float(dimension)
54     matrix.fill(probability)
55 
56     return matrix
57 
58 
59 def process_results(graph, vecs):
60     scores = {}
61     for i, node in enumerate(graph.nodes()):
62         scores[node] = abs(vecs[i, :])
63 
64     return scores
65
```
--- END FILES ---

Please first localize the bug based on the issue statement, and then generate a patch according to the `git diff` format fenced by three backticks.

Here is an example:

```diff
diff --git a/examples/server_async.py b/examples/server_async.py
--- a/examples/server_async.py
+++ b/examples/server_async.py
@@ -313,4 +313,4 @@
 
 
 if __name__ == "__main__":
-    asyncio.run(run_async_server("."), debug=True)
+    asyncio.run(run_async_server(), debug=True)
diff --git a/examples/server_sync.py b/examples/server_sync.py
--- a/examples/server_sync.py
+++ b/examples/server_sync.py
@@ -313,5 +313,5 @@
 
 
 if __name__ == "__main__":
-    server = run_sync_server(".")
+    server = run_sync_server()
     server.shutdown()

```

diff --git a/gensim/summarization/pagerank_weighted.py b/gensim/summarization/pagerank_weighted.py
--- a/gensim/summarization/pagerank_weighted.py
+++ b/gensim/summarization/pagerank_weighted.py
@@ -2,7 +2,9 @@
 # -*- coding: utf-8 -*-
 #
 # Licensed under the GNU LGPL v2.1 - http://www.gnu.org/licenses/lgpl.html
+import numpy
 from numpy import empty as empty_matrix
+from scipy.linalg import eig
 from scipy.sparse import csr_matrix
 from scipy.sparse.linalg import eigs
 from six.moves import xrange
@@ -21,9 +23,10 @@
 
     pagerank_matrix = damping * adjacency_matrix.todense() + (1 - damping) * probability_matrix
 
-    vals, vecs = eigs(pagerank_matrix.T, k=1)  # TODO raise an error if matrix has complex eigenvectors?
+    vec = principal_eigenvector(pagerank_matrix.T)
 
-    return process_results(graph, vecs.real)
+    # Because pagerank_matrix is positive, vec is always real (i.e. not complex)
+    return process_results(graph, vec.real)
 
 
 def build_adjacency_matrix(graph):
@@ -56,9 +59,23 @@
     return matrix
 
 
-def process_results(graph, vecs):
+def principal_eigenvector(a):
+    # Note that we prefer to use `eigs` even for dense matrix
+    # because we need only one eigenvector. See #441, #438 for discussion.
+
+    # But it doesn't work for dim A < 3, so we just handle this special case
+    if len(a) < 3:
+        vals, vecs = eig(a)
+        ind = numpy.abs(vals).argmax()
+        return vecs[:, ind]
+    else:
+        vals, vecs = eigs(a, k=1)
+        return vecs[:, 0]
+
+
+def process_results(graph, vec):
     scores = {}
     for i, node in enumerate(graph.nodes()):
-        scores[node] = abs(vecs[i, :])
+        scores[node] = abs(vec[i])
 
     return scores

{"golden_diff": "diff --git a/gensim/summarization/pagerank_weighted.py b/gensim/summarization/pagerank_weighted.py\n--- a/gensim/summarization/pagerank_weighted.py\n+++ b/gensim/summarization/pagerank_weighted.py\n@@ -2,7 +2,9 @@\n # -*- coding: utf-8 -*-\n #\n # Licensed under the GNU LGPL v2.1 - http://www.gnu.org/licenses/lgpl.html\n+import numpy\n from numpy import empty as empty_matrix\n+from scipy.linalg import eig\n from scipy.sparse import csr_matrix\n from scipy.sparse.linalg import eigs\n from six.moves import xrange\n@@ -21,9 +23,10 @@\n \n     pagerank_matrix = damping * adjacency_matrix.todense() + (1 - damping) * probability_matrix\n \n-    vals, vecs = eigs(pagerank_matrix.T, k=1)  # TODO raise an error if matrix has complex eigenvectors?\n+    vec = principal_eigenvector(pagerank_matrix.T)\n \n-    return process_results(graph, vecs.real)\n+    # Because pagerank_matrix is positive, vec is always real (i.e. not complex)\n+    return process_results(graph, vec.real)\n \n \n def build_adjacency_matrix(graph):\n@@ -56,9 +59,23 @@\n     return matrix\n \n \n-def process_results(graph, vecs):\n+def principal_eigenvector(a):\n+    # Note that we prefer to use `eigs` even for dense matrix\n+    # because we need only one eigenvector. See #441, #438 for discussion.\n+\n+    # But it doesn't work for dim A < 3, so we just handle this special case\n+    if len(a) < 3:\n+        vals, vecs = eig(a)\n+        ind = numpy.abs(vals).argmax()\n+        return vecs[:, ind]\n+    else:\n+        vals, vecs = eigs(a, k=1)\n+        return vecs[:, 0]\n+\n+\n+def process_results(graph, vec):\n     scores = {}\n     for i, node in enumerate(graph.nodes()):\n-        scores[node] = abs(vecs[i, :])\n+        scores[node] = abs(vec[i])\n \n     return scores\n", "issue": "Error while summarizing text\nHi,\n\nI've received the following error when trying to summarize the body of this news article:\n\nhttps://www.theguardian.com/media/2016/jun/19/sun-times-brexit-in-out-shake-it-all-about\n\nThe error follows:\n\n  File \"/home/apps/comment_parser/venv/local/lib/python2.7/site-packages/gensim/summarization/summarizer.py\", line 202, in summarize\n    most_important_docs = summarize_corpus(corpus, ratio=ratio if word_count is None else 1)\n  File \"/home/apps/comment_parser/venv/local/lib/python2.7/site-packages/gensim/summarization/summarizer.py\", line 161, in summarize_corpus\n    pagerank_scores = _pagerank(graph)\n  File \"/home/apps/comment_parser/venv/local/lib/python2.7/site-packages/gensim/summarization/pagerank_weighted.py\", line 24, in pagerank_weighted\n    vals, vecs = eigs(pagerank_matrix.T, k=1)  # TODO raise an error if matrix has complex eigenvectors?\n  File \"/usr/lib/python2.7/dist-packages/scipy/sparse/linalg/eigen/arpack/arpack.py\", line 1271, in eigs\n    ncv, v0, maxiter, which, tol)\n  File \"/usr/lib/python2.7/dist-packages/scipy/sparse/linalg/eigen/arpack/arpack.py\", line 685, in __init__\n    raise ValueError(\"k must be less than ndim(A)-1, k=%d\" % k)\nValueError: k must be less than ndim(A)-1, k=1\n\nRegards,\n\n", "before_files": [{"content": "#!/usr/bin/env python\n# -*- coding: utf-8 -*-\n#\n# Licensed under the GNU LGPL v2.1 - http://www.gnu.org/licenses/lgpl.html\nfrom numpy import empty as empty_matrix\nfrom scipy.sparse import csr_matrix\nfrom scipy.sparse.linalg import eigs\nfrom six.moves import xrange\n\ntry:\n    from numpy import VisibleDeprecationWarning\n    import warnings\n    warnings.filterwarnings(\"ignore\", category=VisibleDeprecationWarning)\nexcept ImportError:\n    pass\n\n\ndef pagerank_weighted(graph, damping=0.85):\n    adjacency_matrix = build_adjacency_matrix(graph)\n    probability_matrix = build_probability_matrix(graph)\n\n    pagerank_matrix = damping * adjacency_matrix.todense() + (1 - damping) * probability_matrix\n\n    vals, vecs = eigs(pagerank_matrix.T, k=1)  # TODO raise an error if matrix has complex eigenvectors?\n\n    return process_results(graph, vecs.real)\n\n\ndef build_adjacency_matrix(graph):\n    row = []\n    col = []\n    data = []\n    nodes = graph.nodes()\n    length = len(nodes)\n\n    for i in xrange(length):\n        current_node = nodes[i]\n        neighbors_sum = sum(graph.edge_weight((current_node, neighbor)) for neighbor in graph.neighbors(current_node))\n        for j in xrange(length):\n            edge_weight = float(graph.edge_weight((current_node, nodes[j])))\n            if i != j and edge_weight != 0.0:\n                row.append(i)\n                col.append(j)\n                data.append(edge_weight / neighbors_sum)\n\n    return csr_matrix((data, (row, col)), shape=(length, length))\n\n\ndef build_probability_matrix(graph):\n    dimension = len(graph.nodes())\n    matrix = empty_matrix((dimension, dimension))\n\n    probability = 1.0 / float(dimension)\n    matrix.fill(probability)\n\n    return matrix\n\n\ndef process_results(graph, vecs):\n    scores = {}\n    for i, node in enumerate(graph.nodes()):\n        scores[node] = abs(vecs[i, :])\n\n    return scores\n", "path": "gensim/summarization/pagerank_weighted.py"}], "after_files": [{"content": "#!/usr/bin/env python\n# -*- coding: utf-8 -*-\n#\n# Licensed under the GNU LGPL v2.1 - http://www.gnu.org/licenses/lgpl.html\nimport numpy\nfrom numpy import empty as empty_matrix\nfrom scipy.linalg import eig\nfrom scipy.sparse import csr_matrix\nfrom scipy.sparse.linalg import eigs\nfrom six.moves import xrange\n\ntry:\n    from numpy import VisibleDeprecationWarning\n    import warnings\n    warnings.filterwarnings(\"ignore\", category=VisibleDeprecationWarning)\nexcept ImportError:\n    pass\n\n\ndef pagerank_weighted(graph, damping=0.85):\n    adjacency_matrix = build_adjacency_matrix(graph)\n    probability_matrix = build_probability_matrix(graph)\n\n    pagerank_matrix = damping * adjacency_matrix.todense() + (1 - damping) * probability_matrix\n\n    vec = principal_eigenvector(pagerank_matrix.T)\n\n    # Because pagerank_matrix is positive, vec is always real (i.e. not complex)\n    return process_results(graph, vec.real)\n\n\ndef build_adjacency_matrix(graph):\n    row = []\n    col = []\n    data = []\n    nodes = graph.nodes()\n    length = len(nodes)\n\n    for i in xrange(length):\n        current_node = nodes[i]\n        neighbors_sum = sum(graph.edge_weight((current_node, neighbor)) for neighbor in graph.neighbors(current_node))\n        for j in xrange(length):\n            edge_weight = float(graph.edge_weight((current_node, nodes[j])))\n            if i != j and edge_weight != 0.0:\n                row.append(i)\n                col.append(j)\n                data.append(edge_weight / neighbors_sum)\n\n    return csr_matrix((data, (row, col)), shape=(length, length))\n\n\ndef build_probability_matrix(graph):\n    dimension = len(graph.nodes())\n    matrix = empty_matrix((dimension, dimension))\n\n    probability = 1.0 / float(dimension)\n    matrix.fill(probability)\n\n    return matrix\n\n\ndef principal_eigenvector(a):\n    # Note that we prefer to use `eigs` even for dense matrix\n    # because we need only one eigenvector. See #441, #438 for discussion.\n\n    # But it doesn't work for dim A < 3, so we just handle this special case\n    if len(a) < 3:\n        vals, vecs = eig(a)\n        ind = numpy.abs(vals).argmax()\n        return vecs[:, ind]\n    else:\n        vals, vecs = eigs(a, k=1)\n        return vecs[:, 0]\n\n\ndef process_results(graph, vec):\n    scores = {}\n    for i, node in enumerate(graph.nodes()):\n        scores[node] = abs(vec[i])\n\n    return scores\n", "path": "gensim/summarization/pagerank_weighted.py"}]}