SYNTHETIC DATASETS FOR NEURAL PROGRAM SYNTHESIS
Year: 2019

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.

heading: 1 INTRODUCTION
text: 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, ∗ricshin@cs.berkeley.edu †Machine Learning at Berkeley
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.

heading: 2 RELATED WORK

heading: 2.1 TRAINING MODELS WITH SYNTHETIC DATA
text: 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.

heading: 2.2 NEURAL PROGRAM INDUCTION AND SYNTHESIS.
text: 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).
Devlin et al. (2017); Parisotto et al. (2017) use neural program synthesis techniques for learning string editing programs in RobustFill. Similarly, Balog et al. (2016) learn array programs in DeepCoder, and Bhupatiraju et al. (2017) learn to compose API calls. Bunel et al. (2018) apply neural program synthesis to the Karel domain we consider in our paper; we use their architecture and dataset. Many of these approaches report high test performance, but good performance on synthetically-specificed programs may not indicate the model’s ability to generalize to arbitrary user-desired programs. 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.

heading: 3 DATA GENERATION METHODOLOGY
text: 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) = (Pq[X = ν(s)] + ε) −1 (
min x∈X Pq[X = x] + ε
) ,
with Pq[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.

heading: 4 APPLICATION TO KAREL: EXPERIMENTS WITH NEW TEST DISTRIBUTIONS
text: 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 {(i1, o1), · · · , (in, on)}, find a Karel program π such that executing π on i1 results in o1, i2 results
in o2, and so on. In the paper, n = 5 unless otherwise specified. An example Karel synthesis task with the I/O examples and the corresponding Karel program to be synthesized is shown in Figure 1.
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.

heading: 4.1 SALIENT VARIABLES IN KAREL
text: 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).

heading: 4.2 CHANGING THE I/O DISTRIBUTION
text: 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 6th 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 rmarker ∼ U(0, 1) and wall ratio rwall ∼ U(0, 1); 3) for each cell (i, j), 0 ≤ i < x, 0 ≤ j < y in the grid, sample mi,j ∼ Bernoulli(rmarker) and wi,j ∼ Bernoulli(rwall); 4) if mi,j = 1 and wi,j = 0, sample marker count mci,j ∼ U{1, . . . 9}, otherwise set mci,j = 0; 5) place walls and markers in grid according to wi,j and mci,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 rwall and rmarker (both between 0 and 1) as well as a distribution Dmarker 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 · rwall cells to contain walls, and xy · rmarker cells for markers; 3) sample mci,j ∼ Dmarker 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 Dmarker 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 Dmarker count. A more negative skew consistently lowered model performance, and this effect was more pronounced at higher values of rmarker.

heading: 4.3 CHANGING THE PROGRAM DISTRIBUTION
text: 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.
1To 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.
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 5L 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.

heading: 5 APPLICATION TO KAREL: CHANGING TRAINING DISTRIBUTIONS
text: 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.

heading: 5.1 TRAINING DATASETS WITH UNIFORM I/O
text: 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.

heading: 5.2 REAL-WORLD BENCHMARKS
text: 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.
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.

heading: 5.3 AUGMENTING DATASET WITH ACTION-ONLY PROGRAMS
text: 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.

heading: 5.4 TRAINING DATASETS WITH NARROWLY DISTRIBUTED I/O
text: 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.

heading: 6 APPLICATION TO CALCULATOR
text: 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.

heading: 6.1 CALCULATOR ENVIRONMENT
text: 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.

heading: 6.2 SALIENT VARIABLES AND METHODOLOGY
text: 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
2 https://github.com/tensorflow/tensor2tensor/blob/8bd81e8fe9dafd4eb1dfa519255bcbe3e33c7ffa/
tensor2tensor/data_generators/algorithmic_math.py
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).

heading: 6.3 RESULTS
text: 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 Dmarker). 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.

heading: 7 CONCLUSION
text: 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.

