Title: SYNTHETIC DATASETS FOR NEURAL PROGRAM SYNTHESIS

Abstract: The goal of program synthesis is to automatically generate programs in a particular language from corresponding specifications, e.g. input-output behavior. Many current approaches achieve impressive results after training on randomly generated I/O examples in limited domain-specific languages (DSLs), as with string transformations in RobustFill. However, we empirically discover that applying test input generation techniques for languages with control flow and rich input space causes deep networks to generalize poorly to certain data distributions; to correct this, we propose a new methodology for controlling and evaluating the bias of synthetic data distributions over both programs and specifications. We demonstrate, using the Karel DSL and a small Calculator DSL, that training deep networks on these distributions leads to improved cross-distribution generalization performance.

1. INTRODUCTION:

Program synthesis is one of the central problems in Artificial Intelligence studied from the early days (Manna & Waldinger, 1971; Waldinger & Lee, 1969) and has seen a lot of recent interest in the machine learning and programming languages community (Alur et al., 2013; Gulwani et al., 2012; 2015; Muggleton, 1991; Lin et al., 2014; Solar-Lezama, 2013) . The recent neural approaches can be broadly classified into two categories: program induction and program synthesis. Both approaches share the objective of learning program semantics but do so in different ways. Program induction aims to embed the semantics of a particular algorithm into a differentiable model trained end-to-end, whereas the goal of program synthesis is for a model to learn the semantics of a domain-specific language (DSL) and produce programs defined by corresponding specifications. Both problems necessitate large datasets, either of I/O pairs in the case of program induction, or programs with corresponding I/O pairs in the case of program synthesis.

However, since large datasets for program induction and synthesis tasks do not exist, these approaches train models on large synthetically generated datasets. Presumably, if a model can accurately predict arbitrary program outputs (for induction) or programs in the DSL (for synthesis) then it has likely learnt the correct algorithm or DSL semantics.

Although this approach has led to some impressive synthesis results in many domains, synthetically generating datasets that cover all DSL programs and the corresponding input space can be problematic, especially for more complex DSLs like Karel the Robot (Pattis, 1981) which includes complex control-flow primitives (while loops and if conditionals) and operators. Likewise, for induction tasks, the sampling procedure for program specifications may lead to undesirable biases in the training distribution that inhibit strong generalization.

In this paper, we consider two problem settings. The first is the Karel domain and the recently proposed Karel synthesis model (Bunel et al., 2018) . We identify many distributions of input examples and DSL programs for which the Karel synthesis model performs poorly. The second problem setting is a program induction problem in which a model is trained to execute and predict the output of simple arithmetic expressions, which we denote the Calculator domain; for this domain, we considered common synthetic data generation strategies including one from tensor2tensor (Vaswani et al., 2018) , an open-source deep learning library. Upon analysis, we find evidence of undesirable artifacts resulting from certain biases in the generation algorithm.

Our results indicate that models trained with common methodologies for synthesizing datasets fail to learn the full semantics of the DSL, even when they perform well on a test set, and suggest the need of a more principled way to generate synthetic datasets. For some program and input distributions, the state-of-the-art neural synthesis models perform quite poorly, often achieving less than 5% generalization accuracy. In our paper, we develop a new methodology for creating training distributions over programs in the DSL to mitigate some of these issues. Moreover, unlike previous works that have ignored considering the distributions over input space, we show that input distributions also play a significant role in determining the synthesizer performance. Our methodology involves defining the distribution over DSL programs and input space using a set of random variables to encode much of the valuable features which describe the data, e.g. in the Karel domain, the amount of control flow nesting in programs or the number of markers present in the inputs.

Our methodology allows us to identify several specialized distributions over the input space and Karel programs on which the current state of the art synthesis models (Bunel et al., 2018) perform poorly when trained on traditional program and input distributions, and tested on our new distributions. From this, we design new training distributions by ensuring greater uniformity over the random variables in our methodology. By retraining the same architecture on these new training data distributions, we observe a greater ability to generalize, with significant improvements when evaluated on the aforementioned test sets. We also observe similar improvements in the Calculator domain as well.

This paper makes the following key contributions:

• We propose a new methodology to generate different desirable distributions over the space of datasets for program induction and synthesis tasks. • We instantiate the methodology for the Karel and Calculator domains and show that model generalization is worse on datasets generated by our technique. • We then retrain models in both domains and demonstrate that models achieve greater overall generalization performance when trained on datasets generated with our methodology.

2. RELATED WORK:



2.1. TRAINING MODELS WITH SYNTHETIC DATA:

In certain domains like computer vision and robotics, collecting high-quality real-world training data incurs significant cost, and so many researchers have investigated the use of large amounts of synthetic data. For example, Christiano et al. (2016) ; Peng et al. (2017); Pinto et al. (2017) ; Bousmalis et al. (2017) aim to learn robotics policies that compensate for differences between the real world and the simulation. Within computer vision, Shrivastava et al. (2016) demonstrate learning from entirely synthetic images for gaze and pose estimation.

2.2. NEURAL PROGRAM INDUCTION AND SYNTHESIS.:

