Differentiable Programs with Neural Libraries

Alexander L. Gaunt, Marc Brockschmidt, Nate Kushman, Daniel Tarlow

This paper flips the script on hybrid neural architectures by using a differentiable programming language as a controller that calls neural networks as subroutines, rather than embedding discrete operations inside a monolithic neural network. This framework, called NEURAL TERPRET (NTPT), enables systems to learn interpretable algorithms from weak supervision, completely avoiding catastrophic forgetting in lifelong learning setups and demonstrating extreme generalization on algorithmic tasks.

The Problem: Forgetting and Generalization

Deep learning models excel at perceptual tasks (like image recognition) but struggle with algorithmic reasoning, lifelong learning, and strong generalization. When a standard neural network learns a sequence of tasks, it often suffers from catastrophic forgetting—overwriting the weights that solved task A to solve task B. Furthermore, neural networks struggle to generalize algorithmically; a sequence model trained to add 3-digit numbers usually fails spectacularly on 10-digit numbers.

Previous attempts to solve this, like Neural Turing Machines, added differentiable memory and discrete operations to neural networks. However, the learned "algorithm" remains tangled inside uninterpretable, monolithic network weights, making it hard to transfer specific sub-skills to new tasks. The authors tackle this by flipping the architecture: what if the program is the main controller, and it simply calls neural networks as helper functions?

NEURAL TERPRET (NTPT) Framework

The authors introduce NEURAL TERPRET (NTPT), an extension of the TERPRET differentiable programming language.

  1. Differentiable Interpreter: NTPT allows users to define a template of a program (e.g., registers, loops, conditional statements). The system compiles this source code into a TensorFlow computation graph where discrete variables are relaxed into marginal probability distributions. This allows the system to "search" for the right source code using standard gradient descent.
  2. Neural Libraries: The key novelty is the addition of Tensor data types and learnable neural functions. A program can pass an image (Tensor) to a neural function (e.g., a CNN), which outputs an integer that the program can then use in its logic.
  3. End-to-End Training: The parameters defining the source code and the weights of the neural library are trained jointly from end-to-end using only input-output examples (weak supervision).
NTPT Framework Overview

Perceptual Programming By Example

The authors evaluate their model on a sequence of Perceptual Programming By Example (PPBE) tasks. These require both perception (reading images) and algorithms (math/logic), using only the final answer as supervision:

  • ADD2X2: 2x2 grids of handwritten MNIST digits. Tasks include summing specific rows or columns.
  • APPLY2X2: 2x2 grids of handwritten arithmetic operators (+, -, x, /). Tasks involve applying the operators to auxiliary integers.
  • MATH: A variable-length sequence of handwritten digits and operators representing a mathematical expression to be evaluated.
Perceptual Programming By Example Tasks

Key Insights and Results

Modularity prevents catastrophic forgetting: Because the solution is structured as source code, the supervision is highly focused. If the program's logic dictates that a specific neural function isn't needed for a task, that function is simply not called, and no gradients flow to it. This naturally protects shared neural components from being corrupted by unrelated tasks. In a sequence of 8 tasks (ADD2X2 and APPLY2X2), purely neural baselines like Multitask Neural Networks (MTNN) suffered heavily from catastrophic forgetting when the task distribution shifted. NTPT maintained its knowledge and achieved 86-100% accuracy across all tasks, outperforming MTNNs and Progressive Neural Networks (PNNs).

Reverse Transfer: By sharing a neural library across a lifetime of tasks, training on later tasks actually improves performance on earlier tasks. For example, learning to do math with digits improves the shared digit-recognizer network, retroactively boosting the system's accuracy on earlier addition tasks without revisiting their training data.

Algorithmic Generalization: Source code provides an incredible inductive bias for generalization. Once NTPT learns the correct for loop to evaluate a 2-digit math problem, that exact same loop works perfectly for a 100-digit problem. The only bottleneck becomes the accuracy of the neural perception module. For the MATH task, a 3-layer LSTM baseline trained on 2-digit expressions achieved only 25.0% accuracy when tested on 16-digit expressions. NTPT trained only on 2-digit expressions achieved 87.1% accuracy on 16-digit expressions, proving the power of explicit programmatic control flow.

Limitations and Future Work

The authors are highly transparent about a major limitation: differentiable interpreters are notoriously difficult to train. The loss landscape is highly non-convex and rugged. For the complex MATH task, the model only converged to the correct program in 2 out of 100 random restarts (though once found, it generalized beautifully).

Future work must focus on making the training of differentiable interpreters more robust. If optimization techniques can be improved to reliably find these programs, hybrid models like NTPT hold massive promise for building interpretable, lifelong learning systems that require far less data than purely neural approaches.

Summary updated

BibTeX
@inproceedings{gaunt2017differentiable,
  author = {Alexander L. Gaunt and Marc Brockschmidt and Nate Kushman and Daniel Tarlow},
  title = {{Differentiable Programs with Neural Libraries}},
  booktitle = {International Conference on Machine Learning},
  year = {2017},
  url = {https://openreview.net/forum?id=BJWgMhW_bH},
}
Figure