Inferensys

Glossary

Link Prediction

Link prediction is the machine learning task of predicting the existence or likelihood of a relationship between two nodes in a graph, commonly used for knowledge base completion and recommender systems.
Knowledge engineer constructing knowledge base on laptop, document hierarchy visible, casual office setup.
GRAPH COMPLETION

What is Link Prediction?

Link prediction is the machine learning task of estimating the likelihood that a relationship exists between two nodes in a graph, used to infer missing edges or forecast future connections.

Link prediction is a core knowledge base completion (KBC) task that computes a probability score for a potential edge between a head and tail entity. It leverages the graph's existing topology and relation embeddings—such as those generated by TransE or graph neural networks (GNNs)—to determine if a missing or hypothetical triple represents a valid fact.

The task is fundamental to knowledge graph population and recommender systems. By framing the problem as a scoring function over semantic triples, models can rank candidate relationships for triple classification. Advanced approaches use contrastive representation learning to ensure that valid connections receive higher scores than corrupted ones, enabling the discovery of latent relationships.

Graph Learning Fundamentals

Key Characteristics of Link Prediction

Link prediction is the machine learning task of inferring the likelihood of a missing or future connection between two nodes in a graph. It is the core mechanism behind recommendation engines, knowledge base completion, and drug discovery.

01

Heuristic Scoring Methods

Classic approaches compute a similarity score between node pairs based on graph topology without learning. These methods serve as strong baselines.

  • Common Neighbors: Counts shared neighbors between two nodes. A higher count suggests a higher probability of connection.
  • Jaccard Coefficient: Normalizes common neighbors by the total number of unique neighbors, penalizing nodes with high degrees.
  • Adamic-Adar Index: Weighs common neighbors inversely by their degree, giving more importance to rare shared connections.
  • Preferential Attachment: Multiplies the degrees of the two nodes, based on the principle that popular nodes tend to connect to other popular nodes.
02

Knowledge Graph Embeddings

These models learn low-dimensional vector representations for entities and relations to score triples. They frame link prediction as a translation or tensor factorization problem.

  • TransE: Models a relationship as a translation vector h + r ≈ t in the embedding space. It is highly efficient but struggles with complex relation patterns like symmetry.
  • DistMult: Uses a bilinear diagonal tensor product. It captures symmetric relations well but cannot model asymmetric or inverse relations.
  • ComplEx: Extends DistMult into the complex space, allowing it to model both symmetric and asymmetric relations by using the Hermitian dot product.
  • RotatE: Defines each relation as a rotation in complex vector space, effectively modeling inversion and composition patterns.
03

Graph Neural Network Encoders

Instead of learning shallow embeddings, Graph Neural Networks (GNNs) generate node representations by aggregating information from a node's local neighborhood. This captures structural features that shallow methods miss.

  • Graph Convolutional Networks (GCNs) apply a first-order approximation of spectral convolutions to aggregate neighbor features.
  • GraphSAGE learns a function to sample and aggregate features from a node's local neighborhood, enabling inductive learning on unseen nodes.
  • Graph Attention Networks (GATs) use a self-attention mechanism to assign different weights to different neighbors during aggregation, focusing on the most relevant connections.
  • A standard GNN encoder for link prediction often uses a Siamese architecture to encode the head and tail nodes separately before scoring the pair.
04

Negative Sampling Strategies

Link prediction is often framed as a binary classification task. Since real graphs are sparse, generating high-quality negative samples (non-existent edges) is critical for training.

  • Uniform Random Sampling: Randomly corrupts the head or tail entity of a true triple. This is fast but often generates easy negatives that don't help the model learn.
  • Bernoulli Sampling: Replaces the head or tail entity with a probability based on the relation's mapping property (one-to-many, many-to-one) to reduce false negatives.
  • Adversarial Sampling: Dynamically selects negative samples that the current model scores highly, forcing the model to learn from its hardest mistakes.
  • Self-Adversarial Sampling: Weighs negative samples by their current model score during the loss calculation, avoiding the computational cost of full adversarial generation.