Program induction methods learn differentiable modules such as stack (Joulin & Mikolov, 2015) , RAM (Kurach et al., 2016) , GPU (Kaiser & Sutskever, 2015) , and read-write external memory (Graves et al., 2014) to represent algorithms. Other methods attempt to learn differentiable control flow operations (Gaunt et al., 2016; Neelakantan et al., 2015) . These approaches reconstruct outputs given inputs, inferring the underlying algorithms. Other methods instead learn neural modules from program traces rather than from I/O examples (Reed & de Freitas, 2015; Xiao et al., 2018; Cai et al., 2017) . In fact, our results show that under certain distributions, these models perform quite poorly. To verify these models appropriately generalize to reasonably complex arbitrary programs, the test set should sufficiently represent the universe of these programs and their specifications. Likewise, to avoid biasing the result, the test set should also draw uniformly from these programs and specifications. For example, for RobustFill, the data generation methodology only sampled programs uniformly from the string DSL, but did not take into account the distribution over input strings such as their length, frequencies of occurrence of regular expressions and their nesting, common words and constants etc.

3. DATA GENERATION METHODOLOGY:

Currently, automated data generation focuses in large part on a constructive process, whose parameters can be tuned. We propose a complementary approach in which we perform a subsequent filtering step on this process to ensure that the resulting distribution has certain properties.

We define a salient random variable as one whose distribution in the final dataset is of interest. In the case of program synthesis, we consider two kinds of salient variables: variables denoting important features of a program in the given DSL, such as its length and degree of nesting; and variables denoting features for the input space.

In many cases, we can modify our sampling procedure to ensure a desirable distribution of a particular salient variable. However, for some salient variables, it is infeasible to tune the parameters of a given sampling procedure in order to obtain a desired distribution for that salient variable. For example, if we sample programs directly from a context-free grammar, it is difficult to control the distribution of various salient variables such as program length, degree of nesting, etc. This is a notable problem in both the Karel and Calculator domains.

Furthermore, within the context of program synthesis specifically, there is often an additional challenge: not all inputs are valid for all programs. For example, in the Karel domain, an input for a given program would be invalid if the program attempts to perform illegal actions for that input (such as move into walls or pickMarker in a cell containing no markers). The requirement that the program/input pairs suit each other itself acts as an unpredictable filter that makes it difficult to ensure uniformity of salient variables by tuning generation parameters.

As such, we propose a methodology for randomly sampling a dataset D (consisting of elements of S) while ensuring that a given salient variable ν : S → X (where X is finite and discrete), denoted as a random variable X = ν(s), has a uniform distribution throughout D. To do this, we first sample an example s ∼ q(•) from an original distribution q. We then add s to D with probability g(s), where

g(s) = (P q [X = ν(s)] + ε) -1 min x∈X P q [X = x] + ε , with P q [X]

, the probabilities induced over X via q, calculated empirically based on counts computed with past samples drawn from q. We repeat the above until D is of a desired size. For full pseudocode see Section B.1 in the appendix.

We use ε ∈ R + as a hyperparameter to trade off the runtime of the above procedure with the level of X's uniformity in D. In Section B.2 (in the Appendix), we provide a probabilistic bound on the uniformity of X in the resulting distribution, for the case where ε = 0. Also, for when ε > 0, we can show that drawing a single sample is possible in O( 1 ε ) calls to the original sampler (proof in Section B.3, with empirical experiments in Section B.4 and B.5). Increasing ε increases the algorithm's speed, at the cost of allowing the distribution of X in D to further diverge from uniform.

4. APPLICATION TO KAREL: EXPERIMENTS WITH NEW TEST DISTRIBUTIONS:

Karel is an educational programming language (Pattis, 1981) where the programmer writes imperative programs with conditionals and loops to produce a sequence of actions for an agent (a robot named Karel) which lives in a rectangular m × n grid world. For a detailed description of the particular instantiation of the Karel language and input grid specification that we consider, see Section A. The program synthesis task that we consider is as follows: given a set of pairs of input and output grids In this section, we employ the Karel instantiation of our abstract data generation methodology in Section 4.1 to generate different test datasets. By imposing a more uniform distribution over the salient random variables when generating the I/O specifications and target programs which make up the test set, we observe much lower accuracies of the previous Karel synthesis models (Bunel et al., 2018) compared to the original test set.

{(i 1 , o 1 ), • • • , (i n , o n )}, find a Karel program π such that executing π on i 1 results in o 1 , i 2 results

4.1. SALIENT VARIABLES IN KAREL:

We devised the following salient random variables to describe the input space in Karel:

• Grid size: Dimensions of the grid in which Karel can act.

• Marker ratio: Fraction of cells with at least one marker.

• Wall ratio: Fraction of cells which contain a wall.

• Marker count: Number of markers that are present in a cell containing markers.

• Number of grids: Number of I/O grids shown to the model to specify the desired program.

For the program space in the Karel DSL, we consider the following random variables:

• Program size: Size of the program in terms of number of tokens.

• Control flow ratio: Number of control flow structures appearing in the program.

• Nested control flow: The amount of control flow nesting in programs (e.g. while inside if).

4.2. CHANGING THE I/O DISTRIBUTION:

We reproduced the encoder-decoder model of Bunel et al. (2018) and trained it using the provided synthetic training set with the teacher-forcing maximum likelihood objective. On the existing test set, our model achieves 73.52% generalization accuracy, slightly higher than the 71.91% accuracy reported in Bunel et al. (2018) . Generalization accuracy denotes how often the model's output is correct on both the 5 I/O examples shown to the model and the remaining held-out 6 th I/O example.

