Link Prediction
Relevant source files
The following files were used as context for generating this wiki page:
Link prediction in DGL-LifeSci is a machine learning task aimed at estimating the probability of existence for links (edges) between nodes within a graph. In biological contexts, this often represents predicting interactions, such as protein-protein associations, within complex networks.
The process typically involves using Graph Neural Networks (GNNs) to learn latent node representations, followed by a predictor module that evaluates pairs of these representations to output a likelihood score. Sources: examples/link_prediction/README.md:1-2, examples/link_prediction/ogbl-ppa/README.md:1-5
General Workflow
The GNN-based link prediction pipeline in this repository follows a structured five-step approach:
- Graph Construction: Building biological networks from raw data.
- Feature Preparation: Initializing node and edge feature vectors.
- Representation Learning: Updating node representations using GNN architectures like GCN or GraphSAGE.
- Link Representation: Computing a link-specific representation, often through the Hadamard product of two node vectors.
- Prediction: Passing the link representation through a Multi-Layer Perceptron (MLP) for final classification or regression.
Sources: examples/link_prediction/README.md:4-10
Link Prediction Logic Flow
The following diagram illustrates the data flow from graph input to the final prediction score.
The diagram shows how the model consumes a graph and outputs probabilities for specific node pairs. Sources: examples/link_prediction/README.md:4-10, examples/link_prediction/ogbl-ppa/full_graph_link_predictor.py:22-40
Architectures and Components
GNN Encoders
The project supports various GNN backends for updating node representations before the prediction stage. Common implementations include:
- GCN (Graph Convolutional Networks): Used for semi-supervised learning on graphs.
- GraphSAGE: An inductive representation learning framework suitable for large graphs.
Sources: examples/link_prediction/ogbl-ppa/README.md:8-10, examples/link_prediction/ogbl-ppa/full_graph_link_predictor.py:126-138
Hadamard Link Predictor
The HadamardLinkPredictor is a specific module that performs link prediction by taking the elementwise multiplication (Hadamard product) of two node representations. It consists of multiple linear layers and is symmetric, meaning it does not distinguish between the order of the two nodes in a pair. Sources: python/dgllife/model/model_zoo/hadamard_link_predictor.py:15-20, python/dgllife/model/model_zoo/hadamard_link_predictor.py:73-81
Predictor Parameters
| Parameter | Type | Default | Description |
|---|---|---|---|
in_feats | int | - | Number of input node features. |
hidden_feats | int | 256 | Number of features in hidden layers. |
num_layers | int | 3 | Total number of linear layers (minimum 2). |
n_tasks | int | 1 | Number of output tasks/labels. |
dropout | float | 0.0 | Dropout rate applied between linear layers. |
activation | callable | F.relu | Activation function for hidden layers. |
Sources: python/dgllife/model/model_zoo/hadamard_link_predictor.py:22-38
Class Interaction
The relationship between the GNN model and the Link Predictor is shown in the class diagram below.
This diagram represents the typical decoupling of the node encoder (GNN) and the edge decoder (HadamardLinkPredictor). Sources: examples/link_prediction/ogbl-ppa/full_graph_link_predictor.py:22-30, python/dgllife/model/model_zoo/hadamard_link_predictor.py:15-40
Implementation Details: ogbl-ppa Example
The ogbl-ppa (Open Graph Benchmark Link Property Prediction - Protein-Protein Association) example demonstrates a full-batch link prediction implementation. Sources: examples/link_prediction/ogbl-ppa/full_graph_link_predictor.py:112-115
Training and Loss Calculation
Training involves sampling both positive (existing) and negative (non-existing) edges. The loss is calculated as the sum of binary cross-entropy for positive and negative samples.
- Positive Loss: $-log(sigmoid(predictor(h_u, h_v)))$ for true edges.
- Negative Loss: $-log(1 - sigmoid(predictor(h_i, h_j)))$ for randomly sampled edges.
Sources: examples/link_prediction/ogbl-ppa/full_graph_link_predictor.py:22-44
Training Sequence
The training loop alternates between updating the GNN and the Predictor parameters.
The sequence shows the synchronous update of both the encoder and decoder components during a training iteration. Sources: examples/link_prediction/ogbl-ppa/full_graph_link_predictor.py:22-46
Performance Metrics
Evaluation is primarily performed using hits@K (e.g., hits@100), which measures the ratio of positive edges ranked within the top K against a large set of randomly sampled negative edges. Sources: examples/link_prediction/ogbl-ppa/README.md:38-41, examples/link_prediction/ogbl-ppa/full_graph_link_predictor.py:84-104
Summary
Link prediction in DGL-LifeSci provides a modular framework for biological network analysis. By combining standard GNN encoders (GCN, GraphSAGE) with specialized decoders like the HadamardLinkPredictor, the system can effectively learn and predict associations between entities in large-scale graphs. Sources: examples/link_prediction/README.md, examples/link_prediction/ogbl-ppa/README.md