pygrank: A Python Package for Graph Node Ranking

Emmanouil Krasanakis, Symeon Papadopoulos, Ioannis Kompatsiaris, Andreas SymeonidisarXiv 2021 · arXiv

TL;DR

pygrank is a new open-source Python package designed to bridge the gap between traditional graph signal processing and modern deep learning. It provides a modular, backend-agnostic framework (supporting NumPy, PyTorch, and TensorFlow) to define, optimize, and evaluate node ranking algorithms as interoperable components within machine learning pipelines.

What Problem Does This Paper Address?

Node ranking—the process of scoring nodes based on their structural relationship to neighbors—is a cornerstone of graph analysis, powering everything from recommendation engines to community detection. However, the ecosystem for these algorithms has historically been fragmented.

Researchers often rely on ad-hoc implementations or specialized libraries that don't "talk" to each other. For instance, traditional tools like NetworkX are great for basic analysis but don't support the backpropagation needed for deep learning. Conversely, deep graph learning libraries like DGL or PyTorch Geometric focus heavily on neural architectures but often lack the flexibility to easily swap out or tune traditional graph filters and post-processors. pygrank addresses this by providing a standardized, unit-tested environment where users can perform rigorous ablation studies and integrate ranking algorithms directly into differentiable ML models.

Methods

The core of pygrank is its modular, object-oriented architecture, divided into four main pillars:

  1. pygrank.core: Manages the "plumbing." It allows the library to be backend-agnostic, meaning you can run computations on NumPy for speed on small graphs or delegate them to TensorFlow/PyTorch tensors to stay within a GPU-accelerated pipeline.
  2. pygrank.algorithms: This is the library's engine room. It includes graph filters (like PageRank and HeatKernel), post-processors (for tasks like fairness-aware ranking or "sweep" procedures), and online tuning components.
  3. pygrank.measures: Provides a suite of supervised and unsupervised metrics to evaluate how well the ranking reflects the underlying graph dynamics.
  4. pygrank.benchmarks: Tools to automate experiments across multiple datasets and algorithm variations.

A standout feature is the ParameterTuner, which uses variations of block coordinate descent to automatically find the best hyperparameters (like diffusion rates) for a specific graph, rather than relying on "rule of thumb" defaults.

Datasets

The paper demonstrates the package using several standard benchmarks:

  • EUCore and Amazon: Used to show how different filters (PageRank vs. HeatKernel) perform at recommending community members.
  • Citeseer: Used to demonstrate how pygrank can be integrated into a Graph Neural Network (GNN) architecture (specifically APPNP) to improve classification accuracy.

The package includes helper methods to automatically download and load these datasets, facilitating reproducible research.

Key Insights and Ideas

  • Interoperability is King: The authors emphasize that classes can be combined like LEGO bricks. You can take a standard PageRank filter, wrap it in a fairness-aware post-processor, and then plug that entire stack into a Keras model.
  • Backend Flexibility: One of the most practical insights is the ability to switch backends. The authors note that for certain sparse matrix multiplications, the NumPy backend is actually several times faster than deep learning frameworks, and pygrank allows users to toggle this for specific tuning steps.
  • Differentiable Ranking: By supporting PyTorch and TensorFlow, node ranking is no longer a static pre-processing step. It becomes a layer in a neural network, allowing the "importance" of nodes to be learned during training via backpropagation.

Key Results

  • Feature Completeness: In a comparison with five major libraries (including NetworkX and DGL), pygrank was the only one to support the full suite of ad-hoc filters, general-purpose filters, post-processing, online tuning, and backpropagation.
  • Automated Tuning: In the community recommendation task, the ParameterTuner consistently performed within 2% of the best possible AUC (Area Under Curve) without requiring the user to manually guess the best algorithm parameters.
  • Efficiency: The authors report that the running time for all components scales near-linearly with the number of edges in the graph, making it suitable for large-scale applications.

Limitations and Future Work

While the core algorithms scale linearly, the authors note that certain iterative post-processing steps can introduce multiplicative terms that might slow down execution on extremely dense graphs.

Regarding future work, the project is positioned as a community-driven effort. The authors have already integrated algorithms from several of their own recent publications (covering fairness and unsupervised evaluation) and are encouraging external contributions to expand the library's collection of filters and measures. The package is currently available under the Apache 2.0 license on GitHub.

Summary updated

Abstract

We introduce pygrank, an open source Python package to define, run and evaluate node ranking algorithms. We provide object-oriented and extensively unit-tested algorithm components, such as graph filters, post-processors, measures, benchmarks and online tuning. Computations can be delegated to numpy, tensorflow or pytorch backends and fit in back-propagation pipelines. Classes can be combined to define interoperable complex algorithms. Within the context of this paper we compare the package with related alternatives and demonstrate its flexibility and ease of use with code examples.
BibTeX
@misc{krasanakis2021pygrank,
  author = {Emmanouil Krasanakis and Symeon Papadopoulos and Ioannis Kompatsiaris and Andreas Symeonidis},
  title = {{pygrank: A Python Package for Graph Node Ranking}},
  year = {2021},
  eprint = {2110.09274},
  archivePrefix = {arXiv},
  url = {https://arxiv.org/abs/2110.09274},
}
Figure