TextRank算法时空复杂度求解:基于指定EMNLP2004论文的技术问询
Great question! Let's break down the time and space complexity of TextRank for both keyword extraction and sentence summarization, building on your initial reasoning about PageRank's complexity:
TextRank Complexity Analysis
Keyword Extraction
- Time Complexity: Your initial conclusion of
O(i*(n+m))is spot-on. Here,nis the number of vocabulary nodes,mis the number of co-occurrence edges between words, andiis the number of PageRank iterations needed for convergence (typically between 10-50, a constant in practice). Sinceidoesn't scale with input size, you could also approximate this asO(n+m)for practical purposes. - Space Complexity: If using an adjacency matrix to represent the word co-occurrence graph, the space cost is
O(V²)whereVis the size of the vocabulary. However, if you use an adjacency table (a more memory-efficient structure for sparse graphs), this drops toO(n+m)since you only store existing edges rather than all possible pairs.
Sentence Extraction (Summarization)
The core PageRank iteration logic stays the same, but the graph nodes and edge calculation add some key nuances:
- Time Complexity:
- Graph Construction: First, you need to compute similarity scores between every pair of sentences (often using cosine similarity on word embeddings or bag-of-words vectors). This step takes
O(S²*d)whereSis the number of sentences anddis the dimensionality of the sentence vectors. - PageRank Iterations: Just like keyword extraction, each iteration runs in
O(S+E)time whereEis the number of edges between sentences (if you keep only edges above a similarity threshold,Emay be smaller thanS²). Multiply byiiterations, givingO(i*(S+E)). - Total Time: Combining both steps, the overall time complexity is
O(S²*d + i*(S+E)).
- Graph Construction: First, you need to compute similarity scores between every pair of sentences (often using cosine similarity on word embeddings or bag-of-words vectors). This step takes
- Space Complexity:
- Using an adjacency matrix for sentence similarity:
O(S²)whereSis the number of sentences. - Using an adjacency table:
O(S+E)to store only valid edges between similar sentences.
- Using an adjacency matrix for sentence similarity:
It's worth noting that in real-world implementations, optimizations (like pruning low-similarity edges early) can reduce both time and space costs significantly, especially for large document collections.
内容的提问来源于stack exchange,提问作者johnbumble
相关产品推荐
相关产品推荐