To test how the model may be sensitive to changes in the I/O examples used to specify the program, we created new test sets by sampling new input grids and running them on each of the programs in the existing test set to obtain new I/O pairs. By keeping the programs themselves the same, we avoid inadvertent changes in the inherent difficulty of the task (the complexity of the programs to be synthesized).

Salient random variables with uniform distribution. We first generated grids such that they would follow a distribution that is as uniform as possible in the salient features in Section 4.1. We used the following procedure to sample each grid: 1) sample the grid size (height and width) from x, y ∼ U{2, . . . 16}; 2) sample the marker ratio r marker ∼ U(0, 1) and wall ratio r wall ∼ U(0, 1);

3) for each cell (i, j), 0 ≤ i < x, 0 ≤ j < y in the grid, sample m i,j ∼ Bernoulli(r marker ) and w i,j ∼ Bernoulli(r wall ); 4) if m i,j = 1 and w i,j = 0, sample marker count mc i,j ∼ U{1, . . . 9}, otherwise set mc i,j = 0; 5) place walls and markers in grid according to w i,j and mc i,j ; 6) place Karel at a random location (not containing a wall) and with a random orientation. After generating 5 input grids for a given program, we ensure that the program does not crash on any of them and also check whether the 5 input grids exhibit complete branch coverage (i.e., each branch is taken by at least one of the 5 inputs). If either of these conditions are not satisfied, we discard all 5 grids and start over.

On this dataset, the model trained on existing data achieved generalization accuracy of only 27.9%, which was a drop of 44.6pp from the existing test set's generalization accuracy of 73.52%.

Salient random variables with narrow distributions. We further investigated the performance drop noted above by synthesizing "narrower" datasets that captured different parts of the joint probability space over the salient input random variables. For each narrow dataset, we selected r wall and r marker (both between 0 and 1) as well as a distribution D marker count which would be the same for all I/O grids. Then, we follow the procedure below for each grid: 1) sample the grid size (height and width) x, y ∼ U{10, . . . 16}; 2) randomly choose xy • r wall cells to contain walls, and xy • r marker cells for markers; 3) sample mc i,j ∼ D marker count for all cells (i, j) chosen to contain markers; 4) place Karel at a random location (not containing a wall) and with a random orientation. In our experiments, we primarily used 3 different distributions for D marker count : Geom(0.5) truncated at 9, U{1, . . . 9}, and 10 -Geom(0.5) which, when sampled, has a value equal to 10 minus a sample from Geom(0.5), truncated at 1.

The results are shown in Table 1 (row 1, "Baseline (%)"). We discovered that the most correlated factor with model performance was the distribution D marker count . A more negative skew consistently lowered model performance, and this effect was more pronounced at higher values of r marker .

4.3. CHANGING THE PROGRAM DISTRIBUTION:

We will now examine how the existing model can surprisingly fail to perform well at synthesizing certain programs that are different from those in the existing validation and test sets.

Performance on complex DSL constructs. We examined whether or not the model could succeed in synthesizing programs which require nesting of conditional constructs. This was of interest since these programs were relatively rare in the training dataset. We generated an evaluation dataset comprised solely of programs that contained while inside while statements, and another dataset in which all programs had while inside if statements. 1 We found that the model fared very poorly on these datasets, achieving only 0.64% and 2.23% accuracy respectively.

Programs only containing actions. Intuitively, much of the difficulty in the Karel program synthesis task should come from inferring the control flow statements, i.e. if, ifElse, and while. Synthesizing a Karel program that only contains actions is intrinsically a much more straightforward task, which a relatively simple search algorithm (such as A * ) can perform well. We performed an experiment using test datasets generated by enumerating action-only programs of various lengths. As there are five actions (move, turnLeft, turnRight, putMarker, pickMarker), there exist 5 L textually unique action-only programs for length L. We sampled up to 500 unique programs of lengths 1, 2, . . . , 8. For each program, we generated 10 specifications, each containing 5 I/O pairs. We sampled each I/O pair from the set of all input grids in the existing training data (of which there are 6.7 million), as to match its distribution as closely as possible.

Table 2 shows the results. Remarkably, even though the underlying programs have relatively low complexity, the model's accuracy is lower on every one of these action-only test sets than the existing provided test set. The generalization accuracy grows as the program length becomes longer, even though those programs should be harder to synthesize.

Among the existing action-only programs in the test set, the model's generalization accuracy on that subset is 99.24%. Given the surprising nature of this result, we investigated the difference between the action-only programs we generated, and those in the existing test set. We found that in the existing training and test sets, all programs contain at least two actions, and also contain at least one move action somewhere in the program. These and any undiscovered differences in the distribution of programs seem to have caused the gap in performance.

5. APPLICATION TO KAREL: CHANGING TRAINING DISTRIBUTIONS:

In Section 4, we saw that the existing model performs much more poorly on certain test datasets that we constructed, compared to its performance on the existing test set as reported in Section 4.2. In light of the framework in Section 3, various imbalances of the salient random variables in the existing training data could have caused these gaps in performance. Then, a natural solution is to train using datasets constructed to avoid undesirable skews in the salient random variables, which should hopefully perform better across a variety of distributions.

5.1. TRAINING DATASETS WITH UNIFORM I/O:

