gensim logo

gensim
gensim tagline

Get Expert Help From The Gensim Authors

Consulting in Machine Learning & NLP

• Commercial document similarity engine: ScaleText.ai

Corporate trainings in Python Data Science and Deep Learning

summarization.pagerank_weighted – Weighted PageRank algorithm

summarization.pagerank_weighted – Weighted PageRank algorithm

This module calculate PageRank [1] based on wordgraph.

[1]https://en.wikipedia.org/wiki/PageRank

Examples

Calculate Pagerank for words

>>> from gensim.summarization.keywords import get_graph
>>> from gensim.summarization.pagerank_weighted import pagerank_weighted
>>> graph = get_graph("The road to hell is paved with good intentions.")
>>> # result will looks like {'good': 0.70432858653171504, 'hell': 0.051128871128006126, ...}
>>> result = pagerank_weighted(graph)

Build matrix from graph

>>> from gensim.summarization.pagerank_weighted import build_adjacency_matrix
>>> build_adjacency_matrix(graph).todense()
matrix([[ 0.,  0.,  0.,  0.,  0.],
        [ 0.,  0.,  1.,  0.,  0.],
        [ 0.,  1.,  0.,  0.,  0.],
        [ 0.,  0.,  0.,  0.,  0.],
        [ 0.,  0.,  0.,  0.,  0.]])
gensim.summarization.pagerank_weighted.build_adjacency_matrix(graph)

Get matrix representation of given graph.

Parameters:graph (Graph) – Given graph.
Returns:Adjacency matrix of given graph, n is number of nodes.
Return type:scipy.sparse.csr_matrix, shape = [n, n]
gensim.summarization.pagerank_weighted.build_probability_matrix(graph)

Get square matrix of shape (n, n), where n is number of nodes of the given graph.

Parameters:graph (Graph) – Given graph.
Returns:Eigenvector of matrix a, n is number of nodes of graph.
Return type:numpy.ndarray, shape = [n, n]
gensim.summarization.pagerank_weighted.pagerank_weighted(graph, damping=0.85)

Get dictionary of graph nodes and its ranks.

Parameters:
  • graph (Graph) – Given graph.
  • damping (float) – Damping parameter, optional
Returns:

Nodes of graph as keys, its ranks as values.

Return type:

dict

gensim.summarization.pagerank_weighted.principal_eigenvector(a)

Get eigenvector of square matrix a.

Parameters:a (numpy.ndarray, shape = [n, n]) – Given matrix.
Returns:Eigenvector of matrix a.
Return type:numpy.ndarray, shape = [n, ]
gensim.summarization.pagerank_weighted.process_results(graph, vec)

Get graph nodes and corresponding absolute values of provided eigenvector. This function is helper for pagerank_weighted()

Parameters:
  • graph (Graph) – Given graph.
  • vec (numpy.ndarray, shape = [n, ]) – Given eigenvector, n is number of nodes of graph.
Returns:

Graph nodes as keys, corresponding elements of eigenvector as values.

Return type:

dict