CS58700: Foundations of Deep Learning¶

Spring 2026¶

Copyright: Bruno Ribeiro¶

Contributors: Balasubramaniam Srinivasan and Beatrice Bevilacqua¶

Graph Representation Learning: Positional vs Structural Representations¶

Two Graph Representation Perspectives¶

When we look at nodes in a graph, there are fundamentally two ways to see them: by their position in the graph, or by their structural role. This distinction is at the heart of our discussion today.

(Recap) Node Isomorphism¶

Definition: Two nodes $u, v \in V$ are isomorphic (denoted $ u \simeq v $) if they occupy symmetric positions in the graph.

Formally, $u, v \in V$, $u \neq v$, are isomorphic if there exists a permutation $\pi \in \mathbb{S}_n$ that's not the identity, such that $\pi \circ \mathbf{A} = \mathbf{A}$ and $\pi(u) = v$, $\pi(v) = u$.

Consider this simple example from (Zhang et al., 2021)

No description has been provided for this image

Here, $v_1 \simeq v_4$ and $v_2 \simeq v_3$. That is, swapping these pairs and the graph would remain unchanged.

This symmetry creates a fundamental challenge for learning on graphs.

  • If node ids are arbitrary, then isomorphic nodes are indistinguishable.

Challenges of Using Positional Node Representations¶

Permutation Sensitivity and Inductive Learning¶

  • Since positional node representations break graph symmetries, they are permutation-sensitive
  • This permutation sensitivity is a problem for inductive learning, where training and test graphs may have different node permutations
  • For example, a model trained on one ordering of nodes might fail when applied to the same graph with nodes reordered
  • This creates a fundamental challenge: positional information is valuable, but its sensitivity to arbitrary node labeling is problematic

Sign and Basis Invariant Neural Networks¶

There are solutions to address the challenges of eigenvector sign and basis sensitivity, Sign and Basis Invariant Networks (SBINs) by Lim et al. (2022) as to create:

  1. Invariant Representations: Design neural network architectures that are invariant to sign flips and basis rotations in the eigenvectors.
  2. Equivariant Message Passing: Implement message passing operations that respect these invariances.
  3. Absolute Value and Squared Features: Using transformations of eigenvectors that are naturally invariant to sign, such as absolute values or squared features.
  • But a significant challenge remains: generalizing between different graphs

  • Positional embeddings are specific to the topology of each graph.

  • The "meaning" of a particular position in one graph may not translate well to another graph.

  • This makes inductive and transfer learning tasks particularly challenging.

  • For example, the second eigenvector of a line graph is very different than the second eigenvector of a star graph, making it difficult to transfer knowledge between these structures.

    • On the other hand, A GNN could learn parameters to create similar node representation for line and star graphs if the predictions need to be the same.

Probability Distributions: The Hidden Connection Between Structure and Position¶

  • Let's look at positional node representations from a probabilistic perspective.
  • This view will illuminate the relationship between positional and structural representations in a way that's both elegant and practical.

From Joint to Marginal: The Probabilistic View¶

Here's a perspective that changed how I think about graph embeddings

  • Imagine we're playing with a graph whose node IDs have been thoroughly shuffled.

  • Consider that any adjacency matrix $\mathbf{A}$ we observe is actually the result of shuffling a "canonical" adjacency matrix $\mathbf{A}'$. Mathematically, $\mathbf{A} = \pi \circ \mathbf{A}'$, where $\pi \sim \text{Unif}(\mathbb{S}_n)$ is a uniformly random permutation from the symmetric group.

