Abstract: We develop a framework for combining differentiable programming languages with neural networks. Using this framework we create end-to-end trainable systems that learn to write interpretable algorithms with perceptual components. We explore the benefits of inductive biases for strong generalization and modularity that come from the program-like structure of our models. In particular, modularity allows us to learn a library of (neural) functions which grows and improves as more tasks are solved. Empirically, we show that this leads to lifelong learning systems that transfer knowledge to new tasks more effectively than baselines.
Introduction
Deep learning has achieved remarkable success in perception-heavy tasks, such as identifying handwritten digits. However, these models often struggle with two fundamental challenges: catastrophic forgetting and poor generalization. When a standard neural network learns a new task, it typically overwrites the weights used for previous tasks. Furthermore, a network trained to sum two numbers often fails when asked to sum ten, as it learns statistical mappings rather than the underlying logic of the operation.
To address these issues, we introduce NEURAL TERPRET (NTPT), a framework that marries the logical structure of computer programs with the perceptual capabilities of neural networks. By treating neural networks as "library functions" within a differentiable program, we create a system capable of solving complex tasks while maintaining interpretability and modularity.
Methods
NTPT is an extension of the differentiable programming language TERPRET. The core philosophy is to represent an algorithm as source code containing "holes" or learnable parameters. In our framework, these parameters represent two distinct types of learning:
- Discrete Control Flow: The model learns which instructions to execute (e.g., choosing between
MOVE,ADD, orLOOK). - Neural Library Functions: Small, specialized neural networks (e.g., a digit classifier) that the program calls to process raw perceptual data.
Because the entire system—including the program's control flow and the neural networks' weights—is differentiable, it can be trained end-to-end using standard gradient descent. The program acts as a high-level controller that decides which neural "tool" from the library is appropriate for a specific sub-task.
Experimental Setup
We evaluated NTPT on a sequence of Perceptual Programming by Example (PPBE) tasks designed to test logic and perception simultaneously:
- ADD2X2: A grid of MNIST digits where the model must learn to sum specific rows or columns based only on the final sum (weak supervision).
- APPLY2X2: A similar grid containing handwritten arithmetic operators (e.g.,
+,-,x). The model must learn to interpret the operator and apply it to integers. - MATH Scenario: A benchmark requiring the model to evaluate variable-length handwritten arithmetic expressions (e.g.,
5 + 3 x 2). This tests the ability to combine digit and operator recognition learned in previous tasks.
Results and Discussion
Our experiments revealed several key advantages of the NTPT framework:
Modularity and Lifelong Learning
NTPT exhibits reverse transfer: learning a new task that utilizes digits actually improves the model's performance on older digit-based tasks. Because the logic is stored in the program structure and perception is in a shared library, the model does not need to relearn basic perception for every new task, effectively shielding it from catastrophic forgetting. On the 2x2 tasks, NTPT achieved 86-100% accuracy, significantly outperforming Progressive Neural Networks (PNNs).
Strong Generalization
Programs possess a natural inductive bias toward loops and recursion. In the MATH scenario, NTPT was trained on expressions with only two digits but maintained high accuracy when tested on expressions with up to 16 digits. In contrast, standard LSTMs and Neural GPUs saw performance drop sharply as expression length increased, as they failed to capture the underlying recursive logic.
Weak Supervision
Notably, the model learns to classify MNIST digits without explicit labels. It infers the identity of a "5" because that is the only interpretation that allows the final mathematical result of the program to be correct.
Conclusion and Future Work
While NTPT shows great promise for modular, lifelong learning, it faces challenges in optimization. Differentiable interpreters create "rugged" loss landscapes with many local minima; we observed that only a small fraction of random restarts successfully converged on the correct program for the MATH task. Future research will focus on making the training of these interpreters more robust and scaling the neural library to handle more complex, real-world perceptual data.
Summary updated