Skip to main content
QUICK REVIEW

[Paper Review] Latent Programmer: Discrete Latent Codes for Program Synthesis

Joey Hong, David Dohan|arXiv (Cornell University)|Dec 1, 2020
Software Engineering ResearchComputer Science48 references5 citations
TL;DR

The Latent Programmer (LP) is a neural program synthesis method that uses discrete latent codes to guide two-level search: first predicting a high-level plan (latent code) from input/output examples, then generating the target program conditioned on the plan. It improves synthesis accuracy by over 10% on longer programs compared to baselines like RobustFill, especially in complex synthesis tasks.

ABSTRACT

In many sequence learning tasks, such as program synthesis and document summarization, a key problem is searching over a large space of possible output sequences. We propose to learn representations of the outputs that are specifically meant for search: rich enough to specify the desired output but compact enough to make search more efficient. Discrete latent codes are appealing for this purpose, as they naturally allow sophisticated combinatorial search strategies. The latent codes are learned using a self-supervised learning principle, in which first a discrete autoencoder is trained on the output sequences, and then the resulting latent codes are used as intermediate targets for the end-to-end sequence prediction task. Based on these insights, we introduce the \emph{Latent Programmer}, a program synthesis method that first predicts a discrete latent code from input/output examples, and then generates the program in the target language. We evaluate the Latent Programmer on two domains: synthesis of string transformation programs, and generation of programs from natural language descriptions. We demonstrate that the discrete latent representation significantly improves synthesis accuracy.

Motivation & Objective

  • To address the challenge of searching over large program spaces in program synthesis by introducing a two-level search strategy inspired by human programming behavior.
  • To learn meaningful, disentangled high-level representations of programs that can serve as plans to guide program generation.
  • To improve synthesis accuracy—particularly for longer and more complex programs—by leveraging discrete latent codes as intermediate plans.
  • To enable more efficient and diverse exploration of program space by decoupling high-level planning from low-level implementation details.

Proposed method

  • The method uses a discrete autoencoder (specifically, a VQ-VAE) to learn a discrete latent code representation of programs, where each program is mapped to a sequence of discrete symbols.
  • A latent predictor network is trained to map input/output examples to the ground-truth discrete latent codes, learning to predict high-level plans from specifications.
  • A latent program decoder generates target language programs token-by-token, conditioned on the predicted latent code, using cross-attention over the latent sequence.
  • The model employs two-level beam search: first generating an L-best list of latent codes, then generating a B/L-best list of programs for each code.
  • During training, variable and argument names are normalized to ARG_i and VAR_i to reduce noise and improve latent code learning.
  • The method is evaluated on two domains: string transformation with I/O examples and code generation from docstrings, using BLEU and accuracy metrics.

Experimental results

Research questions

  • RQ1Can discrete latent codes learned via self-supervised representation learning serve as effective high-level plans for program synthesis?
  • RQ2Does two-level search using latent codes improve program synthesis accuracy compared to end-to-end methods?
  • RQ3How does the performance of the Latent Programmer scale with program length, especially in comparison to baselines?
  • RQ4Can the learned latent codes be interpreted meaningfully as semantic plans, such as identifying common programming patterns?

Key findings

  • The Latent Programmer improves synthesis accuracy by over 10% on longer programs compared to state-of-the-art baselines like RobustFill and Dual.
  • On the code generation task, LP achieves a BLEU score of 21.3 with a beam size of 100, outperforming the next best baseline (17.2) by a significant margin.
  • The method shows particular gains on longer programs, where search space complexity is highest, demonstrating the effectiveness of plan-based search.
  • Interpretability analysis reveals that latent tokens cluster meaningfully with common programming patterns, such as file manipulation or system calls, as shown by TF-IDF analysis of associated program tokens.
  • Normalization of variable and argument names (to ARG_i and VAR_i) significantly improved the model’s ability to learn meaningful latent structures in the program encoder.

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.