We generated a training dataset by taking the programs of the existing training set and synthesizing I/O pairs using the procedure described in Section 4.2. Furthermore, to make the "number of grids" salient variable uniform, we modify the training procedure by uniformly sampling a number between 1 and 5 for each mini-batch, and using that many I/O grids to specify the program to the model. We trained a model on this data and then evaluated it on the same set of narrow distribution evaluation datasets as mentioned in Section 4.2. Table 1 and Figure 2 compares how this new model performs to the baseline model. The model trained on uniform I/O distributions maintains much higher generalization accuracy on the test sets of Section 4.2 than the baseline model. Note that the uniform I/O distribution is not simply a union of the tested distributions and is intended to cover all possible input specifications.

5.2. REAL-WORLD BENCHMARKS:

We evaluated both the baseline model, and the uniform model described in the previous paragraph, on a set of 36 real-world Karel programming problems. This dataset was compiled from the Hour of Code Initiative and Stanford University's introductory computer science course, CS106A, with the problems being hand-designed as educational exercises for students. We found that the baseline model got 4 correct (11.1%) while the uniform model got 7 correct (19.4%) when both models were trained with 5 shown I/O pairs, i.e., without making the "number of grids" salient variable uniform. 1 plus performance on the original test set. The training datasets used for both models (denoted Baseline and Uniform) contained the same programs; however, for Uniform, we sampled new I/O grids used to specify the programs, with homogenized salient random variables, as described in Section 4.2.

This further demonstrates the uniform model's increased ability to generalize to out-of-distribution datasets, including those which are of interest to humans. Both models' accuracies are still low compared to the performance on the synthetically generated test set.

After further analysis, we believe the models face two challenges on the real-world test set: (1) many of the real-world problems require long programs to solve compared to the synthetic test set, (2) the specifications in the real-world examples always contains fewer than 5 I/O pairs, and often only a single one. However, the original training methodology for the model assumes that it is provided with a diverse set of 5 I/O pairs. When we modified the training procedure to vary the number of shown I/O examples as in Section 5.1, the baseline model got 12 correct (33.3%) and the uniform model got 11 correct (30.6%). This shows that the homogenization on the number of I/O pairs was effective. Overall, the real-world dataset's I/O distribution was similar to the MSR training datset in terms of the salient random variables we homogenized, so it is unsurprising that the baseline model was able to outperform the uniform model, consistent with the results on the MSR test set in Figure 2 .

5.3. AUGMENTING DATASET WITH ACTION-ONLY PROGRAMS:

We observed in Section 4.3 that the model fails to do well on either action-only programs or programs with many control-flow statements. In the case of action-only programs, we found that the training data had been pruned to only include programs with at least two actions and at least one move, and in the case of programs with complex control flow, we found a similar sparsity in the train set.

As discussed in Section 3, the principled way to counteract this sparsity is to introduce uniformity into a set of salient variables. This methodology allows us to counteract both naturally sparse data (such as complex control-flow) and spurious data pre-processing (such as enforcing programs to have at least two actions).

In our case, we introduce uniformity into the length of action-only programs by synthesizing 20,000 programs of each length 1 to 20, by uniformly selecting tokens from the five action choices and generating I/O with other salient random variables as close to the original training set as possible; we append these new programs to the original dataset to train a new model. Table 2 shows a clear improvement when homogenizing this salient random variable. The new model achieved 71.8% accuracy on the original test set, which is very close to the 73.52% accuracy of the baseline model.

5.4. TRAINING DATASETS WITH NARROWLY DISTRIBUTED I/O:

As done in for the uniform training dataset, we generated "narrow" training datasets by keeping the same programs as in the existing training data and replacing the I/O pairs with the process from Section 4.2.

We trained a variety of models and evaluated them on 12 datasets of different I/O feature distributions. Figure 3 summarizes the results of evaluating each model on each dataset by noting the performance of the model on the narrow dataset of the same type and the outcome on every other narrow dataset. For the models trained on the low variance datasets, we observed that they all consistently achieved between 60 and 70 percent accuracy on their own training distribution; however, the uniform model was able to achieve similar performance (between 57 and 80 percent accuracy) as shown in Table 1 and Figure 2 . As such, we hypothesize that models trained on wide, uniform distributions can still perform comparable to models trained on narrow sub-distributions, even when tested on the same sub-distributions.

6. APPLICATION TO CALCULATOR:

The Calculator task is given as follows: given an expression such as "5+4 * (2+3)", compute the result modulo 10; in this case, 5. Calculator is a program induction task rather than a program synthesis task like Karel; nevertheless, creating data for the Calculator problem involves sampling from a context-free grammar. Additionally, Calculator is not as intricate a domain as Karel and thus we can more completely control the environment of data generation with less fear of lurking variables.

6.1. CALCULATOR ENVIRONMENT:

Calculator model. Similar to the work by Zaremba & Sutskever (2014) , we implement an LSTM that parses calculator expressions on a character level. We perform a 10-class classification problem using a dense network on the final hidden state of the LSTM. The prediction is correct if it exactly matches the evaluation result of the expression, modulo 10.

Distributions of Calculator tasks. We propose 4 distributions for calculator tasks: direct CFG sampling (DCFG), tensor2tensor sampling (T2T), "runs" CFG sampling (RCFG), and balanced sampling (BAL).