heading: ACKNOWLEDGEMENTS
text: This material is in part based upon work supported by the National Science Foundation under Grant No. TWC-1409915, Berkeley Deep Drive, and DARPA D3M under Grant No. FA8750-17-2-0091. Any opinions, findings, and conclusions or recommendations expressed in this material are those of the author(s) and do not necessarily reflect the views of the National Science Foundation and DARPA.

heading: A THE KAREL DOMAIN
text: A declarative specification of the space of valid input worlds to Karel programs is shown in Figure 4(b). 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.

heading: B SALIENT VARIABLE HOMOGENIZATION ALGORITHM
text: 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 pmin ← minx∈X C[x]t pcurr ← 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 Pr[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∣∣∣∣Pr[X = x]− 1|X| ∣∣∣∣ ≤ ξ with probability at least 1− δ, where pm = minx∈X Pq[X = x] > 0 and ε has been set to 0.
Proof. We can simplify the probability as
Pr[X = x] = Pq[X = x]/C[x]∑ z∈X Pq[X = z]/C[z]
(for ε = 0; see Probability Simplification Lemma below).
Let α = ξ|X|4 . We have that n > 3 log
2|X| δ
α2pm 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|Pr[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|Pr[X = x] ∈ [1− 4α, 1 + 4α] we thus have that ∣∣∣Pr[X = x]− 1|X| ∣∣∣ ≤ 4α|X| = ξ, completing our proof.
Lemma (Count Bounding). We have that if n > 3 log 2|X| δ
α2pm samples have been drawn from q that
P [ ∃x ∈ X, ∣∣∣∣nPq[X = x]C[x] − 1 ∣∣∣∣ ≥ α] ≤ δ
where pm = minx∈X Pq[X = x]
Proof. We can model C[x] as a sum of n independent Bernoulli trials with probability Pq[X = x]. Using Chernoff bound, we have that
P [C[x] ≥ nPq[X = x](1 + α)] ≤ e−α 2nPq [X=x]/3
and
P [C[x] ≥ nPq[X = x](1− √ 2/3α)] ≤ e−α 2nPq [X=x]/3
Thus, we have by union bound that
P
[ nPq[X = x]
C[x] ≥ 1 1− √ 2/3α ∨ nPq[X = x] C[x] ≤ 1 1 + α
] ≤ 2e−α 2nPq [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
[ nPq[X = x]
C[x] ≥ 1 + α ∨ nPq[X = x] C[x] ≤ 1− α
] ≤ 2e−α 2nPq [X=x]/3
or in other words
P [∣∣∣∣nPq[X = x]C[x] − 1 ∣∣∣∣ ≥ α] ≤ 2e−α2nPq [X=x]/3
Thus we can bound the RHS as
2e−α 2nPq [X=x]/3 ≤ 2e−α 2npm/3 < 2e −α2
3 log 2|X| δ
α2pm pm/3 = 2e− log 2|X| δ = δ
|X|
where the first inequality is since Pq[X = x] ≥ pm and the second is since n > 3 log
2|X| δ
α2pm .
We can again apply union bound to get that
P [ ∃x ∈ X, ∣∣∣∣nPq[X = x]C[x] − 1 ∣∣∣∣ ≥ α] ≤ |X| δX = δ
Lemma (Probability Simplification).
Pr[X = x] = Pq[X = x]/C[x]∑ z∈X Pq[X = z]/C[z]
Proof.
Pr[X = x] = ∑
s∈S:ν(s)=x
Pr[S = s]
= ∑
s∈S:ν(s)=x
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) = ∑ s∈S:ν(s)=x miny∈X C[y] C[ν(s)] q(s)
= miny∈X C[y]
C[x]
∑ s∈S:ν(s)=x q(s)
= miny∈X C[y]
C[x] Pq[X = x]
we have that
Pr[X = x] =
∑ s∈S:ν(s)=x g(s)q(s)∑
y∈X ∑ s′∈S:ν(s′)=y g(s ′)q(s′)
= miny∈X C[y] C[x] Pq[X = x]∑
z∈X miny∈X C[y] C[z] Pq[X = z]
= Pq[X = x]/C[x]∑ z∈X Pq[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) = minx 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 = 1g(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
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 Table 5.

Review summaries:
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.