Graph embedding

Also known as: whole-graph embedding

On this page 8

A graph embedding, also called a whole-graph embedding, is a fixed-length vector that represents an entire graph, so that structurally or functionally similar graphs lie close together in the vector space. In graph learning, a branch of artificial intelligence, it turns objects of varying size and shape, such as molecules, social communities or program call graphs, into inputs that standard classifiers, regressors and similarity search systems can handle.

The term is sometimes used loosely for node embeddings as well. In the strict sense used here, a node embedding assigns one vector to each node, while a graph embedding assigns one vector to the whole graph, usually by summarizing node-level information through a readout step.

How a whole-graph embedding is produced

Most modern graph embeddings follow a two-stage pipeline: first compute node representations, then aggregate them into one vector. Both stages must respect the fact that a graph has no natural node ordering, so the final vector must be invariant to permutations of the node labels.

In the first stage, a message passing neural network such as a graph convolutional network or a graph isomorphism network updates each node vector by aggregating features from its neighbors over several layers. After k layers, each node vector summarizes its k-hop neighborhood. In the second stage, a readout function combines all node vectors, for example by summing them, into the graph-level embedding.

Older approaches skip neural networks altogether. Graph kernels count substructures such as subtrees, walks or small subgraphs, while unsupervised methods such as graph2vec treat rooted subgraphs as words and learn document-style embeddings. Spectral approaches derive a signature from the eigenvalues of the graph Laplacian.

Families of graph embedding methods

Graph embedding methods differ in whether they learn from labels, how they capture structure and how well they scale. The table below groups the main families used in research and industry.

FamilyCore ideaSupervisionTypical example
Graph kernelsCount shared substructures between graphsNone, used with SVMsWeisfeiler-Lehman subtree kernel
Substructure skip-gramLearn vectors from rooted subgraph co-occurrenceUnsupervisedgraph2vec
Spectral signaturesSummarize Laplacian eigenvalues or heat tracesUnsupervisedNetLSD
GNN with readoutMessage passing then poolingSupervised or self-supervisedGIN with sum readout
Contrastive GNNPull augmented views of a graph togetherSelf-supervisedGraphCL, InfoGraph
Main families of whole-graph embedding methods

Kernels remain strong baselines on small benchmark datasets, but they scale quadratically with the number of graphs because each pair must be compared. Neural methods produce explicit vectors, which allows approximate nearest-neighbor search over millions of graphs.

Readout and graph pooling choices

The readout function largely determines what information survives in the final vector. Simple permutation-invariant operators are fast and stable, while learned pooling methods can capture hierarchical structure at a higher computational cost.

ReadoutWhat it preservesWeakness
Sum poolingCounts and multiset structureMagnitude grows with graph size
Mean poolingFeature distributionCannot distinguish graph size
Max poolingMost salient featuresDiscards frequency information
Attention poolingWeighted importance of nodesAdds parameters and variance
Hierarchical poolingCluster and motif structureHigher memory, harder to train
Common readout functions and their trade-offs

Theory gives a clear guideline: with injective neighborhood aggregation, sum readout is the most expressive of the simple options, because mean and max can map different multisets of node vectors to the same result. Practitioners often concatenate readouts from every layer to keep both local and wider-range information.

Expressive power and its limits

Standard message passing networks are at most as powerful as the 1-dimensional Weisfeiler-Lehman test at telling non-isomorphic graphs apart. As a result, some structurally different graphs, such as two disjoint triangles and a single six-node cycle, receive identical embeddings when node features are uniform.

Several remedies raise expressiveness: higher-order networks based on k-WL, subgraph-based models, random or structural node features, and positional encodings derived from Laplacian eigenvectors, as used in graph transformers. Each adds computation, and some sacrifice exact permutation invariance unless handled carefully.

Depth brings its own problems. Too many layers cause over-smoothing, where node vectors converge and the graph embedding loses detail, and over-squashing, where information from distant nodes is compressed through narrow bottlenecks.

Graph embedding is often confused with neighboring representation types in graph representation learning. The distinction depends on what the vector describes and which task it serves.

RepresentationUnit embeddedTypical downstream task
Graph embeddingEntire graphGraph classification, similarity search
Node embeddingSingle nodeNode classification, link prediction
Knowledge graph embeddingEntities and relation typesTriple completion with TransE or RotatE
Subgraph embeddingSelected node subsetCommunity or motif analysis
Graph embedding and neighboring concepts

The boundaries are not rigid. A graph embedding can be derived from node embeddings by pooling, and a node embedding can be enriched with a virtual node that stores a graph-level summary during message passing. What matters is the unit the final vector describes, because evaluation metrics, data splits and leakage risks all follow from that choice.

Practical guidance and common mistakes

A reliable workflow starts with a Weisfeiler-Lehman kernel baseline and a GIN with sum readout, then adds complexity only when validation results justify it. Small graph classification benchmarks show high variance across random splits, so results should be reported over repeated folds.

  • Ignoring edge and node features, which often carry more signal than topology alone.
  • Choosing mean readout by default when graph size itself is predictive.
  • Leaking near-duplicate graphs across train and test splits, common with molecular scaffolds.
  • Comparing embeddings from different models as if they shared one vector space.
  • Stacking many layers on small graphs, which triggers over-smoothing.

For retrieval systems, embedding dimensions between 64 and 512 are typical, and vectors are often L2-normalized so that cosine similarity reflects structural closeness rather than graph size. Any model update requires re-embedding the whole collection, since vectors from different checkpoints are not comparable.

In everyday language

Many things are networks: a molecule is atoms joined by bonds, and a friend group is people joined by friendships. Computers struggle to compare networks directly, because they come in all shapes and sizes.

A graph embedding solves this by turning each whole network into a short list of numbers. Networks that look or behave alike get similar lists. Think of it as a fingerprint for a network. Once every network has a fingerprint, finding similar ones becomes a quick comparison of numbers.

Seen in the real world

A pharmaceutical research team screens about two million candidate molecules for possible toxicity. Each molecule is represented as a graph with atoms as nodes and bonds as edges, with features such as element type, charge and bond order.

The team pretrains a graph isomorphism network with contrastive self-supervision on the full library, then fine-tunes it on roughly 8,000 molecules with known toxicity labels. A sum readout over all layers produces a 300-dimensional graph embedding for every molecule, which feeds a small classifier and an approximate nearest-neighbor index.

When chemists flag a promising compound, the index returns its closest structural neighbors in milliseconds, and the classifier ranks them by predicted risk. Compared with the previous fingerprint-based screening, the team prioritizes a shortlist of a few hundred molecules for laboratory testing and finds toxic candidates earlier, reducing wasted synthesis work.