A positional node representation is a function of a specific permutation arrangement

  • Positional node representations are samples from a joint probability distribution $p(\mathbf{Z}_1, \dots, \mathbf{Z}_n | \mathbf{A}')$, where $\mathbf{Z}_i$ represents the positional representation of node $i$.
    • These representations are random because $\pi \sim \text{Unif}(\mathbb{S}_n)$ is random.

Connection between Positional and Structural Node Representations¶

Now, let's consider the marginal distribution for a single node: $$ p(\mathbf{Z}_v | \mathbf{A}) = \int_{\mathbb{R}^{d}} \cdots \int_{\mathbb{R}^{d}} p(\mathbf{Z}_1, \dots, \mathbf{Z}_n | \mathbf{A}) \, d\mathbf{Z}_{\{1,\dots,n\} \setminus \{v\}} $$ This integral might look intimidating, but it's simply asking: "What's the distribution of all positional representations of node $v$ in isolation?"

This is where the magic happens. For isomorphic nodes $u \simeq v$, we can prove that (Srinivasan & Ribeiro, 2020): $$p(\mathbf{Z}_u|\mathbf{A}) = p(\mathbf{Z}_v|\mathbf{A})$$

  • In other words, isomorphic nodes have identical marginal distributions.
    • That is, the marginal distribution is permutation-invariant.
  • These marginal distributions characterize what we call structural node representations.
  • Actually, a structural node representation can be seen as sufficient information (sufficient statistics) for sampling from this distribution.
    • Analogous to how the (mean, variance) vector $(\mu,\rho)$ characterizes a Normal distribution.

A Concrete Analogy: The Bivariate Normal¶

To understand the limitations of marginal distributions, consider a bivariate normal:

$$(X_1, X_2) \sim \mathcal{N}\left(\boldsymbol{\mu}, \begin{bmatrix} 1 & \rho \\ \rho & 1 \end{bmatrix}\right)$$

The marginals are simply $X_1 \sim \mathcal{N}(\mu_1, 1)$ and $X_2 \sim \mathcal{N}(\mu_2, 1)$.

  • But if you observe only samples from the marginals, you cannot estimate some joint characteristics from $(X_1,X_2)$ such as the correlation parameter $\rho$. This parameter exists only in the joint ¸distribution.

  • In graph terms, this means structural node representations (parameters of the marginals) cannot capture relational properties that exist only in the joint distribution of node properties, such as predicting if two nodes have and edge.

Link Prediction: The Joint Task Challenge¶

Link prediction is fundamentally a joint task between two nodes, formulated as learning $f(Z_u, Z_v)$ to predict a joint property of nodes $u$ and $v$, where $Z_u, Z_v$ are joint positional representations.

As we saw with our bivariate normal example, marginal distributions are insufficient for joint tasks.

  • That is, if we sample from the marginals: sample $Z_u$, permute $\mathbf{A}$, and then sample $Z_v$, we may not be able to predict if the edge $(u,v)$ should exist.
  • Then, it also implies that structural representations ($\mathbb{S}_n$-equivariant representations) like standard GNNs have a fundamental limitation in link prediction.

Consider our Arctic food web:

No description has been provided for this image

A standard GNN will assign identical representations to isomorphic nodes like Lynx and Orca.

  • Consequently, for any downstream neural network $f$, $f(\text{GNN}(G)_{\text{Hare}}, \text{GNN}(G)_{\text{Lynx}}) = f(\text{GNN}(G)_{\text{Hare}}, \text{GNN}(G)_{\text{Orca}})$, making it impossible to distinguish between these potential links.

Joint Structural Representations: A Theoretical Solution¶

To address this limitation, we need to think beyond individual nodes.

Definition (Joint structural representations): Joint structural node set representations of an $n\times n$ adjacency matrix ${\bf A}$ (or $n\times n \times k$, $k \geq 2$, adjacency tensor ${\bf A}$) are obtained from a function $f : \mathbb{R}^{n\times n} \to \mathbb{R}^{|P^{\star}(V)| \times d}$, with $P^{\star}(V)$ the power set excluding the empty set, where isomorphic node sets (denoted by $\simeq$) obtain identical representations i.e. $$ s_1 \simeq s_2 \implies (f({\bf A}))_{s1,\cdot} = (f({\bf A}))_{s2,\cdot},$$ where $s_1, s_2 \in \mathcal{P}(V)$ and $(f({\bf A}))_{s_2,\cdot}$ denotes the row of $f({\bf A})$ corresponding to $s_2$.

The representation $f({\bf A})$ is considered most-expressive iff $(f({\bf A}))_{s1,\cdot} = (f({\bf A}))_{s2,\cdot} \implies s_1 \simeq s_2.$

Example of a 3-node representation
No description has been provided for this image

Theorem (Srinivasan & Ribeiro, 2020) (informal): For a graph $G$, given a sequence of node sets $\vec{S}=(s_1,\ldots,s_n),\;s_i \in P^{\star}(V)$ and their associated random variables as a sequence $\vec{Y}=(y_1,\ldots,y_n)$, if for all pairs of isomorphic node sets $s_i, s_j$ in $\vec{S}$, their corresponding random variables $y_i, y_j$ are equal in distribution (i.e. $y_i \stackrel{d}{=} y_j)$, then there exists a function $g$ and most expressive joint structural representation $f$ s.t. $$g((f({\bf A}))_{si,\cdot},\epsilon) \stackrel{\text{a.s.}}{=} y_i,$$ where $\epsilon$ is a pure source of random noise .

Corollary (Srinivasan & Ribeiro, 2020) (informal): While most expressive structural node representations independently are not sufficient to perform link prediction, the most expressive joint structural representations (of a pair of nodes) are sufficient.

Breaking Symmetry: A Practical Solution for Joint Node Representations¶

  • While joint structural representations provide a theoretical solution, implementing them directly can be computationally challenging.
  • Instead, we can use a simple but powerful technique: symmetry breaking.

A Symmetry Group Perspective¶

  • To break the symmetries of a permutation-equivariant representation like a GNN, we have seen that we can augment nodes with unique identifiers $u_i \in \mathbb{R}^d$, ensuring $u_i \neq u_j$ for all $i \neq j$.

  • In what follows we will see how we can use GNN symmetry breaking methods for link prediction.

Practical Symmetry-Breaking Methods for Pairwise Representations¶

1. Labeling Trick (Zhang et al., 2021)¶

  • For link prediction between a source node $s \in V$ and other nodes in the graph, we can transform the problem by marking the source node, giving it a unique node feature:
def create_source_specific_features(x, source_node_idx, feature_dim=1):
    num_nodes = x.shape[0]
    source_feature = torch.zeros((num_nodes, feature_dim))
    
    # Set the source node's indicator to 1
    source_feature[source_node_idx] = 1.0
    
    # Concatenate with original features
    augmented_features = torch.cat([x, source_feature], dim=1)
    
    return augmented_features
No description has been provided for this image

This approach is particularly elegant.

  • By marking node $v$ with a unique feature, information about this source node propagates through the graph during the GNN message passing algorithm.

  • Each node's structural embedding now encodes its relationship to the source node.

  • When we predict the link between nodes $v$ and $u$, we mark $v$ as the source node and examine the GNN representation of $u$.

    • This representation is no longer permutation-equivariant (because of the marking of node $v$) but contains information about the relationship between $u$ and $v$, even if $v$ is isomorphic to other nodes.
    • This approach is equivariant to pairs of nodes: that is, if two pairs of nodes are "isomorphic" to another two pairs, then this procedure will give them the same pairwise representations.
  • This approach is widely used but theoretically incorrect: There is one mistake, can you spot it?

A complete implementation looks like:

class MarkingGNN(nn.Module):
    def __init__(self, input_dim, hidden_dim, output_dim, num_layers=2, mlp_layers=2):
        super().__init__()
        self.input_dim = input_dim
        self.source_indicator_dim = 1
        
        # MLP for processing node features before convolution
        self.feature_mlp = nn.ModuleList()
        self.feature_mlp.append(nn.Linear(input_dim, hidden_dim))
        for _ in range(mlp_layers - 1):
            self.feature_mlp.append(nn.Linear(hidden_dim, hidden_dim))
        
        # GNN layers with source-aware input dimension
        self.convs = nn.ModuleList()
        self.convs.append(GCNConv(hidden_dim + self.source_indicator_dim, hidden_dim))
        
        for _ in range(num_layers - 1):
            self.convs.append(GCNConv(hidden_dim, hidden_dim))
        
        # Link prediction head
        self.link_pred = nn.Linear(hidden_dim, 1)


    def forward(self, x, edge_index, source_node):
        """Forward pass of the Node-Marking GNN model.
        
        Args:
            x (torch.Tensor): Node feature matrix with shape [num_nodes, input_dim]
            edge_index (torch.Tensor): Graph connectivity in COO format with shape [2, num_edges]
            source_node (int): Index of the source node to create specialized features for
            
        Returns:
            torch.Tensor: Node embeddings with shape [num_nodes, hidden_dim]
        """
        # Step 1: Process input features through MLP layers
        h = x
        for i, layer in enumerate(self.feature_mlp):
            h = layer(h)
            if i < len(self.feature_mlp) - 1:  # Apply ReLU to all but last layer
                h = F.relu(h)
        
        # Step 2: Augment processed features with source node indicator
        # This adds a binary feature that marks whether each node is the source node
        x_augmented = create_source_specific_features(h, source_node)
        
        # Step 3: Apply graph convolution layers for message passing
        h = x_augmented
        for conv in self.convs:
            h = conv(h, edge_index)
            h = F.relu(h)  # Non-linear activation after each convolution
        
        # Return the final node embeddings
        return h 
        
    def predict_link(self, x, edge_index, source_node, target_node):
        """Predict the likelihood of a link between source and target nodes.
        
        Args:
            x (torch.Tensor): Node feature matrix with shape [num_nodes, input_dim]
            edge_index (torch.Tensor): Graph connectivity in COO format with shape [2, num_edges]
            source_node (int): Index of the source node in the potential link
            target_node (int): Index of the target node in the potential link
            
        Returns:
            torch.Tensor: Probability for the existence of a link between source and target nodes
        """
        # Step 1: Obtain node embeddings from the GNN with awareness of the source node
        # This gives us contextualized representations of all nodes in the graph
        node_embeddings = self.forward(x, edge_index, source_node)
        
        # Step 2: Extract the target node's embedding and compute link score
        # We only need the representation of the target node for prediction
        link_score = self.link_pred(node_embeddings[target_node])
        
        # Step 3: Apply sigmoid activation to get a probability in range [0,1]
        return torch.sigmoid(link_score)
    

To train this model for link prediction:

def train_target_aware_link_prediction(model, graph, train_edges, labels):
    optimizer = torch.optim.Adam(model.parameters(), lr=0.01)
    criterion = nn.BCELoss()
    
    for epoch in range(100):
        model.train()
        optimizer.zero_grad()
        
        total_loss = 0
        for (u, v), label in zip(train_edges, labels):
            # For each edge, mark source u and predict if node v forms an edge with u.
            pred = model.predict_link(graph.x, graph.edge_index, u, v)
            loss = criterion(pred, label)
            total_loss += loss
        
        total_loss.backward()
        optimizer.step()
  • This approach elegantly solves the link prediction problem using GNNs.
  • When we predict the link (Hare, Lynx), we mark Lynx and examine Hare's embedding.
  • For (Hare, Orca), we mark Orca and examine Hare's embedding again.
    • Even though Lynx and Orca might be structurally equivalent, the unique marker at Lynx allow the GNN to learn different representations for Orca and Lynx.

Mathematical Foundation¶

Why do these approaches work? Let us get some deeper intuition:

  1. With standard GNNs, isomorphic nodes $u \simeq v$ will have identical representations: $$\text{GNN}(G)_u = \text{GNN}(G)_v$$

  2. When we add symmetry-breaking features, we transform the node features $X$ to $X'$ such that nodes $u$ and $v$ now have distinct features: $$X'_u \neq X'_v$$

  3. The GNN now processes this augmented graph: $$\text{GNN}(G, X')_u \neq \text{GNN}(G, X')_v$$

  4. For link prediction specifically, marking a source node $s$ creates embeddings that are contextual to that node: $$\text{GNN}(G, X \oplus I_s),$$ where $I_s$ is an indicator for the source node, and $\oplus$ represents feature concatenation.

  5. The message passing process propagates this source information throughout the graph, creating node representations that encode relationships to the source node.

  • This allows us to maintain the power of GNNs for capturing graph structure while adding the ability to create joint representations between two nodes.

Practical Symmetry-Breaking Methods for k-Ary Representations¶

The key insight from our previous discussion is that breaking symmetry through unique node features enables GNNs to capture positional information. We can extend this approach from pairwise to k-ary relationships by using multiple source node markers.

Single-Source Marking (Binary Relationships)¶

For a source node $v$, we create modified node features:

  • For node $v$: Add a "1" indicator (e.g., [original_features , 1])
  • For all other nodes: Add a "0" indicator (e.g., [original_features , 0])

Then we run a standard GNN on this modified graph. The unique marker on $v$ propagates information through message passing, creating embeddings that encode each node's relationship to $v$.

  • This approach is widely used but does not theoretically guarantee equivariance: There is one mistake, can you spot it?

Dual-Source Marking (Ternary Relationships)¶

For source nodes $v$ and $i$, we create modified node features:

  • For node $v$: Add a "1,0" indicator (e.g., [original_features | 1 | 0])
  • For node $i$: Add a "0,1" indicator (e.g., [original_features | 0 | 1])
  • For all other nodes: Add a "0,0" indicator (e.g., [original_features | 0 | 0])

Then we run a standard GNN on this modified graph. The unique markers on $v$ and $i$ propagate information through message passing, creating embeddings that encode each node's relationship to both $v$ and $i$.

This allows us to answer queries like "Given source nodes $v$ and $i$, which node $j$ is likely to form a triangle with them?"

  • This approach is widely used but does not theoretically guarantee equivariance: There is one mistake, can you spot it?

Multi-Source Marking (k-Ary Relationships)¶

For $k-1$ source nodes $\{v_1, v_2, ..., v_{k-1}\}$, we create modified node features:

  • For node $v_1$: Add a "1,0,0,...,0" indicator
  • For node $v_2$: Add a "0,1,0,...,0" indicator
  • ...
  • For node $v_{k-1}$: Add a "0,0,0,...,1" indicator
  • For all other nodes: Add a "0,0,0,...,0" indicator
  • Then we run a standard GNN on this modified graph. The unique markers propagate through message passing, creating embeddings that encode each node's relationship to all $k-1$ source nodes.

  • This approach enables the GNN to predict complex relationships like "Given source nodes $v_1, v_2, ..., v_{k-1}$, which node $v_k$ is likely to form a k-clique with them?" or "Which node would complete this particular subgraph pattern?"

  • This approach does not theoretically guarantee equivariance: There is one mistake, can you spot it?

Implementation Example¶

def kary_symmetry_breaking(graph, source_nodes, gnn_model):
    """
    Apply symmetry breaking for k-ary relationship prediction
    
    Args:
        graph: Input graph
        source_nodes: List of source nodes to mark with unique features
        gnn_model: GNN model to use
    """
    n = graph.number_of_nodes()
    k = len(source_nodes) + 1  # +1 for the node we'll predict
    
    # Create marker matrix for source nodes
    markers = np.zeros((n, len(source_nodes)))
    
    # Set markers for each source node (one-hot encoding)
    for i, node_idx in enumerate(source_nodes):
        markers[node_idx, i] = 1.0
    
    # Augment node features with markers
    augmented_features = np.concatenate([graph.x, markers], axis=1)
    
    # Create augmented graph
    marked_graph = copy.deepcopy(graph)
    marked_graph.x = augmented_features
    
    # Run GNN on augmented graph
    node_embeddings = gnn_model(marked_graph)
    
    return node_embeddings

Why This Approach Works¶

By marking $k-1$ source nodes with unique features, we:

  1. Break Structural Equivalence: Even if nodes are structurally equivalent in the original graph, the markers differentiate them.

  2. Create Relative Positional Context: Each node's embedding encodes its position relative to the marked source nodes.

  3. Enable k-Ary Relationship Prediction: The embeddings capture how each node relates to the entire set of source nodes as a group.

  4. Transform Global Problems to Local: Complex k-ary relationship prediction is transformed into a simpler node scoring problem.

  • E.g.: in a molecule, marking two source atoms allows the GNN to predict which third atom is likely to form a specific bond angle or dihedral relationship with them, even if the atoms are of the same type and would normally have identical structural embeddings.

Applications to Specific k-Ary Problems¶

Triangular Relationship Prediction

For predicting triangles in social networks:

  1. Mark two users as sources with unique features.
  2. Run a GNN to create embeddings that capture relationships to both sources.
  3. For each remaining user, predict their likelihood of completing a triangle with the two sources

Knowledge Graph Completion

For predicting missing entities in (source, relation, target) triples:

  1. Mark the source with an unique feature.
  2. Run an edge-type GNN to create embeddings that capture relationships to both.
  3. Predict which entity is most likely to be the target in this relationship.

Enzyme-Substrate-Cofactor Prediction

For predicting biochemical interactions:

  1. Mark an enzyme and substrate as sources with unique features.
  2. Run a GNN to create embeddings that capture relationships to both sources.
  3. Predict which molecule is most likely to act as a cofactor in the reaction.

The symmetry-breaking approach provides a simple, flexible, and computationally efficient way to model complex k-ary relationships in graphs, extending the power of standard GNNs beyond their traditional structural limitations.

Conclusion: Symmetry Breaking on Graphs Allows GNNs to Perform Distinct Tasks¶

  • Each task order (node, link prediction, triangle prediction) has its own required symmetry.

    • How to create a GNN that can learn over multiple order tasks?
  • Structural representations are all you need: Individual node representations are insufficient for link prediction because of symmetries.

    • Joint structural representations provide the theoretical solution, but symmetry-breaking techniques offer a practical implementation.
  • This solution enjoys the computational advantages of GNNs while endowing them with the expressiveness needed for tasks like link prediction and higher order ($k$-ary) tasks, $k \geq 3$.

  • By understanding the connection between positional representations as samples from a joint distribution and symmetry-breaking as a way to access this joint distribution, we can develop more powerful graph learning models that combine the best of both worlds (structural and positional).

  • Remember: when in doubt, break symmetry with a well-placed random feature or a source indicator. Sometimes, a little bit of uniqueness is all you need to unlock the full potential of graph neural networks.

References¶

  1. Srinivasan, B., & Ribeiro, B. (2020). On the Equivalence Between Positional Node Embeddings and Structural Graph Representations.

  2. Zhang, M., Li, P., Xia, Y., Wang, K. and Jin, L., 2021. Labeling trick: A theory of using graph neural networks for multi-node representation learning. Advances in Neural Information Processing Systems.

  3. Xu, K., Hu, W., Leskovec, J., & Jegelka, S. (2019). How Powerful are Graph Neural Networks?

  4. Lim, D., Robinson, J., Zhao, L., Smidt, T., Sra, S., Maron, H. and Jegelka, S., 2022. Sign and basis invariant networks for spectral graph representation learning. arXiv preprint arXiv:2202.13013.