Skip to content

Conversation

@tommyly201
Copy link
Contributor

@tommyly201 tommyly201 commented Mar 9, 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

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 just get CI green (the precommit needs fix from you, the other one isnt related to you so hopefully it just goes away when you fix the precommit one)

@tommyly201
Copy link
Contributor Author

Thank you, Rishi

It passed the precommit now! looking forward to seeing this in the repo 😄 . so excited for this!

@puririshi98
Copy link
Contributor

need fix for https://github.com/pyg-team/pytorch_geometric/actions/runs/14187814330/job/39794651601?pr=10105:
Warning, treated as error:
/home/runner/work/pytorch_geometric/pytorch_geometric/torch_geometric/nn/models/attract_repel.py:docstring of torch_geometric.nn.models.attract_repel.ARLinkPredictor:16:Field list ends without a blank line; unexpected unindent.

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, the CI failure remaining does not seem related, hopefully gets fixed soon

@puririshi98 puririshi98 enabled auto-merge (squash) April 1, 2025 21:27
@puririshi98
Copy link
Contributor

@tommyly201 just keep updating the branch as updates come to master and it should merge itself once its green, then ill merge the example PR

auto-merge was automatically disabled April 3, 2025 22:04

Invalid email address

@puririshi98 puririshi98 merged commit 81d562e into pyg-team:master Apr 3, 2025
16 checks passed
puririshi98 added a commit that referenced this pull request Apr 3, 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.

---------

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
# 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