Latent Space Representations of Neural Algorithmic Reasoners

Vladimir V. Mirjanić, Razvan Pascanu, Petar Veličković

TL;DR

This paper opens up the "black box" of Neural Algorithmic Reasoners (NARs) by analyzing the latent spaces of Graph Neural Networks (GNNs) trained to execute classical algorithms. The authors identify two critical failure modes—loss of resolution between similar values and poor generalization to out-of-distribution inputs—and introduce two simple, effective remedies: softmax aggregation and processor decay. These modifications yield consistent performance improvements across the standard CLRS-30 algorithmic benchmark.

What Problem Does This Paper Address?

Neural Algorithmic Reasoning (NAR) sits at the intersection of deep learning and classical computer science. The goal is to design neural networks—usually GNNs—that can learn to mimic step-by-step classical algorithms like sorting or shortest-path routing. While NAR models generalize well to new graph structures, they often struggle when encountering values slightly outside their training distribution or when forced to make fine-grained distinctions between highly similar inputs.

Until now, the high-dimensional latent spaces where these GNNs perform their "thinking" have been poorly understood. This paper addresses this gap by analyzing how these latent spaces are structured during algorithm execution, exposing why standard GNN architectures fail, and proposing targeted architectural fixes.

Methods

The authors begin by visualizing the latent space trajectories of a simplified GNN (LinearPGN) and a state-of-the-art model (Triplet-GMPNN) executing the Bellman-Ford shortest-path algorithm. They use Principal Component Analysis (PCA) to map high-dimensional node embeddings into 2D and 3D spaces.

To probe the robustness of the latent space, they test how the network responds to mathematical symmetries inherent to the algorithm:

  • Scaling Symmetry: Multiplying all edge weights by a positive constant $\lambda$.
  • Reweighting Symmetry: Shifting edge weights using a potential function (derived from Johnson’s algorithm) that preserves the shortest-path tree but changes individual edge values.

Based on their diagnostic findings, the authors introduce two modifications to the standard GNN processor pipeline:

  1. Softmax Aggregation: Standard algorithmic GNNs use a hard max operator to aggregate messages from neighboring nodes. The authors replace this with a parameterized softmax aggregator. This allows gradients to flow through multiple paths, preventing the model from prematurely locking into suboptimal choices when competing paths have similar lengths.
  2. Processor Decay: To handle out-of-distribution (OOD) values (e.g., longer paths than seen in training), the authors introduce a step-wise regularization trick that scales down the magnitude of the latent embeddings by a constant factor ($c < 1$) at each execution step.

Datasets

The primary benchmark used for evaluation is CLRS-30, a standard suite consisting of 30 classical algorithms spanning sorting, searching, graphs, and dynamic programming. Crucially, to test out-of-distribution generalization, the models are evaluated on graphs that are four times larger than the ones used during training.

Key Insights and Ideas

  • Low-Dimensional Manifolds: Even though the GNN operates in a 128-dimensional latent space, the learned manifolds are remarkably low-dimensional. In step-wise PCA, the first three principal components capture over 96% of the total variance.
  • Latent Attractors: The execution trajectories of different graphs naturally converge toward a single "attractor state" that signifies the completion of the algorithm.
  • Symmetry Clustering: The latent space implicitly learns algorithmic symmetries. Graphs that are mathematically equivalent under reweighting or scaling naturally cluster together or lie on smooth, low-dimensional curves.
Figure 1: Left: Step-wise PCA visualisation of latent spaces for random graphs. Middle: Step-wise PCA for a set of graphs derived from scaling symmetry. Scaling has one degree of freedom. This is captured in the latent space, as all step embeddings are one-dimensional. Right: Step-wise PCA of 8 classes of random graphs, each containing graphs equivalent under reweighting symmetry. Clusters corresponding to each class of graphs are clearly visible, showing that the model learns to group graphs with same execution close together. Red lines trace graph trajectories. Different colors correspond to different steps in algorithm execution. Sequential view available in Appendix F.
  • The "Premature Correctness" Trap: A misprediction analysis revealed a fascinating quirk: for almost all final incorrect predictions, the GNN had actually settled on the correct intermediate prediction at some point during execution, only to overwrite it with an incorrect value later. This occurs because the hard max aggregator cannot gracefully differentiate between two very close values, causing errors to propagate and reinforce over time.
Figure 3: Left: Similarity between final predictions for our model, true Bellman-Ford, and multiple faulty implementations. Our model is closer to ground truth than to any others. Right: Predictions of the model split on the basis of whether they match ground truth at the end (y-axis), and during execution (x-axis). Almost all mispredicts were correctly predicted at an earlier point.

Key Results

The proposed architectural tweaks were validated on both the standard MPNN and the state-of-the-art Triplet-GMPNN across all 30 CLRS algorithms:

  • Softmax Aggregation (+sft): Proved to be the most advantageous standalone modification, outperforming the baseline on 15 out of 30 algorithms for Triplet-GMPNN.
  • Combined Approach (+sft+dec): Combining softmax aggregation with processor decay beat the baseline on 11 algorithms for Triplet-GMPNN and showed even more dramatic improvements on the standard MPNN (e.g., boosting DAG Shortest Paths accuracy from 81.55% to 92.01%).

Limitations and Future Work

While processor decay helps mitigate out-of-distribution value explosion, the authors note that it is somewhat situational, and more work is required to decouple its benefits from its downsides.

Additionally, the current CLRS-30 setup assumes the model knows the exact number of execution steps required at test time—an unrealistic assumption for real-world deployment. The authors suggest that future work could exploit the latent space's natural convergence to an attractor state as a dynamic, unsupervised termination criterion.

Summary updated

Abstract

Neural Algorithmic Reasoning (NAR) is a research area focused on designing neural architectures that can reliably capture classical computation, usually by learning to execute algorithms. A typical approach is to rely on Graph Neural Network (GNN) architectures, which encode inputs in high-dimensional latent spaces that are repeatedly transformed during the execution of the algorithm. In this work we perform a detailed analysis of the structure of the latent space induced by the GNN when executing algorithms. We identify two possible failure modes: (i) loss of resolution, making it hard to distinguish similar values; (ii) inability to deal with values outside the range observed during training. We propose to solve the first issue by relying on a softmax aggregator, and propose to decay the latent space in order to deal with out-of-range values. We show that these changes lead to improvements on the majority of algorithms in the standard CLRS-30 benchmark when using the state-of-the-art Triplet-GMPNN processor. Our code is available at https://github.com/mirjanic/nar-latent-spaces
BibTeX
@inproceedings{mirjanic2023latent,
  author = {Vladimir V. Mirjanić and Razvan Pascanu and Petar Veličković},
  title = {{Latent Space Representations of Neural Algorithmic Reasoners}},
  booktitle = {LoG},
  year = {2023},
  url = {https://openreview.net/forum?id=tRP0Ydz5nN},
}
Figure