Gradient-Based Program Synthesis with Neurally Interpreted Languages

Matthew Macfarlane, Clément Bonnet, Herke van Hoof, Levi Lelis

In the landscape of artificial intelligence, a persistent tug-of-war exists between symbolic and neural approaches. Symbolic methods, akin to traditional programming, excel at "compositional generalization"—if a system learns to shift_left and increment, it can seamlessly combine these operations to solve novel tasks. However, these systems are notoriously brittle and rely heavily on human-engineered Domain-Specific Languages (DSLs). Conversely, neural networks offer immense flexibility and learn directly from raw data, but they often function as monolithic black boxes that struggle to systematically apply learned concepts to longer or more complex out-of-distribution problems.

A new paper, "Gradient-Based Program Synthesis with Neurally Interpreted Languages," introduces the Neural Language Interpreter (NLI). This architecture bridges the neuro-symbolic divide by learning its own discrete, symbolic-like programming language entirely from scratch, achieving near-perfect systematic generalization on tasks where standard neural networks and Large Language Models (LLMs) typically fail.

The Challenge of Program Induction

The core problem NLI addresses is program induction: given a small set of input-output examples (e.g., [1, 2, 3] -> [2, 3, 1]), can a model autonomously "write" the underlying program that performs this transformation?

Current neural approaches, such as In-Context Learning (ICL) in LLMs or Latent Program Networks (LPNs), represent programs as continuous vectors. While powerful, these continuous representations lack the discrete, "building block" nature of real code. Consequently, if a model is only exposed to short programs during training, it generally fails to string those same concepts together to solve longer, more complex problems at test time. On the other hand, traditional symbolic systems that rely on human-written DSLs face severe scalability issues; searching through combinations of discrete symbols quickly becomes an intractable combinatorial explosion.

The Neural Language Interpreter (NLI)

To resolve this, the authors propose an architecture that autonomously discovers a vocabulary of discrete "neural primitives" and learns a differentiable interpreter to execute them.

NLI Architecture

The NLI consists of two primary components:

  1. The Program Inductor (Encoder): This module takes input-output examples and generates a sequence of discrete tokens. Rather than human-readable code, these tokens are learned "primitives" drawn from an emergent codebook.
  2. The Neural Executor (Decoder): Acting as an interpreter, this recurrent network consumes the tokens sequentially, updating an internal state to transform the input into the desired output.

The "Secret Sauce"

  • Gumbel-Softmax Relaxation: To make the discrete token selection differentiable and visible to gradient descent, NLI employs the Gumbel-Softmax trick, allowing the entire system to be trained end-to-end.
  • Gradient-Based Search at Test Time: This is NLI's most innovative feature. If the encoder's initial program guess is incorrect, the model does not fail. Because the interpreter is fully differentiable, NLI uses gradient descent at inference time to iteratively "nudge" the program tokens until they perfectly explain the provided data.
  • Token Reuse Regularization: To prevent the model from trivially memorizing a unique token for every specific task, a regularization loss penalizes the use of too many unique tokens. This forces the model to discover a compact, highly reusable set of primitive operations.

One of the most fascinating outcomes of NLI is the emergence of meaningful, compositional symbols.

Learned Program Representations

For instance, in a sequence-shifting task, the model autonomously discovered a specific token (ID 231) that acts as a "shift-left-by-1" operation. To shift an array by 4, it learned to repeat that token or combine it with another learned primitive (like 476). This demonstrates true compositional generalization.

Furthermore, NLI highlights that recurrence is essential. By processing tokens sequentially rather than simultaneously, the model avoids being locked into a fixed program length, enabling it to solve problems much longer than those encountered during training. Finally, NLI proves that searching in a "relaxed" continuous space using gradients is far more efficient for finding complex compositions than the brute-force combinatorial search used in traditional program synthesis.

Performance Highlights

The authors evaluated NLI on a custom Compositionality Benchmark (testing length extrapolation, primitive extraction, and composition) as well as the standard DeepCoder benchmark.

  • Outperforming the Giants: On the "Shift-L" task (length extrapolation), standard In-Context Learning and Latent Program Networks completely failed, scoring 0% accuracy. In stark contrast, NLI with gradient search achieved 99% accuracy.
  • Zero-Shot Composition: On the "Comp-I" task, NLI achieved 91% accuracy when synthesizing entirely novel programs by recombining its learned primitives.
  • Competitive with Neuro-Symbolic Models: On the complex list-processing tasks of DeepCoder, NLI matched or exceeded the performance of specialized models like ExeDec—remarkably, doing so without ever seeing ground-truth programs during training.

Limitations and Future Directions

While NLI represents a significant leap forward, the authors acknowledge several current limitations. First, running gradient descent at test time to refine programs is computationally heavier than a single forward pass in standard LLMs. Second, the current interpreter executes strictly sequentially; it does not yet support complex control flows like loops (for/while) or conditional branching (if/else) natively within its learned language. Finally, scaling to massive vocabularies for highly complex tasks may introduce optimization challenges, such as vanishing or exploding gradients.

Future iterations of NLI could integrate evolutionary search or more efficient local search strategies, paving the way for models that combine the robust compositionality of discrete languages with the scalable, end-to-end learning power of neural networks.

Summary updated

BibTeX
@inproceedings{macfarlane2026gradient,
  author = {Matthew Macfarlane and Clément Bonnet and Herke van Hoof and Levi Lelis},
  title = {{Gradient-Based Program Synthesis with Neurally Interpreted Languages}},
  booktitle = {International Conference on Learning Representations},
  year = {2026},
  url = {https://openreview.net/forum?id=NAORIWBaoO},
}
Figure