Skip to content
DeepForgeby svx
All problems
MediumNLPnlp-138

TextRank One Iteration

Problem

Perform one TextRank (PageRank) update: new[i] = (1 - damping) / n + damping * sum over j of similarity[j][i] * scores[j], where similarity[j][i] is the edge weight from j to i.

Return the updated score list, or an empty list when there are no nodes.

Hint

Each node receives mass along incoming edges: sum the column down similarity[j][i].

Test cases

case 1
in: [[1,1],[[0,1],[1,0]],0.85]
expected: [0.925,0.925]
case 2
in: [[1,0],[[0,1],[0,0]],0.5]
expected: [0.25,0.75]
case 3
in: [[],[],0.85]
expected: []
case 4
in: [[0.5],[[0]],0.85]
expected: [0.15000000000000002]
Starter codePython
def textrank_iteration(scores, similarity, damping):
    # Your code here
    pass

4 test cases · run your code against them in the editor