05

Decoder Scoring Functions

After encoding the source and target nodes, a decoder function computes the final likelihood score for the potential edge.

  • Dot Product: Computes the inner product of the two node embeddings. Simple but effective for undirected graphs.
  • DistMult Decoder: A bilinear diagonal product <h, r, t>, where r is a relation-specific diagonal matrix.
  • ConvE: Uses a 2D convolutional layer over reshaped and concatenated embeddings, capturing rich feature interactions.
  • InteractE: Improves upon ConvE by increasing the number of feature permutations and reshapes, capturing more heterogeneous interactions.
06

Evaluation Metrics

The performance of link prediction models is evaluated by ranking a true target entity against all other possible entities in the graph.

  • Mean Reciprocal Rank (MRR): The average of the inverse of the rank assigned to the correct entity. It heavily penalizes low ranks.
  • Hits@K (e.g., Hits@10): The fraction of test triples where the correct entity appears in the top K positions of the ranked list. This is the most common metric for knowledge base completion.
  • Mean Rank (MR): The average rank of the correct entity. A lower value is better, but it is highly sensitive to outliers from a few very bad predictions.
  • Evaluation is performed under a filtered setting, where all other known true triples are removed from the ranking list before calculating the rank to avoid penalizing the model for predicting other valid facts.
TASK COMPARISON

Link Prediction vs. Related Graph Tasks

Distinguishing link prediction from adjacent graph learning and knowledge base completion tasks.

FeatureLink PredictionKnowledge Base CompletionTriple Classification

Primary Objective

Predict probability of an edge existing between two nodes

Infer and add entirely missing facts to an incomplete knowledge graph

Classify a given (h, r, t) triple as true or false

Input Format

Graph structure (nodes, existing edges) and node features

Incomplete knowledge graph with existing triples

A single candidate triple (subject, predicate, object)

Output

Ranked list of likely edges or a probability score

Set of new, high-confidence triples to add to the graph

Binary label (True/False) with confidence score

Typical Models

TransE, RotatE, Graph Neural Networks (GCNs, GATs)

TransE, ComplEx, ConvE, HolE

BERT-based classifiers, KG-BERT, fine-tuned encoders

Training Paradigm

Self-supervised via masking existing edges; negative sampling

Self-supervised via masking existing triples; negative sampling

Supervised binary classification on labeled triples

Evaluation Metric

Mean Reciprocal Rank (MRR), Hits@K

Mean Reciprocal Rank (MRR), Hits@K

Accuracy, F1-Score, Area Under ROC Curve (AUC)

Handles Unseen Entities

Core Use Case

Recommender systems, drug-drug interaction prediction, social network analysis

Automated ontology population, knowledge graph curation

Fact verification, validating extracted relations against a knowledge base

LINK PREDICTION

Frequently Asked Questions

Clear, technical answers to the most common questions about the machine learning task of predicting missing or future relationships in graph-structured data.

Link prediction is the machine learning task of estimating the likelihood that a relationship (an edge) exists or will form between two nodes in a graph. It works by learning a scoring function $f(u, v)$ that quantifies the probability of a link between nodes $u$ and $v$. Heuristic methods compute this score based on local structural properties, such as the number of common neighbors or the Adamic-Adar index. Embedding-based methods, like TransE and RotatE, learn low-dimensional vector representations for each node and relation, defining the score via a geometric operation (e.g., translation distance). Graph Neural Network (GNN) methods, such as GraphSAGE and RGCN, generate node embeddings by aggregating features from multi-hop neighborhoods, capturing complex, non-linear structural patterns. The model is trained on positive edges from the graph and synthetically generated negative samples, optimizing a margin-based ranking loss or binary cross-entropy to rank true edges above false ones.

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.