Inferensys

Glossary

TextRank

A graph-based ranking algorithm for natural language processing that identifies the most important sentences or keywords in a document based on their co-occurrence links.
Knowledge engineer constructing knowledge base on laptop, document hierarchy visible, casual office setup.
GRAPH-BASED KEYWORD EXTRACTION

What is TextRank?

TextRank is a graph-based ranking algorithm for natural language processing that identifies the most important sentences or keywords in a document based on their co-occurrence links.

TextRank is an unsupervised, extractive summarization and keyword extraction algorithm that models a document as a semantic graph. In this graph, vertices represent lexical units (words or sentences), and edges represent co-occurrence relations defined by a sliding window. The algorithm applies a recursive, iterative voting mechanism derived from PageRank to score the importance of each vertex until convergence, surfacing the most salient terms or sentences without requiring prior training data.

Unlike supervised methods that rely on annotated corpora, TextRank exploits the inherent structure of the text itself. For keyword extraction, vertices are filtered to retain only nouns and adjectives, and edges connect words appearing within a window of N tokens. For sentence extraction, vertices represent full sentences, and edges are weighted by semantic similarity—typically cosine similarity of TF-IDF vectors. The final ranking identifies the sentences that best represent the document's core themes for extractive summarization.

GRAPH-BASED RANKING

Key Features of TextRank

TextRank adapts Google's PageRank algorithm to natural language, constructing graphs from text units and iteratively scoring them based on co-occurrence links to identify the most salient sentences or keywords.

01

Graph Construction from Co-occurrence

TextRank builds a graph where vertices represent text units (sentences or words) and edges represent co-occurrence within a defined window. For keyword extraction, a window of N words slides across the text, linking all words that appear together. For sentence extraction, edges connect sentences with overlapping lexical content. This unsupervised approach requires no labeled training data, making it domain-agnostic and immediately applicable to any language or corpus.

02

Iterative Convergence Scoring

The algorithm initializes all vertices with a default score of 1 and iteratively updates each vertex's score using the weighted sum of its neighbors' scores until convergence (typically when the change between iterations falls below a threshold of 0.0001). The damping factor—usually set to 0.85—prevents rank sinks and ensures convergence. The final score of a vertex represents its global salience within the entire graph, not just local prominence.

03

Keyword Extraction Variant

For keyword extraction, TextRank filters candidate words to retain only nouns and adjectives after part-of-speech tagging. Words that are adjacent in the filtered sequence form multi-word keyphrases. The top T vertices by final score are selected as the document's key terms. This variant outperforms TF-IDF on tasks requiring semantic coherence because it captures structural relationships rather than relying solely on raw frequency statistics.

04

Extractive Summarization Variant

For sentence extraction, TextRank treats each sentence as a vertex and computes edge weights based on content overlap—typically the number of shared lexical tokens normalized by sentence length. This penalizes long sentences that accumulate high overlap purely due to length. The top-ranked sentences are selected in their original order to form an extractive summary, preserving the document's narrative flow without generating new text.

05

Undirected vs. Directed Graph Variants

The original TextRank uses undirected, weighted graphs where edge weights are symmetric, reflecting the reciprocal nature of co-occurrence. However, directed variants exist that incorporate forward-looking context—edges point from earlier to later text units within the window—to model the sequential nature of language. Directed graphs can better capture discourse structure but introduce sparsity and require careful tuning of the damping factor to maintain convergence guarantees.

06

Advantages Over Supervised Methods

TextRank's primary advantage is its language independence and domain portability. Unlike supervised extractors that require expensive annotated corpora, TextRank operates on raw text alone. It also naturally handles redundancy reduction—the graph-based scoring inherently penalizes duplicate information because vertices that are highly similar to already high-scoring vertices receive diminished marginal contribution, a property analogous to Maximum Marginal Relevance (MMR) without requiring a separate diversity mechanism.

TEXTRANK EXPLAINED

Frequently Asked Questions

Clear, technically precise answers to the most common questions about the graph-based ranking algorithm for keyword and sentence extraction.

TextRank is a graph-based ranking algorithm for natural language processing that identifies the most important sentences or keywords in a document by modeling text as a network of co-occurrence links. It works by building a graph where vertices represent lexical units (words or sentences) and edges represent co-occurrence relationships within a defined window. The algorithm then applies a recursive, PageRank-inspired scoring mechanism where the importance of a vertex is determined by the number and quality of incoming connections. The process iterates until convergence, producing a ranked list of the most salient elements without requiring any prior training data or language-specific resources, making it a fully unsupervised, domain-independent method.

Prasad Kumkar

About the author

Prasad Kumkar

CEO & MD, Inference Systems

Prasad Kumkar is the CEO & MD of Inference Systems and writes about AI systems architecture, LLM infrastructure, model serving, evaluation, and production deployment. Over 5+ years, he has worked across computer vision models, L5 autonomous vehicle systems, and LLM research, with a focus on taking complex AI ideas into real-world engineering systems.

His work and writing cover AI systems, large language models, AI agents, multimodal systems, autonomous systems, inference optimization, RAG, evaluation, and production AI engineering.