Abstract
The objective of unsupervised graph representation learning (GRL) is to learn a low-dimensional space of node embeddings that reflect the structure of a given unlabeled graph. Existing algorithms for this task rely on negative sampling objectives that maximize the similarity in node embeddings at nearby nodes (referred to as "cohesion") by maintaining positive and negative corpus of node pairs. While positive samples are drawn from node pairs that co-occur in short random walks, conventional approaches construct negative corpus by uniformly sampling random pairs, thus ignoring valuable information about structural dissimilarity among distant node pairs (referred to as "separation"). In this paper, we present a novel Distance-aware Negative Sampling (DNS) which maximizes the separation of distant node-pairs while maximizing cohesion at nearby node-pairs by setting the negative sampling probability proportional to the pair-wise shortest distances. Our approach can be used in conjunction with any GRL algorithm and we demonstrate the efficacy of our approach over baseline negative sampling methods over downstream node classification tasks on a number of benchmark datasets and GRL algorithms.
Introduction
Unsupervised Graph Representation Learning (GRL) aims to map nodes into a low-dimensional vector space while preserving the graph's inherent structural properties. Most modern GRL frameworks, such as DeepWalk or Node2Vec, utilize a negative sampling strategy. They define "positive" node pairs based on proximity (e.g., co-occurrence in short random walks) and "negative" node pairs to contrast against.
A critical limitation of current methods is their reliance on uniform negative sampling (UNS). By picking negative samples uniformly at random, these algorithms prioritize cohesion—ensuring nearby nodes have similar embeddings—but often neglect separation. Without explicitly pushing distant nodes apart in the embedding space, the resulting representations can become cluttered, failing to capture the global topology of the network.
Distance-aware Negative Sampling (DNS)
To address the separation gap, we propose Distance-aware Negative Sampling (DNS). The core intuition is simple: the probability of selecting a node $k$ as a negative sample for a source node $i$ should be proportional to their shortest-path distance $d(k, i)$ in the graph:
$$P_{neg}(k|i) \propto d(k, i)$$
This strategy ensures that nodes structurally far apart in the graph are more likely to be pushed far apart in the embedding space. We define "Separation Power" as a metric to quantify this effect. Mathematically, we demonstrate that while standard UNS has a separation power of 1, DNS achieves a separation power equal to the maximum distance in the graph ($d_{max}$), significantly enhancing the structural resolution of the embeddings.
Scalability and Heuristics
Calculating all-pairs shortest paths is computationally prohibitive for large-scale graphs ($O(n^2)$ space complexity). To make DNS practical, we developed DNS-approx and DNS-scalable. These variants utilize "landmark" nodes—typically high-degree "popular" nodes—to approximate distances.
By leveraging these landmarks, we can estimate distances with significantly reduced memory and time requirements. For instance, on the PubMed dataset, the scalable heuristic reduced the model size from 1.5 GB to just 66 MB without sacrificing classification performance.
Experimental Evaluation
We evaluated DNS across several benchmark datasets, including citation networks (CiteSeer, Cora, PubMed) and biological networks (PPI), as well as synthetic graphs of varying densities.
Key Results
- Performance Gains: DNS-enhanced models consistently outperformed their UNS counterparts. On CiteSeer, DeepWalk-DNS achieved an F1-macro score of 0.61, a substantial improvement over standard DeepWalk-UNS (0.51) and Graph Autoencoders (0.40).
- Sparsity Advantage: DNS is particularly effective on sparse graphs, where the distribution of shortest-path distances is broader, providing more informative signals for the distance-aware sampler.
- Visual Separation: Qualitative analysis via t-SNE visualizations confirmed that DNS produces tighter, more distinct clusters corresponding to node classes, whereas uniform sampling often results in overlapping "blobs" that obscure class boundaries.
Conclusion
Cohesion alone is insufficient for high-quality graph representations. By incorporating structural distance into the negative sampling process, DNS achieves superior separation, leading to more robust and discriminative embeddings. Our approach is algorithm-agnostic and scales effectively to large networks through landmark-based heuristics. Future work will explore the application of distance-aware sampling to dynamic graphs and disconnected components.
Summary updated