Two of our distributions represent reasonable ways in which a researcher might choose to sample data. The first is DCFG, which involves returning a digit with some probability (1 -p), or else recursively sampling two productions and combining them with a -, * , or +, each with probability p 3 . This corresponds to a direct, weighted sampling of the CFG for the calculator grammar. The second is T2T, which is used by the tensor2tensor library to sample arithmetic expressions in one of its examples.2 It involves sampling a depth d, then ensuring that the resulting AST has depth d by forcing a random side of the operation production to be sampled to d -1 and the other side to be sampled to a depth d ∼ U{0, 1, . . . , d -1}.

The other two distributions represent potentially difficult or nonstandard problems that might appear in practical environments. RCFG is similar to DCFG but involves increasing the frequency of "runs" of the associative operations + and * by picking 2, 3, or 4 subexpressions and then combining them with the given symbol. BAL (balanced sampling) involves selecting a depth and then creating an AST that is a balanced binary tree at that depth. Importantly, regardless of sampling technique, redundant parentheses are removed. This is to increase the difficulty somewhat as order of operations needs to be established.

6.2. SALIENT VARIABLES AND METHODOLOGY:

We use the following salient variables: length (rounded to the nearest even number), number of operations, number of pairs of parentheses, mean parenthesized depth, and maximum parenthesized Table 3 : Improvements in Calculator performance over unhomogenized distributions when various homogenizations were applied. See Section 6 for details on performance metrics.

depth. Parenthesized depth is defined for each digit and refers to the number of nested parentheses it is in. For example in (1+2) * (3-4)+5, the 1, 2, 3, and 4 are at depth 1 while the 5 is at depth 0.

We constructed 2 × (1 + 5) distributions in total, corresponding to a total of 2 task distributions, T2T and DCFG, which represent the "natural" sampling techniques a researcher might employ, and 1 + 5 homogenization strategies, one unhomogenized and five homogenized corresponding to each salient variable with ε = 0.025. We then evaluated each model on a fresh evaluation set sampled from a mixture of the four unhomogenized distributions (T2T, DCFG, RCFG, BAL).

6.3. RESULTS:

The original performances and improvements created by homogenizing different random variables can be found in Table 3 . On average, homogenizing the DCFG and T2T distributions caused the accuracy to increase by 5.00pp and 2.84pp, respectively.

We note that the Calculator domain is much simpler than Karel when considering both input complexity (grid worlds versus arithmetic expressions) and output complexity (a DSL program versus a single digit). Furthermore, the difference in distributions between the naive sampling approaches and the versions with one homogenized random variable are not as different in Calculator as what we observed in Karel (see Table 1 for the dramatic effect of D marker ). We hypothesize that it is this difference in complexity that explains the smaller (but still consistent) effect of homogenizing salient random variables in Calculator as compared to in Karel.

7. CONCLUSION:

We demonstrate that existing sampling methods for randomly generating input-output examples have unintended and overlooked distribution flaws in both the Calculator and the Karel domain. These flaws prevent models trained on these distributions from generalizing to other test distributions, even if the are very simple. To resolve these problems, we propose a robust strategy for controlling and evaluating the bias of synthetic data distributions over programs and specifications by defining certain random variables that capture desired features of the program and input spaces, such as the number of parentheses in a calculator expression, and specifically manipulating their distributions. Equipped with our method, deep networks exhibit an increase in cross-distribution test accuracy, at the expense of a minor decrease in on-distribution test accuracy. We believe this methodology would lead to more rigorous evaluation of the synthesis techniques and moreover, aid them in learning better models that generalize well.

Equipped with a set of hand-designed salient random variables, we demonstrate the effectiveness of homogenizing synthetic datasets over this set. One of the core limitations of our approach is that the salient random variables are engineered by hand. This requires the scientist to have insights about the structure of the training examples they are randomly generating. Therefore, a promising extension of this algorithm is to automatically select which salient random variables to use, and automatically compute these variables; potentially via the use of a general unsupervised learning algorithm.

We evaluate our method on two domains: the Karel DSL, and a calculator expression parser. There is a natural question of whether the methods developed in this paper will improve out-of-distribution generalization on applications other than program synthesis which use synthetic data-for example, a convolutional neural network that receives renderings of a virtual environment, for the robotics and vision domains mentioned in Section 2.1. Providing a thorough evaluation of our proposed homogenization algorithm on alternative domains is a promising area for future work. As with Bunel et al. (2018) , we assume a bound on the input grid size to be 2 ≤ m, n ≤ 16. Each cell (i, j) in a grid can either be empty, contain an obstacle (i.e. a wall, specified by the list Walls), or contain k ≤ 9 markers (defined using the list Markers). The agent starts at some cell denoted by KarelLoc in the grid (which may contain markers but no obstacle) with a particular orientation direction denoted by Orientation.

The grammar for the Karel DSL we consider in this work is shown in Figure 4 (a). The DSL allows the Karel agent to perform a move action to move one step in the grid in the direction of the orientation, actions turnLeft and turnRight to change its orientation direction, and actions pickMarker and putMarker to manipulate markers. The language contains if, ifElse, while constructs with conditionals {front,left,right}IsClear, markersPresent, and their negations.

The repeat construct allows for a fixed number of repetitions. Note that the language does not contain any variables or auxiliary functions.

B SALIENT VARIABLE HOMOGENIZATION ALGORITHM:

The following is a more formal description of the Algorithm described in Section 3, as well as proofs of correctness, and an investigation of the parameter's pratical effect.

B.1 FULL PSEUDOCODE:

Let S be some space that is sampled by some original distribution q : S → [0, 1]. Let X be the space of a salient variable which is calculated by ν : S → X; it is a finite set. Let ε be our tolerance. procedure SAMPLEDHOMOGENIZE(q

: S → [0, 1], ν : S → X, ε ∈ R, n ∈ N) C ← {x → 0 : x ∈ X} Set up a dictionary of counts of each value of X t ← 0

The total number of samples seen D ← {} D is originally an empty multiset while

|D| < n do s ← a sample from q C[ν(s)] ← C[ν(s)] + 1 t ← t + 1 p min ← min x∈X C[x] t p curr ← C[ν(s)] t g ← pmin+ε pcurr+ε h ← 1 with probability g 0 with probability 1 -g if h = 1 then D ← D ∪ {s} end if end while return D end procedure B.2 PROOF OF CORRECTNESS

Let the initial sampling distribution be q and the resulting distribution be r. We use the notation P r [X = x] to refer to the probability that X = x given that S is sampled from the distribution r. C[x] refers to the count for the salient variable value x ∈ X among past samples from q, as defined in SAMPLEDHOMOGENIZE.

Theorem. The Salient Variable Homogenization algorithm produces samples from a distribution close to uniform. Formally, after 48 log 2|X| δ pm|X| 2 ξ 2 samples are drawn from distribution q, we have that the resulting homogenized distribution satisfies

P r [X = x] - 1 |X| ≤ ξ

with probability at least 1 -δ, where p m = min x∈X P q [X = x] > 0 and ε has been set to 0.

Proof. We can simplify the probability as

P r [X = x] = P q [X = x]/C[x] z∈X P q [X = z]/C[z] (for ε = 0; see Probability Simplification Lemma below). Let α = ξ|X| 4 . We have that n > 3 log 2|X| δ α 2 pm

by assumption and substituting in α. By the Count Bounding Lemma we have that

nPq[X=x] C[x]

-1 ≤ α for all x with probability at least 1 -δ. The following computations assume

nPq[X=x] C[x]

-1 ≤ α for all x and thus are valid with probability 1 -δ.

We have

nPq[X=x] C[x] ∈ [1 -α, 1 + α]. We also have 1 |X| z∈X nP [X = z]/C[z] -1 = 1 |X| z∈X (nP [X = z]/C[z] -1) =≤ 1 |X| z∈X |nP [X = z]/C[z] -1| =≤ 1 |X| z∈X α = α and thus 1 |X| z∈X nP [X=z] C[z] ∈ [1 -α, 1 + α].

Combining the previous two ranges via a division, we have

|X|P r [X = x] = nPq[X=x] C[x] 1 |X| z∈X nP [X=z] C[z] ∈ 1 -α 1 + α , 1 + α 1 -α We have that 1-α 1+α = 1 -2α 1+α ≥ 1 -2α ≥ 1 -4α and 1+α 1-α = 1 + 2α 1-α = 1 + 4α 2-2α ≤ 1 + 4α since 2 -2α > 1 for small α. Thus, we have that 1-α 1+α , 1+α 1-α ⊆ [1 -4α, 1 + 4α] and therefore we have |X|P r [X = x] ∈ [1 -4α, 1 + 4α] we thus have that P r [X = x] -1 |X| ≤ 4α |X| = ξ, completing our proof.

Lemma (Count Bounding). We have that if n >

3. log:

2|X| δ α 2 pm samples have been drawn from q that

P ∃x ∈ X, nP q [X = x] C[x] -1 ≥ α ≤ δ where p m = min x∈X P q [X = x]

Proof. We can model C[x] as a sum of n independent Bernoulli trials with probability P q [X = x].

Using Chernoff bound, we have that

P [C[x] ≥ nP q [X = x](1 + α)] ≤ e -α 2 nPq[X=x]/3 and P [C[x] ≥ nP q [X = x](1 -2/3α)] ≤ e -α 2 nPq[X=x]/3

Thus, we have by union bound that

P nP q [X = x] C[x] ≥ 1 1 -2/3α ∨ nP q [X = x] C[x] ≤ 1 1 + α ≤ 2e -α 2 nPq[X=x]/3

For α ≤ 3/2 -1 we have that

1 1- √ 2/3α = 1 + √ 2/3α 1- √ 2/3α = 1 + α √ 3/2-α ≤ 1 + α and 1 1+α = 1 -α 1+α ≥ 1 -α.

Thus, we can restate the previous inequality as

P nP q [X = x] C[x] ≥ 1 + α ∨ nP q [X = x] C[x] ≤ 1 -α ≤ 2e -α 2 nPq[X=x]/3

or in other words

P nP q [X = x] C[x] -1 ≥ α ≤ 2e -α 2 nPq[X=x]/3

Thus we can bound the RHS as

2e -α 2 nPq[X=x]/3 ≤ 2e -α 2 npm/3 < 2e -α 2 3 log 2|X| δ α 2 pm pm/3 = 2e -log 2|X| δ = δ |X|

where the first inequality is since P q [X = x] ≥ p m and the second is since n >

2|X| δ α 2 pm . We can again apply union bound to get that

P ∃x ∈ X, nP q [X = x] C[x] -1 ≥ α ≤ |X| δ X = δ

Lemma (Probability Simplification). g(s)q(s)

s ∈S g(s )q(s ) = s∈S:ν(s)=x g(s)q(s)

s ∈S g(s )q(s ) = s∈S:ν(s)=x g(s)q(s) z∈X s ∈S:ν(s )=z g(s )q(s )

Since we can simplify s∈S:ν(s)=x g(s)q(s) = P q [X = z]

= P q [X = x]/C[x] z∈X P q [X = z]/C[z]

B.3 EFFICIENCY ANALYSIS:

We show that the number of samples from the original distribution required to produce a sample from the homogenized distribution is O( 1 ε ) in expectation. In the Salient Variable Homogenization algorithm, we have the probability of not rejecting a given sample as g(s) = minx P [X=x]+ε P [X=X(s)]+ε . We know that

g(s) = min x P [X = x] + ε P [X = v(s)] + ε ≥ ε P [X = v(s)] + ε ≥ ε 1 + ε

Since each sample is independent, we can model this as a geometric distribution, and thus we have that the expected number of tries t = 1 g(s) ≤ 1 + 1 ε . We thus have that in expectation, we need to sample O( 1 ε ) samples from the original distribution to produce one homogenized sample.

B.4 EMPIRICAL EFFECT OF VARYING ε:

The solid line is an upper bound ε 1+ε derived in Section B.3. Seen in the measured samples for different values of ε, the upper bound appropriately reflects the maximum height of the samples, with Table 4 : Improvements in Calculator performance with homogenized datasets of various sampling parameters ε. See Section 6 for details on performance metrics.

very little remaining space on the DCFG dataset and some but not much on the T2T dataset, and is thus a close bound. As the values of ε → ∞ the bound approaches the limit 1, indicating no samples are rejected by the algorithm.

Increasing the parameter ε has the theoretical affect of causing the homogenized distribution to deviate more from uniform in its salient random variables, as shown in B.3. In practice, we discover that performance boosts tend to decrease with increasing ε, although the effect was not as pronounced on the T2T dataset, potentially because the unhomogenized T2T distribution is closer to uniform and thus homogenization has a limited effect for any larger ε values.

B.5 EMPIRICAL EVIDENCE FOR INCREASE IN UNIFORMITY:

Empirically, the Salient Variable Homogenization algorithm led to increases in uniformity in the variable being homogenized. We measure uniformity by KL divergence between the distribution being measured and the uniform distribution. A table of relative improvements is given in 

:

To avoid any negative effects from changes in the I/O distribution, we attempted to ensure that rwall, rmarker and Dmarker count matches that of the provided training and test sets.

https://github.com/tensorflow/tensor2tensor/blob/8bd81e8fe9dafd4eb1dfa519255bcbe3e33c7ffa/ tensor2tensor/data_generators/algorithmic_math.py

Figures and Tables:

Figure 1: An example Karel synthesis task, where the goal is to synthesize the program in (b) given the two I/O examples shown in (a). See the Appendix for more details about Karel.

Figure 2: Comparison of generalization accuracies across the datasets given in Table1plus performance on the original test set. The training datasets used for both models (denoted Baseline and Uniform) contained the same programs; however, for Uniform, we sampled new I/O grids used to specify the programs, with homogenized salient random variables, as described in Section 4.2.

Trained on Narrow Distributions When Evaluated on Other Narrow Distributions

Figure3: Evaluation of models that were trained on narrow distributions. When evaluated on their own training distribution, they consistently achieved similar results. When evaluated on a different narrow distribution, the performance was rarely similar and usually very low.

Figure 4: (a) The DSL of Karel programs taken from Bunel et al. (2018), and (b) a declarative specification of the space of valid input worlds for Karel programs.

r [X = x] = P q [X = x]/C[x] z∈X P q [X = z]/C[z]

Figure 5: Number of samples required by salient variable homogenization parameterized by an ε before a new sample is returned.

Generalization accuracies of the baseline model and a model trained on a uniform I/O distribution, on selected datasets. G, U , and A stand for Geom(0.5), U{1, . . . 9} and 10-Geom(0.5) respectively. See Section 4.2 for dataset generation details, and Section 5.1 for details about the Uniform model.

Table content: <table><tr><td>r wall</td><td/><td>0.05</td><td/><td/><td>0.25</td><td/><td/><td>0.65</td><td/><td/><td>0.85</td><td/></tr><tr><td>r marker</td><td/><td>0.85</td><td/><td/><td>0.65</td><td/><td/><td>0.25</td><td/><td/><td>0.05</td><td/></tr><tr><td>D marker count</td><td>G</td><td>U</td><td>A</td><td>G</td><td>U</td><td>A</td><td>G</td><td>U</td><td>A</td><td>G</td><td>U</td><td>A</td></tr><tr><td>Baseline (%)</td><td>24.30</td><td>1.32</td><td>0.04</td><td>21.08</td><td>2.98</td><td>0.08</td><td>16.63</td><td>13.31</td><td>6.63</td><td>15.99</td><td>12.88</td><td>12.98</td></tr><tr><td>Uniform (%)</td><td>69.37</td><td>70.21</td><td>68.99</td><td>63.25</td><td>63.74</td><td>62.78</td><td>65.83</td><td>67.39</td><td>68.09</td><td>77.32</td><td>78.63</td><td>80.19</td></tr><tr><td>∆</td><td colspan="12">+45.07 +68.89 +68.95 +42.17 +60.76 +62.70 +49.20 +54.08 +61.46 +61.33 +65.75 +67.21</td></tr></table>

