Skip to content

Conversation

@tommyly201
Copy link
Contributor

@tommyly201 tommyly201 commented Mar 10, 2025

Attract-Repel Link Prediction Example

This PR adds an example implementation showcasing the attract-repel embeddings (from PR #10105) on link prediction tasks. The example demonstrates how attract-repel embeddings can significantly improve performance on citation networks.

Overview

The example:

  • Compares traditional vs attract-repel embeddings on link prediction
  • Works with standard Planetoid datasets (Cora, CiteSeer, PubMed)
  • Shows performance improvements across different networks
  • Calculates and reports the R-fraction for analysis

Results

Dataset Method Test AUC
Cora Traditional 0.6624
Cora Attract-Repel 0.8945
PubMed Traditional 0.8977
PubMed Attract-Repel 0.9607
CitiSeer Traditional 0.8067
CitiSeer Attract-Repel 0.8206

The attract-repel approach shows consistent improvements across datasets:

  • Cora: +0.2321 AUC (R-fraction: 0.4075)
  • PubMed: +0.0630 AUC (R-fraction: 0.5062)
  • CitiSeer: +0.0139 AUC (R-fraction: 0.4869)

The varying R-fractions indicate that the model adapts to different graph structures, with PubMed using more of the repel component than Cora.

Usage

Traditional approach:
python examples/ar_link_pred.py --dataset Cora

Attract-Repel approach
python examples/ar_link_pred.py --dataset Cora --use_ar

This example complements the attract-repel embeddings implementation in PR #10105.

@tommyly201 tommyly201 requested a review from wsad1 as a code owner March 10, 2025 17:25
Copy link
Contributor

@puririshi98 puririshi98 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

before i review the code,
@tommyly201 if you see where it says link_pred.py in https://github.com/tommyly201/pytorch_geometric/blob/feature/ar-link-pred-example/examples/README.md
please add something below that explaining how you can get better accuracy (share the range of improvement across your benchmarks as an estimate in parenthesis). then link the example and the corresponding paper.

tommyly201 and others added 6 commits March 12, 2025 20:01
Update README.md to include ar_link_pred.py example
Update README.md to include ar_link_pred.py example
For a flexible implementation that can enhance any GNN model with attract-repel capabilities, see [`attract_repel_wrapper.py`](./attract_repel_wrapper.py).
Copy link
Contributor

@puririshi98 puririshi98 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

otherwise LGTM i can merge once we get #10105 (review) merged

@puririshi98
Copy link
Contributor

LGTM, will approve and merge once we get #10105 in

puririshi98 added a commit that referenced this pull request Apr 3, 2025
# Add Attract-Repel Embeddings for Link Prediction

This PR adds an implementation of Attract-Repel embeddings from the
paper "Pseudo-Euclidean Attract-Repel Embeddings for Undirected Graphs"
by Peysakhovich et al.

## Overview
Attract-Repel embeddings address a fundamental limitation in traditional
graph embeddings: their inability to effectively represent
non-transitive relationships. The method splits node representations
into two components:
- Attract component: nodes with similar attract vectors are likely to
connect
- Repel component: nodes with similar repel vectors are unlikely to
connect

Link prediction scores are calculated as: attract_dot_product -
repel_dot_product

## Implementation
- Added `ARLinkPredictor` class that implements the core functionality
- Added thorough tests to validate the implementation
- The implementation is minimal and focused on the core concept

## Benefits
- Improves link prediction performance on graphs with non-transitive
relationships
- Requires minimal architectural changes to existing models
- Provides useful information about graph structure through R-fraction
analysis
- Example PR [#10107
](#10107)

---------

Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
Co-authored-by: Rishi Puri <[email protected]>
Co-authored-by: Rishi Puri <[email protected]>
Copy link
Contributor

@puririshi98 puririshi98 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

@puririshi98 puririshi98 merged commit b89c37a into pyg-team:master Apr 3, 2025
16 checks passed
chrisn-pik pushed a commit to chrisn-pik/pytorch_geometric that referenced this pull request Jun 30, 2025
# Add Attract-Repel Embeddings for Link Prediction

This PR adds an implementation of Attract-Repel embeddings from the
paper "Pseudo-Euclidean Attract-Repel Embeddings for Undirected Graphs"
by Peysakhovich et al.

## Overview
Attract-Repel embeddings address a fundamental limitation in traditional
graph embeddings: their inability to effectively represent
non-transitive relationships. The method splits node representations
into two components:
- Attract component: nodes with similar attract vectors are likely to
connect
- Repel component: nodes with similar repel vectors are unlikely to
connect

Link prediction scores are calculated as: attract_dot_product -
repel_dot_product

## Implementation
- Added `ARLinkPredictor` class that implements the core functionality
- Added thorough tests to validate the implementation
- The implementation is minimal and focused on the core concept

## Benefits
- Improves link prediction performance on graphs with non-transitive
relationships
- Requires minimal architectural changes to existing models
- Provides useful information about graph structure through R-fraction
analysis
- Example PR [pyg-team#10107
](pyg-team#10107)

---------

Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
Co-authored-by: Rishi Puri <[email protected]>
Co-authored-by: Rishi Puri <[email protected]>
chrisn-pik pushed a commit to chrisn-pik/pytorch_geometric that referenced this pull request Jun 30, 2025
# Attract-Repel Link Prediction Example

This PR adds an example implementation showcasing the attract-repel
embeddings (from PR pyg-team#10105) on link prediction tasks. The example
demonstrates how attract-repel embeddings can significantly improve
performance on citation networks.

## Overview

The example:
- Compares traditional vs attract-repel embeddings on link prediction
- Works with standard Planetoid datasets (Cora, CiteSeer, PubMed)
- Shows performance improvements across different networks
- Calculates and reports the R-fraction for analysis

## Results

| Dataset | Method | Test AUC |
|---------|--------|----------|
| Cora | Traditional | 0.6624 |
| Cora | Attract-Repel | 0.8945 |
| PubMed | Traditional | 0.8977 |
| PubMed | Attract-Repel | 0.9607 |
| CitiSeer | Traditional | 0.8067 |
| CitiSeer | Attract-Repel | 0.8206 |

The attract-repel approach shows consistent improvements across
datasets:
- **Cora**: +0.2321 AUC (R-fraction: 0.4075)
- **PubMed**: +0.0630 AUC (R-fraction: 0.5062)
- **CitiSeer**: +0.0139 AUC (R-fraction: 0.4869)

The varying R-fractions indicate that the model adapts to different
graph structures, with PubMed using more of the repel component than
Cora.

## Usage

Traditional approach:
python examples/ar_link_pred.py --dataset Cora

Attract-Repel approach
python examples/ar_link_pred.py --dataset Cora --use_ar

This example complements the attract-repel embeddings implementation in
PR pyg-team#10105.

---------

Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
Co-authored-by: Rishi Puri <[email protected]>
Co-authored-by: Rishi Puri <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants