Skip to main content
QUICK REVIEW

[Paper Review] Neural Execution Engines: Learning to Execute Subroutines

Yujun Yan, Kevin Swersky|arXiv (Cornell University)|Jun 15, 2020
Topic ModelingComputer Science6 references7 citations
TL;DR

This paper proposes Neural Execution Engines (NEEs), a transformer-based architecture that learns to execute algorithmic subroutines like sorting and shortest paths with strong generalization. By introducing a learned conditional masking mechanism and using binary number representations, NEEs achieve near-perfect accuracy on inputs far beyond the training distribution, including longer sequences and unseen data ranges.

ABSTRACT

A significant effort has been made to train neural networks that replicate algorithmic reasoning, but they often fail to learn the abstract concepts underlying these algorithms. This is evidenced by their inability to generalize to data distributions that are outside of their restricted training sets, namely larger inputs and unseen data. We study these generalization issues at the level of numerical subroutines that comprise common algorithms like sorting, shortest paths, and minimum spanning trees. First, we observe that transformer-based sequence-to-sequence models can learn subroutines like sorting a list of numbers, but their performance rapidly degrades as the length of lists grows beyond those found in the training set. We demonstrate that this is due to attention weights that lose fidelity with longer sequences, particularly when the input numbers are numerically similar. To address the issue, we propose a learned conditional masking mechanism, which enables the model to strongly generalize far outside of its training range with near-perfect accuracy on a variety of algorithms. Second, to generalize to unseen data, we show that encoding numbers with a binary representation leads to embeddings with rich structure once trained on downstream tasks like addition or multiplication. This allows the embedding to handle missing data by faithfully interpolating numbers not seen during training.

Motivation & Objective

  • Address the lack of strong generalization in neural networks for algorithmic reasoning, particularly when inputs exceed training distribution ranges.
  • Overcome attention degradation in transformers on long sequences with numerically similar values, which leads to misprediction and error compounding.
  • Enable generalization to unseen data distributions by learning structured, interpolative number embeddings through binary representation.
  • Design a modular framework where a single trained subroutine (e.g., comparison) can be reused across diverse algorithms like Dijkstra’s and Prim’s without retraining.
  • Demonstrate robustness across diverse graph types and input distributions, showing minimal performance drop under distribution shift.

Proposed method

  • Use a sequence-to-sequence transformer to predict both a value and a pointer for each step in a subroutine, enabling dynamic state tracking.
  • Introduce a learned conditional masking mechanism that updates the encoder mask based on predicted pointers, improving attention fidelity on long sequences.
  • Represent numbers in binary form to create hierarchical, exponentially scalable embeddings that support interpolation for unseen values.
  • Train the model on downstream tasks like addition and multiplication to learn structured, interpretable number representations.
  • Decouple the learning of algorithmic logic from data distribution by training on subroutines rather than full algorithms, enabling modular reuse.
  • Apply the same NEE across different algorithms (e.g., Dijkstra’s, Prim’s) using the same learned subroutine, demonstrating transferability without retraining.

Experimental results

Research questions

  • RQ1Can a transformer-based model learn to execute subroutines like sorting and shortest paths with strong generalization beyond its training distribution?
  • RQ2Why do standard transformers fail to generalize to longer sequences or numerically similar inputs, and how can attention fidelity be preserved?
  • RQ3Can binary number representations lead to structured, interpolative embeddings that support generalization to unseen numbers?
  • RQ4To what extent can a single learned subroutine (e.g., comparison) be reused across different algorithms without retraining?
  • RQ5How robust are Neural Execution Engines to distribution shifts in input data, such as different graph types or input ranges?

Key findings

  • NEEs achieve 100.00% accuracy on Dijkstra’s shortest path and Prim’s minimum spanning tree for test graph sizes up to 100, even when training was on size-8 graphs.
  • Performance on graph algorithms remains near-perfect (99.91% for shortest path, 93.00% for MST) even when test graphs differ in type from training graphs, demonstrating robustness to distribution shift.
  • Using binary number representations, the model learns structured, interpretable embeddings that support interpolation—e.g., 65% of numbers held out during training were faithfully interpolated.
  • The learned conditional masking mechanism enables strong generalization: models trained on short sequences (e.g., length 8) generalize accurately to sequences up to 100 elements long.
  • NEEs trained on one subroutine (e.g., comparison) can be directly applied to multiple algorithms (e.g., Dijkstra, Prim) without retraining, showing high modularity and transferability.
  • Binary-embedded models outperform one-hot outputs in parameter efficiency and scalability, while maintaining high performance across all tasks and input ranges.

Read this paper

Open the full text in the Nubint reader and ask about any passage as you read.

Read this paper on Nubint

This review was generated by AI from the original paper. Please check the paper before citing it.