Results on programs only containing actions. The generalization accuracy on action-only programs in the existing test set is 99.24%. See Section 5 for details on Action-Only Augmented.

Table content: <table><tr><td>Program length</td></tr></table>



Table content: <table><tr><td/><td>Length</td><td colspan="3">Max Depth Mean Depth #Operations</td><td>#Parens</td></tr><tr><td>DCFG</td><td>42.98%</td><td>30.77%</td><td>27.05%</td><td>43.95%</td><td>23.63%</td></tr><tr><td>T2T</td><td>46.68%</td><td>30.45%</td><td>13.99%</td><td>38.82%</td><td>36.91%</td></tr></table>

Percentage reductions in KL-divergence from uniform of the given salient variable when homogenized at ε = 0.025.

Table content: <table/>

Peer review (iclr2019):
 This paper provides a good presentation of a serious problem in evaluating (as well as training!) performance of machine learning models for program synthesis / program induction: considering specifically the problem of learning a program which corresponds to given input/output pairs, since large datasets of "real-world" programs typically do not exist it necessary to construct a synthetic dataset for training and testing; this requires both (a) generating programs, and (b) generating input/output examples for these programs. Enumerating either all possible programs or examples is typically impossible, and so a sampling scheme is used to simulate "reasonable" programs and examples. This may hinder generalization to other data not often produced by the sampling scheme. To address this, the paper then argues that programs should be synthesized from a distribution which as as uniform as possible over a set of user-specified statistics (the "salient variables") as well as over the input space. Intuitively, this makes sense: maximizing the entropy of the synthetic data should provide good coverage over the entire input space. However, there are a few ways in which the particular approach is unsatisfying: (1) It requires manual curation of salient random variables. This sort of punts the decision of "what should my sampling procedure be" to "what is my choice of salient variables to make uniform". I agree that this is still an improvement. (2) The procedure described for generating synthetic examples is essentially a rejection sampling algorithm, and it will fail to generate examples in a reasonable timeframe if the original proposal distribution is highly non-uniform, or if the salient random variables include values which fall in the tail of the proposal distribution. Also, relatedly, I don*t follow the description of correctness in section 8.2 at all. What is meant by the "= 1" at the end of the line right before "… And thus…"? Clearly P_r[X=x] cannot both equal 1, and equal k. Is the "=1" meant to only mean the summand itself? If so, please fix the notation. Also, I assume that k is meant to be the cardinality of the set {s: X(s) = x}, but this is not defined anywhere. Notational issues aside, unless the mapping X(s) from sample to salient variable is one-to-one, then I*m not clear how the P_q[X = X(s)] would relate to q(s). This should be made more clear. Also, I believe there need to be conditions on q(s), e.g. such that min_x P_q[X = x] must always be greater than zero. These issues aside, the empirical demonstrations on the Karel the Robot examples are nicely presented and make the point well. My primary question here would be around section 5, the "real-world benchmarks", where it is observed that the baseline model performs less well than re-training on a uniform / homogenized dataset. While it is nice that it performed better, I don*t understand why even the better number (19.4%) is so low; the performance of the uniform model in table 1 tends to be much higher (in the 60% to 70% range). This would suggest that the uniform model perhaps is significantly *underweighting* important parts of the space. What is causing this? e.g. what do the salient variables look like for real-world examples? Finally, I am not sure I understand how the calculator example fits into this paper. Unless I misunderstand, it is not a program synthesis task, but rather a regression task. Clearly it does still depend on generation of synthetic data, but that is more a different task (as described in section 2). I feel its inclusion somewhat dilutes the paper. Rather, it would be nice to see more discussion or investigation into the failure modes of these trained models; for example, looking deeper at the handling of control flow and recursion, or at whether particular values of salient variables tended to be correlated with success or failure under different train / test regimes. ===== after updates ===== Thanks for the edits — I believe the overall paper is more clearly presented, now. I still think it is a stretch to consider the calculator domain is a program induction problem: it is a regression problem, from an input string to an output integer, or alternately a classification problem, since it computes the result mod 10. The only way I could understand this as a program induction problem is rather obliquely, if the meaning is that any system which is able to compute the result of the calculator evaluation has implicitly replicated internally, in some capacity, the sequence of instructions which are evaluated. I don*t think this is really very clear though; for example, given two calculator programs, one a subprogram of another (e.g., "4*(3+2)" and "3+2"), do the resulting "induced" computations share the same compositional structure? The examples of program induction in section 2 are largely architectures which are explicitly designed to have properties which mimic conventional programming languages (e.g. extra data structures as memories, compositionality, …). In contrast, the calculator example in this paper simply uses an LSTM. That said, I think it*s still a great example! Learning a fast differentiable model which accurately mimics existing non-differentiable model has tons of applications, and has exactly the same challenges regarding synthetic data. I have to say I find the new section 8.3 a bit intuitively challenging; e.g. it*s not clear really how long a waiting time of 48 log(2|X|/.delta) / (p|X|^2 z^2) really is. But, to that end, I appreciate the empirical discussion in 8.4–8.6. I*ve updated my review to increase my score — I lean towards accepting this paper, as it is a timely contribution and I think it is important for future program synthesis papers to take the results here to heart. I*ve reduced my confidence slightly, as I have not fully reviewed the new proof in 8.3.