Towards Modular Algorithm Induction

Daniel A. Abolafia, Rishabh Singh, Manzil Zaheer, Charles SuttonarXiv 2020

Abstract

Neural algorithm induction—teaching machines to learn programs from input-output examples—remains a significant challenge in artificial intelligence, particularly regarding length generalization. We introduce the Modular Algorithm Induction Network (MAIN), a novel architecture designed to solve algorithmic tasks by composing discrete computational modules. By utilizing a memoryless controller paired with a self-attention-based "history tape," MAIN achieves near-perfect generalization on tasks with input lengths ten times greater than those encountered during training. Our results demonstrate that decoupling control logic from data processing is a key step toward robust neural program induction.

Introduction

A long-standing goal of AI is the ability to learn general-purpose algorithms from data. While models like Neural Turing Machines (NTMs) and Differentiable Neural Computers (DNCs) have made progress by incorporating external memory, they often fail to generalize to longer sequences. For instance, a model might learn to sort a list of five numbers but fail completely on a list of fifty. This failure is often attributed to a lack of modularity; most existing architectures attempt to learn logic and computation simultaneously within a monolithic recurrent structure.

MAIN (Modular Algorithm Induction Network) seeks to bridge this gap by separating the "controller" (which handles logic and pointer management) from the "modules" (which handle the actual data processing). This approach mirrors human programming, where complex problems are solved by combining small, reusable procedures.

Methods

The MAIN architecture (Figure 1) is built around three core components: a variable-length memory tape, a set of pre-defined computational modules, and a memoryless neural controller.

The MAIN architecture: A memoryless controller selects modules and manages tape pointers.

Architecture Components

  1. The Memory: A discrete token tape that stores inputs, intermediate values, and final outputs.
  2. The Modules: A library of fixed functions (e.g., Sum, Max, Increment). At each computational step, the controller selects one module to execute.
  3. The Controller: A non-recurrent neural network that acts as the "brain." Crucially, it does not use an internal hidden state (like an LSTM). Instead, it relies on the external tape and a specialized "History Tape."

Key Innovations

  • History Tape: To navigate the memory tape without internal state, MAIN employs a parallel tape that marks "landmark" symbols, such as the most recently read or written locations. This allows the controller to navigate the tape spatially rather than relying on a fading internal memory.
  • Attention-based Encoding: The controller uses a combination of 1D-CNNs and self-attention to view the tape. Because attention is naturally length-invariant, the model can process a tape of length 100 using the same logic it learned on length 10.
  • Reinforcement Learning: The system is trained end-to-end using Impala, a distributed RL actor-critic algorithm. It learns a policy to pick the right module and the correct tape addresses for arguments and results.

Experimental Setup

The authors evaluated MAIN on five classic algorithmic benchmarks: Copy, Reverse, Increment, Filter Even, and Multi-digit Addition. Models were trained on short sequences (up to length 10) and tested on lengths of 10, 20, and 100 to measure generalization capabilities.

Tape representations for Copy and Multi-digit Addition tasks.

Results and Discussion

MAIN demonstrated superior generalization compared to previous state-of-the-art models across all tasks.

Near-Perfect Generalization

For the Copy, Reverse, Increment, and Filter Even tasks, MAIN achieved 100% accuracy on test cases with length 100, despite only seeing length 10 during training. This 10x scale-up is a significant improvement over traditional recurrent architectures.

Solving Multi-digit Addition

The Multi-digit Addition task is notoriously difficult for reinforcement learning due to the complex "carry" logic required. While only a fraction of training runs reached perfect convergence, those that did were able to generalize perfectly to length 100. This proves the architecture is capable of learning complex, iterative logic when the search space is appropriately modularized.

The Importance of Spatial History

Ablation studies highlighted the necessity of the "History Tape." Removing this component caused the model to fail completely (0% accuracy), proving that providing the model with its own action history is vital for iterative algorithms. By offloading "state" to the history tape, the model avoids the vanishing gradient and "forgetting" issues common in LSTMs as sequences grow longer.

Conclusion

MAIN demonstrates that a modular approach to algorithm induction, combined with externalized history and attention-based encoding, can overcome the length generalization barriers of previous models. Future work will explore learning the modules themselves from scratch and making the halting decision a part of the learned policy to remove the need for an external halting oracle.

Summary updated

BibTeX
@misc{abolafia2020towards,
  author = {Daniel A. Abolafia and Rishabh Singh and Manzil Zaheer and Charles Sutton},
  title = {{Towards Modular Algorithm Induction}},
  year = {2020},
  eprint = {2003.04227},
  archivePrefix = {arXiv},
  url = {https://arxiv.org/abs/2003.04227},
}
Figure