Natural- to formal-language generation using Tensor Product Representations

  • 2019-11-21 04:20:45
  • Kezhen Chen, Qiuyuan Huang, Hamid Palangi, Paul Smolensky, Kenneth D. Forbus, Jianfeng Gao
  • 0

Abstract

Generating formal-language represented by relational tuples, such as Lispprograms or mathematical expressions, from a natural-language input is anextremely challenging task because it requires to explicitly capture discretesymbolic structural information from the input to generate the output. Moststate-of-the-art neural sequence models do not explicitly capture suchstructure information, and thus do not perform well on these tasks. In thispaper, we propose a new encoder-decoder model based on Tensor ProductRepresentations (TPRs) for Natural- to Formal-language generation, calledTP-N2F. The encoder of TP-N2F employs TPR 'binding' to encode natural-languagesymbolic structure in vector space and the decoder uses TPR 'unbinding' togenerate a sequence of relational tuples, each consisting of a relation (oroperation) and a number of arguments, in symbolic space. TP-N2F considerablyoutperforms LSTM-based Seq2Seq models, creating a new state of the art resultson two benchmarks: the MathQA dataset for math problem solving, and theAlgoList dataset for program synthesis. Ablation studies show that improvementsare mainly attributed to the use of TPRs in both the encoder and decoder toexplicitly capture relational structure information for symbolic reasoning.

 

Quick Read (beta)

Natural- to formal-language generation
using Tensor Product Representations

Kezhen Chen, Qiuyuan Huang, Hamid Palangi, Paul Smolensky§,
Kenneth D. Forbus, Jianfeng Gao
Northwestern University, Evanston, IL
Microsoft Research, Redmond, WA
§Johns Hopkins University, Baltimore, MD
[email protected]
{qihua,hpalangi,psmo,jfgao}@microsoft.com
[email protected]
[email protected]
Kezhen Chen contributed to this work as an intern at Microsoft Research, Redmond WA.
Abstract

Generating formal-language represented by relational tuples, such as Lisp programs or mathematical operations, from natural-language input is a challenging task because it requires explicitly capturing discrete symbolic structural information implicit in the input. Most state-of-the-art neural sequence models do not explicitly capture such structural information, limiting their performance on these tasks. In this paper we propose a new encoder-decoder model based on Tensor Product Representations (TPRs) for Natural- to Formal-language generation, called TP-N2F. The encoder of TP-N2F employs TPR ‘binding’ to encode natural-language symbolic structure in vector space and the decoder uses TPR ‘unbinding’ to generate, in symbolic space, a sequence of relational tuples, each consisting of a relation (or operation) and a number of arguments. On two benchmarks, TP-N2F considerably outperforms LSTM-based seq2seq models, creating new state-of-the-art results: the MathQA dataset for math problem solving, and the AlgoLisp dataset for program synthesis. Ablation studies show that improvements can be attributed to the use of TPRs in both the encoder and decoder to explicitly capture relational structure to support reasoning.

Natural- to formal-language generation
using Tensor Product Representations

Kezhen Chenthanks: Kezhen Chen contributed to this work as an intern at Microsoft Research, Redmond WA., Qiuyuan Huang, Hamid Palangi, Paul Smolensky§,
Kenneth D. Forbus, Jianfeng Gao
Northwestern University, Evanston, IL
Microsoft Research, Redmond, WA
§Johns Hopkins University, Baltimore, MD
[email protected]
{qihua,hpalangi,psmo,jfgao}@microsoft.com
[email protected]
[email protected]

1 INTRODUCTION

When people perform explicit reasoning, they can typically describe the way to the conclusion step by step via relational descriptions. There is ample evidence that relational representations are important for human cognition (e.g., (Gentner2003; Forbus2017; Crouse2018; Chen2018; Chen2019)). Although a rapidly growing number of researchers use deep learning to solve complex symbolic reasoning and language tasks (a recent review is (gao2019neural)), most existing deep learning models, including sequence models such as LSTMs, do not explicitly capture human-like relational structure information.

In this paper we propose a novel neural architecture, TP-N2F, to solve natural- to formal-language generation tasks (N2F). In the tasks we study, math or programming problems are stated in natural-language, and answers are given as programs, sequences of relational representations, to solve the problem. TP-N2F encodes the natural-language symbolic structure of the problem in an input vector space, maps this to a vector in an intermediate space, and uses that vector to produce a sequence of output vectors that are decoded as relational structures. Both input and output structures are modelled as Tensor Product Representations (TPRs) (Smolensky1990). During encoding, NL-input symbolic structures are encoded as vector space embeddings using TPR ‘binding’ (following Palangi2018); during decoding, symbolic constituents are extracted from structure-embedding output vectors using TPR ‘unbinding’ (following Huang2018; Huang2019).

Our contributions in this work are as follows. (i) We propose a role-level analysis of N2F tasks. (ii) We present a new TP-N2F model which gives a neural-network-level implementation of a model solving the N2F task under the role-level description proposed in (i). To our knowledge, this is the first model to be proposed which combines both the binding and unbinding operations of TPRs to achieve generation tasks through deep learning. (iii) State-of-the-art performance on two recently developed N2F tasks shows that the TP-N2F model has significant structure learning ability on tasks requiring symbolic reasoning through program synthesis.

2 Background: Review of Tensor-Product Representation

The TPR mechanism is a method to create a vector space embedding of complex symbolic structures. The type of a symbol structure is defined by a set of structural positions or roles, such as the left-child-of-root position in a tree, or the second-argument-of-R position of a given relation R. In a particular instance of a structural type, each of these roles may be occupied by a particular filler, which can be an atomic symbol or a substructure (e.g., the entire left sub-tree of a binary tree can serve as the filler of the role left-child-of-root). For now, we assume the fillers to be atomic symbols.11 1 When fillers are structures themselves, binding can be used recursively, giving tensors of order higher than 2. In general, binding is done with the tensor product, since conflation with matrix algebra is only possible for order-2 tensors. Our unbinding of relational tuples involves the order-3 TPRs defined in Sec. 3.1.2.

The TPR embedding of a symbol structure is the sum of the embeddings of all its constituents, each constituent comprising a role together with its filler. The embedding of a constituent is constructed from the embedding of a role and the embedding of the filler of that role: these are joined together by the TPR ‘binding’ operation, the tensor (or generalized outer) product .

Formally, suppose a symbolic type is defined by the roles {ri}, and suppose that in a particular instance of that type, 𝚂, role ri is bound by filler fi. The TPR embedding of 𝚂 is the order-2 tensor

𝑻=i𝒇i𝒓i=i𝒇i𝒓i (1)

where {𝒇i} are vector embeddings of the fillers and {𝒓i} are vector embeddings of the roles. In Eq. 1, and below, for notational simplicity we conflate order-2 tensors and matrices.

As a simple example, consider the symbolic type string, and choose roles to be r1= first_element, r2= second_element, etc. Then in the specific string S = cba, the first role r1 is filled by c, and r2 and r3 by b and a, respectively. The TPR for S is 𝒄𝒓1+𝒃𝒓2+𝒂𝒓3, where 𝒂,𝒃,𝒄 are the vector embeddings of the symbols a, b, c, and 𝒓i is the vector embedding of role ri.

A TPR scheme for embedding a set of symbol structures is defined by a decomposition of those structures into roles bound to fillers, an embedding of each role as a role vector, and an embedding of each filler as a filler vector. Let the total number of roles and fillers available be nR,nF, respectively. Define the matrix of all possible role vectors to be 𝑹dR×nR, with column i, [𝑹]:i=𝒓idR, comprising the embedding of ri. Similarly let 𝑭dF×nF be the matrix of all possible filler vectors. The TPR 𝑻dF×dR. Below, dR,nR,dF,nF will be hyper-parameters, while 𝑹,𝑭 will be learned parameter matrices.

Using summation in Eq.1 to combine the vectors embedding the constituents of a structure risks non-recoverability of those constituents given the embedding 𝑻 of the the structure as a whole. The tensor product is chosen as the binding operation in order to enable recovery of the filler of any role in a structure 𝚂 given its TPR 𝑻. This can be done with perfect precision if the embeddings of the roles are linearly independent. In that case the role matrix 𝑹 has a left inverse 𝑼: 𝑼𝑹=𝑰. Now define the unbinding (or dual) vector for role rj, 𝒖j, to be the jth column of 𝑼: U:j. Then, since [𝑰]ji=[𝑼𝑹]ji=𝑼j:𝑹:i=[𝑼:j]𝑹:i=𝒖j𝒓i=𝒓i𝒖j, we have 𝒓i𝒖j=δji. This means that, to recover the filler of rj in the structure with TPR 𝑻, we can take its tensor inner product (or matrix-vector product) with 𝒖j:22 2 When the role vectors are not linearly independent, this operation performs unbinding approximately, taking 𝑼 to be the left pseudo-inverse of 𝑹. Because randomly chosen vectors on the unit sphere in a high-dimensional space are approximately orthogonal, the approximation is often excellent (anonymous2019).

𝑻𝒖j=[i𝒇i𝒓i]𝒖j=i𝒇iδij=𝒇j (2)

In the architecture proposed here, we will make use of both TPR binding using the tensor product with role vectors 𝒓i and TPR unbinding using the tensor inner product with unbinding vectors 𝒖j. Binding will be used to produce the order-2 tensor 𝑻S embedding of the NL problem statement. Unbinding will be used to generate output relational tuples from an order-3 tensor 𝑯. Because they pertain to different representations (of different orders in fact), the binding and unbinding vectors we will use are not related to one another.

3 TP-N2F Model

We propose a general TP-N2F neural network architecture operating over TPRs to solve N2F tasks under a proposed role-level description of those tasks. In this description, natural-language input is represented as a straightforward order-2 role structure, and formal-language relational representations of outputs are represented with a new order-3 recursive role structure proposed here. Figure 1 shows an overview diagram of the TP-N2F model. It depicts the following high-level description.

Figure 1: Overview diagram of TP-N2F.

As shown in Figure 1, while the natural-language input is a sequence of words, the output is a sequence of multi-argument relational tuples such as (RA1A2), a 3-tuple consisting of a binary relation (or operation) R with its two arguments. The “TP-N2F encoder” uses two LSTMs to produce a pair consisting of a filler vector and a role vector, which are bound together with the tensor product. These tensor products, concatenated, comprise the “context” over which attention will operate in the decoder. The sum of the word-level TPRs, flattened to a vector, is treated as a representation of the entire problem statement; it is fed to the “Reasoning MLP”, which transforms this encoding of the problem into a vector encoding the solution. This is the initial state of the “TP-N2F decoder” attentional LSTM, which outputs at each time step an order-3 tensor representing a relational tuple. To generate a correct tuple from decoder operations, the model must learn to give the order-3 tensor the form of a TPR for a (RA1A2) tuple (detailed explanation in Sec. 3.1.2). In the following sections, we first introduce the details of our proposed role-level description for N2F tasks, and then present how our proposed TP-N2F model uses TPR binding and unbinding operations to create a neural network implementation of this description of N2F tasks.

3.1 Role-level description of N2F tasks

In this section, we propose a role-level description of N2F tasks, which specifies the filler/role structures of the input natural-language symbolic expressions and the output relational representations.

3.1.1 Role-level description for natural-language input

Instead of encoding each token of a sentence with a non-compositional embedding vector looked up in a learned dictionary, we use a learned role-filler decomposition to compose a tensor representation for each token. Given a sentence S with n word tokens {w0,w1,,wn-1}, each word token wt is assigned a learned role vector 𝒓t, soft-selected from the learned dictionary 𝑹, and a learned filler vector 𝒇t, soft-selected from the learned dictionary 𝑭 (Sec. 2). The mechanism closely follows that of Palangi2018, and we hypothesize similar results: the role and filler approximately encode the grammatical role of the token and its lexical semantics, respectively.33 3 Although the TPR formalism treats fillers and roles symmetrically, in use, hyperparameters are selected so that the number of available fillers is greater than that of roles. Thus, on average, each role is assigned to more words, encouraging it to take on a more general function, such as a grammatical role. Then each word token wt is represented by the tensor product of the role vector and the filler vector: 𝑻t=𝒇t𝒓t. In addition to the set of all its token embeddings {𝑻0,,𝑻n-1}, the sentence S as a whole is assigned a TPR equal to the sum of the TPR embeddings of all its word tokens: 𝑻S=t=0n-1𝑻t.

Using TPRs to encode natural language has several advantages. First, natural language TPRs can be interpreted by exploring the distribution of tokens grouped by the role and filler vectors they are assigned by a trained model (as in Palangi2018). Second, TPRs avoid the Bag of Word (BoW) confusion (Huang2018): the BoW encoding of Jay saw Kay is the same as the BoW encoding of Kay saw Jay but the encodings are different with TPR embedding, because the role filled by a symbol changes with its context.

3.1.2 Role-level description for relational representations

In this section, we propose a novel recursive role-level description for representing symbolic relational tuples. Each relational tuple contains a relation token and multiple argument tokens. Given a binary relation rel, a relational tuple can be written as (relarg1arg2) where arg1,arg2 indicate two arguments of relation rel. Let us adopt the two positional roles, pirel= argi-of-rel for i=1,2. The filler of role pirel is argi. Now let us use role decomposition recursively, noting that the role pirel can itself be decomposed into a sub-role pi= argi-of-¯ which has a sub-filler rel. Suppose that argi,rel,pi are embedded as vectors 𝒂i,𝒓,𝒑i. Then the TPR encoding of pirel is 𝒓rel𝒑i, so the TPR encoding of filler argi bound to role pirel is 𝒂i(𝒓rel𝒑i). The tensor product is associative, so we can omit parentheses and write the TPR for the formal-language expression, the relational tuple (relarg1arg2), as:

𝑯=𝒂1𝒓rel𝒑1+𝒂2𝒓rel𝒑2. (3)

Given the unbinding vectors 𝒑i for positional role vectors 𝒑i and the unbinding vector 𝒓rel for the vector 𝒓rel that embeds relation rel, each argument can be unbound in two steps as shown in Eqs. 45.

𝑯𝒑i=[𝒂1𝒓rel𝒑1+𝒂2𝒓rel𝒑2]𝒑i=𝒂i𝒓rel (4)
[𝒂i𝒓rel]𝒓rel=𝒂i (5)

Here denotes the tensor inner product, which for the order-3 𝑯 and order-1 𝒑i in Eq. 4 can be defined as [𝑯𝒑i]jk=l[𝑯]jkl[𝒑i]l; in Eq. 5, is equivalent to the matrix-vector product.

Our proposed scheme can be contrasted with the TPR scheme in which (relarg1arg2) is embedded as 𝒓rel𝒂1𝒂2 (e.g., smolensky2016basic; Schlag2018). In that scheme, an n-ary-relation tuple is embedded as an order-(n+1) tensor, and unbinding an argument requires knowing all the other arguments (to use their unbinding vectors). In the scheme proposed here, an n-ary-relation tuple is still embedded as an order-3 tensor: there are just n terms in the sum in Eq. 3, using n position vectors 𝒑1,,𝒑n; unbinding simply requires knowing the unbinding vectors for these fixed position vectors.

In the model, the order-3 tensor 𝑯 of Eq. 3 has a different status than the order-2 tensor 𝑻S of Sec. 3.1.1. 𝑻S is a TPR by construction, whereas 𝑯 is a TPR as a result of successful learning. To generate the output relational tuples, the decoder assumes each tuple has the form of Eq. 3, and performs the unbinding operations which that structure calls for. In Appendix Sec. A.3, it is shown that, if unbinding each of a set of roles from some unknown tensor 𝑻 gives a target set of fillers, then 𝑻 must equal the TPR generated by those role/filler pairs, plus some tensor that is irrelevant because unbinding from it produces the zero vector. In other words, if the decoder succeeds in producing filler vectors that correspond to output relational tuples that match the target, then, as far as what the decoder can see, the tensor that it operates on is the TPR of Eq. 3.

3.1.3 The TP-N2F Scheme for Learning the input-output mapping

To generate formal relational tuples from natural-language descriptions, a learning strategy for the mapping between the two structures is particularly important. As shown in (6), we formalize the learning scheme as learning a mapping function fmapping(), which, given a structural representation of the natural-language input, 𝑻S, outputs a tensor 𝑻F from which the structural representation of the output can be generated. At the role level of description, there’s nothing more to be said about this mapping; how it is modeled at the neural network level is discussed in Sec. 3.2.1.

𝑻F=fmapping(𝑻S) (6)

3.2 The TP-N2F Model for Natural- to Formal-Language Generation

As shown in Figure 1, the TP-N2F model is implemented with three steps: encoding, mapping, and decoding. The encoding step is implemented by the TP-N2F natural-language encoder (TP-N2F Encoder), which takes the sequence of word tokens as inputs, and encodes them via TPR binding according to the TP-N2F role scheme for natural-language input given in Sec. 3.1.1. The mapping step is implemented by an MLP called the Reasoning Module, which takes the encoding produced by the TP-N2F Encoder as input. It learns to map the natural-language-structure encoding of the input to a representation that will be processed under the assumption that it follows the role scheme for output relational-tuples specified in Sec. 3.1.2: the model needs to learn to produce TPRs such that this processing generates correct output programs. The decoding step is implemented by the TP-N2F relational tuples decoder (TP-N2F Decoder), which takes the output from the Reasoning Module (Sec. 3.1.3) and decodes the target sequence of relational tuples via TPR unbinding. The TP-N2F Decoder utilizes an attention mechanism over the individual-word TPRs 𝑻t produced by the TP-N2F Encoder. The detailed implementations are introduced below.

3.2.1 The TP-N2F natural-language Encoder

The TP-N2F encoder follows the role scheme in Sec. 3.1.1 to encode each word token wt by soft-selecting one of nF fillers and one of nR roles. The fillers and roles are embedded as vectors. These embedding vectors, and the functions for selecting fillers and roles, are learned by two LSTMs, the Filler-LSTM and the Role-LSTM. (See Figure 2.) At each time-step t, the Filler-LSTM and the Role-LSTM take a learned word-token embedding 𝒘t as input. The hidden state of the Filler-LSTM, 𝒉Ft, is used to compute softmax scores ukF over nF filler slots, and a filler vector 𝒇t=𝑭𝒖F is computed from the softmax scores (recall from Sec. 2 that 𝑭 is the learned matrix of filler vectors). Similarly, a role vector is computed from the hidden state of the Role-LSTM, 𝒉Rt. fF and fR denote the functions that generate 𝒇t and 𝒓t from the hidden states of the two LSTMs. The token wt is encoded as 𝑻t, the tensor product of 𝒇t and 𝒓t. 𝑻t replaces the hidden vector in each LSTM and is passed to the next time step, together with the LSTM cell-state vector 𝒄t: see (7)–(8). After encoding the whole sequence, the TP-N2F encoder outputs the sum of all tensor products t𝑻t to the next module. We use an MLP, called the Reasoning MLP, for TPR mapping; it takes an order-2 TPR from the encoder and maps it to the initial state of the decoder. Detailed equations and implementation are provided in Sec. A.2.1 of the Appendix.

𝒉Ft=fFiller-LSTM(𝒘t,𝑻t-1,𝒄Ft-1)    𝒉Rt=fRole-LSTM(𝒘t,𝑻t-1,𝒄Rt-1) (7)
𝑻t=𝒇t𝒓t=fF(𝒉Ft)fR(𝒉Rt) (8)
Figure 2: Implementation of the TP-N2F encoder.

3.2.2 The TP-N2F Relational-Tuple Decoder

The TP-N2F Decoder is an RNN that takes the output from the reasoning MLP as its initial hidden state for generating a sequence of relational tuples (Figure 3). This decoder contains an attentional LSTM called the Tuple-LSTM which feeds an unbinding module: attention operates on the context vector of the encoder, consisting of all individual encoder outputs {𝑻t}. The hidden-state 𝑯 of the Tuple-LSTM is treated as a TPR of a relational tuple and is unbound to a relation and arguments. During training, the Tuple-LSTM needs to learn a way to make 𝑯 suitably approximate a TPR. At each time step t, the hidden state 𝑯t of the Tuple-LSTM with attention (The version in luong2015att) (9) is fed as input to the unbinding module, which regards 𝑯t as if it were the TPR of a relational tuple with m arguments possessing the role structure described in Sec. 3.1.2: 𝑯ti=1m𝒂it𝒓relt𝒑i. (In Figure 3, the assumed hypothetical form of 𝑯t, as well as that of 𝑩it below, is shown in a bubble with dashed border.) To decode a binary relational tuple, the unbinding module decodes it from 𝑯t using the two steps of TPR unbinding given in (4)–(5). The positional unbinding vectors 𝒑i are learned during training and shared across all time steps. After the first unbinding step (4), i.e., the inner product of 𝑯t with 𝒑i, we get tensors 𝑩it (10). These are treated as the TPRs of two arguments 𝒂it bound to a relation 𝒓relt. A relational unbinding vector 𝒓relt is computed by a linear function from the sum of the 𝑩it and used to compute the inner product with each 𝑩it to yield 𝒂it, which are treated as the embedding of argument vectors (11). Based on the TPR theory, 𝒓relt is passed to a linear function to get 𝒓relt as the embedding of a relation vector. Finally, the softmax probability distribution over symbolic outputs is computed for relations and arguments separately. In generation, the most probable symbol is selected. (Detailed equations are in Appendix Sec. A.2.3)

𝑯t=Atten(fTuple-LSTM(relt,arg1t,arg2t,𝑯t-1,ct-1),[𝑻0,,𝑻n-1]) (9)
𝑩1t=𝑯t𝒑1    𝑩2t=𝑯t𝒑2 (10)
𝒓relt=flinear(𝑩1t+𝑩2t)    𝒂1t=𝑩1t𝒓relt    𝒂2t=𝑩2t𝒓relt (11)
Figure 3: Implementation of the TP-N2F decoder.

3.3 Inference and The Learning Strategy of the TP-N2F Model

During inference time, natural language questions are encoded via the encoder and the Reasoning MLP maps the output of the encoder to the input of the decoder. We use greedy decoding (selecting the most likely class) to decode one relation and its arguments. The relation and argument vectors are concatenated to construct a new vector as the input for the Tuple-LSTM in the next step.

TP-N2F is trained using back-propagation (rumelhart1986learning) with the Adam optimizer (adam2017) and teacher-forcing. At each time step, the ground-truth relational tuple is provided as the input for the next time step. As the TP-N2F decoder decodes a relational tuple at each time step, the relation token is selected only from the relation vocabulary and the argument tokens from the argument vocabulary. For an input that generates N output relational tuples, the loss is the sum of the cross entropy loss between the true labels L and predicted tokens for relations and arguments as shown in (12).

=i=0N-1(reli,Lreli)+i=0N-1j=12(argji,Largji) (12)

4 EXPERIMENTS

The proposed TP-N2F model is evaluated on two N2F tasks, generating operation sequences to solve math problems and generating Lisp programs. In both tasks, TP-N2F achieves state-of-the-art performance. We further analyze the behavior of the unbinding relation vectors in the proposed model. Results of each task and the analysis of the unbinding relation vectors are introduced in turn. Details of experiments and datasets are described in Sec. A.1 in the Appendix.

4.1 Generating operation sequences to solve math problems

Given a natural-language math problem, we need to generate a sequence of operations (operators and corresponding arguments) from a set of operators and arguments to solve the given problem. Each operation is regarded as a relational tuple by viewing the operator as relation, e.g., (add,n1,n2). We test TP-N2F for this task on the MathQA dataset (Amini2019). The MathQA dataset consists of about 37k math word problems, each with a corresponding list of multi-choice options and the corresponding operation sequence. In this task, TP-N2F is deployed to generate the operation sequence given the question. The generated operations are executed with the execution script from Amini2019 to select a multi-choice answer. As there are about 30% noisy data (where the execution script returns the wrong answer when given the ground-truth program; see Sec. A.1 of the Appendix), we report both execution accuracy (of the final multi-choice answer after running the execution engine) and operation sequence accuracy (where the generated operation sequence must match the ground truth sequence exactly). TP-N2F is compared to a baseline provided by the seq2prog model in Amini2019, an LSTM-based seq2seq model with attention. Our model outperforms both the original seq2prog, designated SEQ2PROG-orig, and the best reimplemented seq2prog after an extensive hyperparameter search, designated SEQ2PROG-best. Table 1 presents the results. To verify the importance of the TP-N2F encoder and decoder, we conducted experiments to replace either the encoder with a standard LSTM (denoted LSTM2TP) or the decoder with a standard attentional LSTM (denoted TP2LSTM). We observe that both the TPR components of TP-N2F are important for achieving the observed performance gain relative to the baseline.

Table 1: Results on MathQA dataset testing set
MODEL Operation Accuracy(%) Execution Accuracy(%)
SEQ2PROG-orig 59.4 51.9
SEQ2PROG-best 66.97 54.0
LSTM2TP (ours) 68.21 54.61
TP2LSTM (ours) 68.84 54.61
TP-N2F (ours) 71.89 55.95

4.2 Generating program trees from natural-language descriptions

Generating Lisp programs requires sensitivity to structural information because Lisp code can be regarded as tree-structured. Given a natural-language query, we need to generate code containing function calls with parameters. Each function call is a relational tuple, which has a function as the relation and parameters as arguments. We evaluate our model on the AlgoLisp dataset for this task and achieve state-of-the-art performance. The AlgoLisp dataset (Polosukhin2018) is a program synthesis dataset. Each sample contains a problem description, a corresponding Lisp program tree, and 10 input-output testing pairs. We parse the program tree into a straight-line sequence of tuples (same style as in MathQA). AlgoLisp provides an execution script to run the generated program and has three evaluation metrics: the accuracy of passing all test cases (Acc), the accuracy of passing 50% of test cases (50p-Acc), and the accuracy of generating an exactly matching program (M-Acc). AlgoLisp has about 10% noisy data (details in the Appendix), so we report results both on the full test set and the cleaned test set (in which all noisy testing samples are removed). TP-N2F is compared with an LSTM seq2seq with attention model, the Seq2Tree model in Polosukhin2018, and a seq2seq model with a pre-trained tree decoder from the Tree2Tree autoencoder (SAPS) reported in Bednarek2019. As shown in Table 2, TP-N2F outperforms all existing models on both the full test set and the cleaned test set. Ablation experiments with TP2LSTM and LSTM2TP show that, for this task, the TP-N2F Decoder is more helpful than TP-N2F Encoder. This may be because lisp codes rely more heavily on structure representations.

Table 2: Results of AlgoLisp dataset
Full Testing Set Cleaned Testing Set
MODEL (%) Acc 50p-Acc M-Acc Acc 50p-Acc M-Acc
Seq2Tree 61.0
LSTM2LSTM+atten 67.54 70.89 75.12 76.83 78.86 75.42
TP2LSTM (ours) 72.28 77.62 79.92 77.67 80.51 76.75
LSTM2TPR (ours) 75.31 79.26 83.05 84.44 86.13 83.43
SAPSpre-VH-Att-256 83.80 87.45 92.98 94.15
TP-N2F (ours) 84.02 88.01 93.06 93.48 94.64 92.78

4.3 Interpretation of learned structure

To interpret the structure learned by the model, we extract the trained unbinding relation vectors from the TP-N2F Decoder and reduce the dimension of vectors via Principal Component Analysis. K-means clustering results on the average vectors are presented in Figure 4 and Figure 5 (in Appendix A.6). Results show that unbinding vectors for operators or functions with similar semantics tend to be close to each other. For example, with 5 clusters in the MathQA dataset, arithmetic operators such as add, subtract, multiply, divide are clustered together, and operators related to square or volume of geometry are clustered together. With 4 clusters in the AlgoLisp dataset, partial/lambda functions and sort functions are in one cluster, and string processing functions are clustered together. Note that there is no direct supervision to inform the model about the nature of the operations, and the TP-N2F decoder has induced this role structure using weak supervision signals from question/operation-sequence-answer pairs. More clustering results are presented in the Appendix A.6.

5 Related work

N2F tasks include many different subtasks such as symbolic reasoning or semantic parsing (spsurvey2019; Cai2019; LiaoQSE2018; Amini2019; Polosukhin2018; Bednarek2019). These tasks require models with strong structure-learning ability. TPR is a promising technique for encoding symbolic structural information and modeling symbolic reasoning in vector space. TPR binding has been used for encoding and exploring grammatical structural information of natural language (Palangi2018; Huang2019). TPR unbinding has also been used to generate natural language captions from images (Huang2018). Some researchers use TPRs for modeling deductive reasoning processes both on a rule-based model and deep learning models in vector space (Lee2016; smolensky2016basic; Schlag2018). However, none of these previous models takes advantage of combining TPR binding and TPR unbinding to learn structure representation mappings explicitly, as done in our model. Although researchers are paying increasing attention to N2F tasks, most of the proposed models either do not encode structural information explicitly or are specialized to particular tasks. Our proposed TP-N2F neural model can be applied to many tasks.

6 CONCLUSION AND FUTURE WORK

In this paper we propose a new scheme for neural-symbolic relational representations and a new architecture, TP-N2F, for formal-language generation from natural-language descriptions. To our knowledge, TP-N2F is the first model that combines TPR binding and TPR unbinding in the encoder-decoder fashion. TP-N2F achieves the state-of-the-art on two instances of N2F tasks, showing significant structure learning ability. The results show that both the TP-N2F encoder and the TP-N2F decoder are important for improving natural- to formal-language generation. We believe that the interpretation and symbolic structure encoding of TPRs are a promising direction for future work. We also plan to combine large-scale deep learning models such as BERT with TP-N2F to take advantage of structure learning for other generation tasks.

References

Appendix A Appendix

A.1 Implementations of TP-N2F for experiments

In this section, we present details of the experiments of TP-N2F on the two datasets. We present the implementation of TP-N2F on each dataset.

The MathQA dataset consists of about 37k math word problems ((80/12/8)% training/dev/testing problems), each with a corresponding list of multi-choice options and an straight-line operation sequence program to solve the problem. An example from the dataset is presented in the Appendix A.4. In this task, TP-N2F is deployed to generate the operation sequence given the question. The generated operations are executed to generate the solution for the given math problem. We use the execution script from Amini2019 to execute the generated operation sequence and compute the multi-choice accuracy for each problem. During our experiments we observed that there are about 30% noisy examples (on which the execution script fails to get the correct answer on the ground truth program). Therefore, we report both execution accuracy (the final multi-choice answer after running the execution engine) and operation sequence accuracy (where the generated operation sequence must match the ground truth sequence exactly).

The AlgoLisp dataset (Polosukhin2018) is a program synthesis dataset, which has 79k/9k/10k training/dev/testing samples. Each sample contains a problem description, a corresponding Lisp program tree, and 10 input-output testing pairs. We parse the program tree into a straight-line sequence of commands from leaves to root and (as in MathQA) use the symbol #i to indicate the result of the ith command (generated previously by the model). A dataset sample with our parsed command sequence is presented in the Appendix A.4. AlgoLisp provides an execution script to run the generated program and has three evaluation metrics: accuracy of passing all test cases (Acc), accuracy of passing 50% of test cases (50p-Acc), and accuracy of generating an exactly matched program (M-Acc). AlgoLisp has about 10% noise data (where the execution script fails to pass all test cases on the ground truth program), so we report results both on the full test set and the cleaned test set (in which all noisy testing samples are removed).

We use dR,nR,dF,nF to indicate the TP-N2F encoder hyperparameters, the dimension of role vectors, the number of roles, the dimension of filler vectors and the number of fillers. dRel,dArg,dPos indicate the TP-N2F decoder hyper-parameters, the dimension of relation vectors, the dimension of argument vectors, and the dimension of position vectors.

In the experiment on the MathQA dataset, we use nF=150, nR=50, dF=30, dR=20, dRel=20, dArg=10, dPos=5 and we train the model for 60 epochs with learning rate 0.00115. The reasoning module only contains one layer. As most of the math operators in this dataset are binary, we replace all operators taking three arguments with a set of binary operators based on hand-encoded rules, and for all operators taking one argument, a padding symbol is appended. For the baseline SEQ2PROG-orig, TP2LSTM and LSTM2TP, we use hidden size 100, single-direction, one-layer LSTM. For the SEQ2PROG-best, we performed a hyperparameter search on the hidden size for both encoder and decoder; the best score is reported.

In the experiment on the AlgoLisp dataset, we use nF=150, nR=50, dF=30, dR=30, dRel=30, dArg=20, dPos=5 and we train the model for 50 epochs with learning rate 0.00115. We also use one-layer in the reasoning module like in MathQA. For this dataset, most function calls take three arguments so we simply add padding symbols for those functions with fewer than three arguments.

A.2 Detailed equations of TP-N2F

A.2.1 TP-N2F encoder

Filler-LSTM in TP-N2F encoder

This is a standard LSTM, governed by the equations:

𝒇ft=φ(𝑼ff𝒘t+𝑽ff(𝑻t-1)+𝒃ff) (13)
𝒈ft=tanh(𝑼fg𝒘t+𝑽fg(𝑻t-1)+𝒃fg) (14)
𝒊ft=φ(𝑼fi𝒘t+𝑽fi(𝑻t-1)+𝒃fi) (15)
𝒐ft=φ(𝑼fo𝒘t+𝑽fo(𝑻t-1)+𝒃fo) (16)
𝒄ft=𝒇ft𝒄ft-1+𝒊ft𝒈ft (17)
𝒉ft=𝒐fttanh(𝒄ft) (18)

φ,tanh are the logistic sigmoid and tanh functions applied elementwise. flattens (reshapes) a matrix in dF×dR into a vector in dT, where dT=dFdR. is elementwise multiplication. The variables have the following dimensions:

𝒇ft,𝒈ft,𝒊ft,𝒐ft,𝒄ft,𝒉ft,𝒃ff,𝒃fg,𝒃fi,𝒃fo,(𝑻t-1)dT
wtd
𝑼ff,𝑼fg,𝑼fi,𝑼fodT×d
𝑽ff,𝑽fg,𝑽fi,𝑽fodT×dT

Filler vector

The filler vector for input token wt is 𝒇t, defined through an attention vector over possible fillers, 𝒂ft:

𝒂ft=softmax((𝑾fa𝒉ft)/T) (19)
𝒇t=𝑾f𝒂ft (20)

(Wf is the same as 𝑭 of Sec. 2.) The variables’ dimensions are:

𝑾fanF×dT
𝒂ftnF
𝑾fdF×nF
𝒇tdF

T is the temperature factor, which is fixed at 0.1.

Role-LSTM in TP-N2F encoder

Similar to the Filler-LSTM, the Role-LSTM is also a standard LSTM, governed by the equations:

𝒇rt=φ(𝑼rf𝒘t+𝑽rf(𝑻t-1)+𝒃rf) (21)
𝒈rt=tanh(𝑼rg𝒘t+𝑽rg(𝑻t-1)+𝒃rg) (22)
𝒊rt=φ(𝑼ri𝒘t+𝑽ri(𝑻t-1)+𝒃ri) (23)
𝒐rt=φ(𝑼ro𝒘t+𝑽ro(𝑻t-1)+𝒃ro) (24)
𝒄rt=𝒇rt𝒄rt-1+𝒊rt𝒈rt (25)
𝒉rt=𝒐rttanh(𝒄rt) (26)

The variable dimensions are:

𝒇rt,𝒈rt,𝒊rt,𝒐rt,𝒄rt,𝒉rt,𝒃rf,𝒃rg,𝒃ri,𝒃ro,(𝑻t-1)dT
wtd
𝑼rf,𝑼rg,𝑼ri,𝑼rodT×d
𝑽rf,𝑽rg,𝑽ri,𝑽rodT×dT

Role vector

The role vector for input token wt is determined analogously to its filler vector:

𝒂rt=softmax((𝑾ra𝒉rt)/T) (27)
𝒓t=𝑾r𝒂rt (28)

The dimensions are:

𝑾ranR×dT
𝒂rtnR
𝑾rdR×nR
𝒓tdR

Binding

The TPR for the filler/role binding for token wt is then:

𝑻t=𝒓t𝒇t (29)

where

𝑻tdR×dF

A.2.2 Structure Mapping

𝑯0=fmapping(𝑻t) (30)

𝑯0dH, where dH=dA,dO,dP are dimension of argument vector, operator vector and position vector. fmapping is implemented with a MLP (linear layer followed by a tanh) for mapping the 𝑻tdT to the initial state of decoder 𝑯0.

A.2.3 TP-N2F decoder

Tuple-LSTM

The output tuples are also generated via a standard LSTM:

𝒘dt=γ(𝒘Relt-1,𝒘Arg1t-1,𝒘Arg2t-1) (31)
𝒇t=φ(𝑼f𝒘dt+𝑽f(𝑯t-1)+𝒃f) (32)
𝒈t=tanh(𝑼g𝒘dt+𝑽g(𝑯t-1)+𝒃g) (33)
𝒊t=φ(𝑼i𝒘dt+𝑽i(𝑯t-1)+𝒃i) (34)
𝒐t=φ(𝑼o𝒘dt+𝑽o(𝑯t-1)+𝒃o) (35)
𝒄t=𝒇t𝒄t-1+𝒊t𝒈t (36)
𝒉inputt=𝒐ttanh(𝒄t) (37)
𝑯t=Atten(𝒉inputt,[𝑻0,,𝑻n-1]) (38)

Here, γ is the concatenation function. 𝒘Relt-1 is the trained embedding vector for the Relation of the input binary tuple, 𝒘Arg1t-1 is the embedding vector for the first argument and 𝒘Arg2t-1 is the embedding vector for the second argument. Then the input for the Tuple LSTM is the concatenation of the embedding vectors of relation and arguments, with dimension ddec.

𝒇t,𝒈t,𝒊t,𝒐t,𝒄t,𝒉inputt,𝒃f,𝒃g,𝒃i,𝒃o,(𝑯t-1)dH
𝒘dtddec
𝑼f,𝑼g,𝑼i,𝑼odH×ddec
𝑽f,𝑽g,𝑽i,𝑽odH×dH
𝑯tdH

Atten is the attention mechanism used in luong2015att, which computes the dot product between 𝒉inputt and each 𝑻t. Then a linear function is used on the concatenation of 𝒉inputt and the softmax scores on all dot products to generate 𝑯t. The following equations show the attention mechanism:

𝒅t=score(𝒉inputt,𝑪T) (39)
𝒔t=𝑪Tsoftmax(𝒅t) (40)
𝑯t=𝑲γ(𝒉inputt,𝒔t) (41)

score is the score function of the attention. In this paper, the score function is dot product.

𝑪TdH×n
𝒅tn
𝒔tdH
𝑲dH×(dT+n)

Unbinding

At each timestep t, the 2-step unbinding process described in Sec. 3.1.2 operates first on an encoding of the triple as a whole, 𝑯, using two unbinding vectors 𝒑i that are learned but fixed for all tuples. This first unbinding gives an encoding of the two operator-argument bindings, 𝑩i. The second unbinding operates on the 𝑩i, using a generated unbinding vector for the operator, 𝒓rel, giving encodings of the arguments, 𝒂i. The generated unbinding vector for the operator, 𝒓, and the generated encodings of the arguments, 𝒂i, each produce a probability distribution over symbolic operator outputs Rel and symbolic argument outputs Argi; these probabilities are used in the cross-entropy loss function. For generating a single symbolic output, the most-probable symbols are selected.

𝑩1t=𝑯t𝒑1 (42)
𝑩2t=𝑯t𝒑2 (43)
𝒓relt=𝑾dual(B1t+B2t) (44)
𝒂1t=𝑩1t𝒓relt (45)
𝒂2t=𝑩2t𝒓relt (46)
𝒍rrelt=𝑳rrelt𝒓relt (47)
𝒍a1t=𝑳at𝒂1t (48)
𝒍a2t=𝑳at𝒂2t (49)
Relt=argmax(softmax(𝒍rt)) (50)
Arg1t=argmax(softmax(𝒍a1t)) (51)
Arg2t=argmax(softmax(𝒍a2t)) (52)

The dimensions are:

𝒓reltdO
𝒂1t,𝒂2tdA
𝒑1,𝒑2dP
𝑩1t,𝑩2tdA×dO
𝑾dualdH
𝑳rtnO×dO
𝑳atnA×dA
𝒍rtnR
𝒍a1t,𝒍a2tnA

A.3 The tensor that is input to the decoder’s Unbinding Module is a TPR

Here we show that, if learning is successful, the order-3 tensor 𝑯 that each iteration of the decoder’s Tuple LSTM feeds to the decoder’s Unbinding Module (Figure 3) will be a TPR of the form assumed in Eq. 3, repeated here:

𝑯=j𝒂j𝒓rel𝒑j. (53)

The operations performed by the decoder are given in Eqs. 45, and Eqs. 1011, rewritten here:

𝑯𝒑i=𝒒i (54)
𝒒i𝒓rel=𝒂i (55)

This is the standard TPR unbinding operation, used recursively: first with the unbinding vectors for positions, 𝒑i, then with the unbinding vector for the operator, 𝒓rel. It therefore suffices to analyze a single unbinding; the result can then be used recursively. This in effect reduces the problem to the order-2 case. What we will show is: given a set of unbinding vectors {𝒓i} which are dual to a set of role vectors {𝒓i}, with i ranging over some index set I, if 𝑯 is an order-2 tensor such that

𝑯𝒓i=𝒇i,iI (56)

then

𝑯=iI𝒇i𝒓i+𝒁𝑯TPR+𝒁 (57)

for some tensor 𝒁 that annihilates all the unbinding vectors:

𝒁𝒓i=𝟎,iI. (58)

If learning is successful, the processing in the decoder will generate the target relational tuple (R,A1,A2) by obeying Eq. 54 in the first unbinding, where we have 𝒓i=𝒑i,𝒇i=𝒒i,I={1,2}, and obeying Eq. 55 in the second unbinding, where we have 𝒓i=𝒓rel,𝒇i=𝒂i, with I= the set containing only the null index.

Treat rank-2 tensors as matrices; then unbinding is simply matrix-vector multiplication. Assume the set of unbinding vectors is linearly independent (otherwise there would in general be no way to satisfy Eq. 56 exactly, contrary to assumption). Then expand the set of unbinding vectors, if necessary, into a basis {𝒓k}kKI. Find the dual basis, with 𝒓k dual to 𝒓k (so that 𝒓l𝒓j=δlj). Because {𝒓k}kK is a basis, so is {𝒓k}kK, so any matrix 𝑯 can be expanded as 𝑯=kK𝒗k𝒓k. Since 𝑯𝒓i=𝒇i,iI are the unbinding conditions (Eq. 56), we must have 𝒗i=𝒇i,iI. Let 𝑯TPRiI𝒇i𝒓i. This is the desired TPR, with fillers 𝒇i bound to the role vectors 𝒓i which are the duals of the unbinding vectors 𝒓i (iI). Then we have 𝑯=𝑯TPR+𝒁 (Eq. 57) where 𝒁jK,jI𝒗j𝒓j; so 𝒁𝒓i=𝟎,iI (Eq. 58). Thus, if training is successful, the model must have learned how to feed the decoder with order-3 TPRs with the structure posited in Eq. 53.

The argument so far addresses the case where the unbinding vectors are linearly independent, making it possible to satisfy Eq. 56 exactly. In relatively high-dimensional vector spaces, it will often happen that even when the number of unbinding vectors exceeds the dimension of their space by a factor of 2 or 3 (which applies to the TP-N2F models presented here), there is a set of role vectors {𝒓k}kK approximately dual to {𝒓k}kK, such that 𝒓l𝒓j=δljl,jK holds to a good approximation. (If the distribution of normalized unbinding vectors is approximately uniform on the unit sphere, then choosing the approximate dual vectors to equal the unbinding vectors themselves will do, since they will be nearly orthonormal (anonymous2019). If the {𝒓k}kK are not normalized, we just rescale the role vectors, choosing 𝒓k=𝒓k/𝒓k2.) When the number of such role vectors exceeds the dimension of the embedding space, they will be overcomplete, so while it is still true that any matrix 𝑯 can be expanded as above (𝑯=kK𝒗k𝒓k), this expansion will no longer be unique. So while it remains true that 𝑯 a TPR, it is no longer uniquely decomposable into filler/role pairs. The claim above does not claim uniqueness in this sense, and remains true.)

A.4 Dataset samples

A.4.1 Data sample from MathQA dataset

Problem: The present polulation of a town is 3888. Population increase rate is 20%. Find the population of town after 1 year?
Options: a) 2500, b) 2100, c) 3500, d) 3600, e) 2700
Operations: multiply(n0,n1), divide(#0,const-100), add(n0,#1)

A.4.2 Data sample from AlgoLisp dataset

Problem: Consider an array of numbers and a number, decrements each element in the given array by the given number, what is the given array?
Program Nested List: (map a (partial1 b –))
Command-Sequence: (partial1 b –), (map a #0)

A.5 Generated programs comparison

In this section, we display some generated samples from the two datasets, where the TP-N2F model generates correct programs but LSTM-Seq2Seq does not.

Question: A train running at the speed of 50 km per hour crosses a post in 4 seconds. What is the length of the train?
TP-N2F(correct):
(multiply,n0,const1000) (divide,#0,const3600) (multiply,n1,#1)
LSTM(wrong):
(multiply,n0,const0.2778) (multiply,n1,#0)

Question: 20 is subtracted from 60 percent of a number, the result is 88. Find the number?
TP-N2F(correct):
(add,n0,n2) (divide,n1,const100) (divide,#0,#1)
LSTM(wrong):
(add,n0,n2) (divide,n1,const100) (divide,#0,#1) (multiply,#2,n3) (subtract,#3,n0)

Question: The population of a village is 14300. It increases annually at the rate of 15 percent. What will be its population after 2 years?
TP-N2F(correct):
(divide,n1,const100) (add,#0,const1) (power,#1,n2) (multiply,n0,#2)
LSTM(wrong):
(multiply,const4,const100) (sqrt,#0)

Question: There are two groups of students in the sixth grade. There are 45 students in group a, and 55 students in group b. If, on a particular day, 20 percent of the students in group a forget their homework, and 40 percent of the students in group b forget their homework, then what percentage of the sixth graders forgot their homework?
TP-N2F(correct):
(add,n0,n1) (multiply,n0,n2) (multiply,n1,n3) (divide,#1,const100) (divide,#2,const100) (add,#3,#4) (divide,#5,#0) (multiply,#6,const100)
LSTM(wrong):
(multiply,n0,n1) (subtract,n0,n1) (divide,#0,#1)

Question: 1 divided by 0.05 is equal to
TP-N2F(correct):
(divide,n0,n1)
LSTM(wrong):
(divide,n0,n1) (multiply,n2,#0)

Question: Consider a number a, compute factorial of a
TP-N2F(correct):
( ¡=,arg1,1 ) ( -,arg1,1 ) ( self,#1 ) ( *,#2,arg1 ) ( if,#0,1,#3 ) ( lambda1,#4 ) ( invoke1,#5,a )
LSTM(wrong):
( ¡=,arg1,1 ) ( -,arg1,1 ) ( self,#1 ) ( *,#2,arg1 ) ( if,#0,1,#3 ) ( lambda1,#4 ) ( len,a ) ( invoke1,#5,#6 )

Question: Given an array of numbers and numbers b and c, add c to elements of the product of elements of the given array and b, what is the product of elements of the given array and b?
TP-N2F(correct):
( partial, b,* ) ( partial1,c,+ ) ( map,a,#0 ) ( map,#2,#1 )
LSTM(wrong):
( partial1,b,+ ) ( partial1,c,+ ) ( map,a,#0 ) ( map,#2,#1 )

Question: You are given an array of numbers a and numbers b , c and d , let how many times you can replace the median in a with sum of its digits before it becomes a single digit number and b be the coordinates of one end and c and d be the coordinates of another end of segment e , your task is to find the length of segment e rounded down
TP-N2F(correct):
( digits arg1 ) ( len #0 ) ( == #1 1 ) ( digits arg1 ) ( reduce #3 0 + ) ( self #4 ) ( + 1 #5 ) ( if #2 0 #6 ) ( lambda1 #7 ) ( sort a ) ( len a ) ( / #10 2 ) ( deref #9 #11 ) ( invoke1 #8 #12 ) ( - #13 c ) ( digits arg1 ) ( len #15 ) ( == #16 1 ) ( digits arg1 ) ( reduce #18 0 + ) ( self #19 ) ( + 1 #20 ) ( if #17 0 #21 ) ( lambda1 #22 ) ( sort a ) ( len a ) ( / #25 2 ) ( deref #24 #26 ) ( invoke1 #23 #27 ) ( - #28 c ) ( * #14 #29 ) ( - b d ) ( - b d ) ( * #31 #32 ) ( + #30 #33 ) ( sqrt #34 ) ( floor #35 )
LSTM(wrong): ( digits arg1 ) ( len #0 ) ( == #1 1 ) ( digits arg1 ) ( reduce #3 0 + ) ( self #4 ) ( + 1 #5 ) ( if #2 0 #6 ) ( lambda1 #7 ) ( sort a ) ( len a ) ( / #10 2 ) ( deref #9 #11 ) ( invoke1 #8 #12 c ) ( - #13 ) ( - b d ) ( - b d ) ( * #15 #16 ) ( * #14 #17 ) ( + #18 ) ( sqrt #19 ) ( floor #20 )

Question: Given numbers a , b , c and e , let d be c , reverse digits in d , let a and the number in the range from 1 to b inclusive that has the maximum value when its digits are reversed be the coordinates of one end and d and e be the coordinates of another end of segment f , find the length of segment f squared
TP-N2F(correct):
( digits c ) ( reverse #0 ) ( * arg1 10 ) ( + #2 arg2 ) ( lambda2 #3 ) ( reduce #1 0 #4 ) ( - a #5 ) ( digits c ) ( reverse #7 ) ( * arg1 10 ) ( + #9 arg2 ) ( lambda2 #10 ) ( reduce #8 0 #11 ) ( - a #12 ) ( * #6 #13 ) ( + b 1 ) ( range 0 #15 ) ( digits arg1 ) ( reverse #17 ) ( * arg1 10 ) ( + #19 arg2 ) ( lambda2 #20 ) ( reduce #18 0 #21 ) ( digits arg2 ) ( reverse #23 ) ( * arg1 10 ) ( + #25 arg2 ) ( lambda2 #26 ) ( reduce #24 0 #27 ) ( ¿ #22 #28 ) ( if #29 arg1 arg2 ) ( lambda2 #30 ) ( reduce #16 0 #31 ) ( - #32 e ) ( + b 1 ) ( range 0 #34 ) ( digits arg1 ) ( reverse #36 ) ( * arg1 10 ) ( + #38 arg2 ) ( lambda2 #39 ) ( reduce #37 0 #40 ) ( digits arg2 ) ( reverse #42 ) ( * arg1 10 ) ( + #44 arg2 ) ( lambda2 #45 ) ( reduce #43 0 #46 ) ( ¿ #41 #47 ) ( if #48 arg1 arg2 ) ( lambda2 #49 ) ( reduce #35 0 #50 ) ( - #51 e ) ( * #33 #52 ) ( + #14 #53 )
LSTM(wrong):
( - a d ) ( - a d ) ( * #0 #1 ) ( digits c ) ( reverse #3 ) ( * arg1 10 ) ( + #5 arg2 ) ( lambda2 #6 ) ( reduce #4 0 #7 ) ( - #8 e ) ( + b 1 ) ( range 0 #10 ) ( digits arg1 ) ( reverse #12 ) ( * arg1 10 ) ( + #14 arg2 ) ( lambda2 #15 ) ( reduce #13 0 #16 ) ( digits arg2 ) ( reverse #18 ) ( * arg1 10 ) ( + #20 arg2 ) ( lambda2 #21 ) ( reduce #19 0 #22 ) ( ¿ #17 #23 ) ( if #24 arg1 arg2 ) ( lambda2 #25 ) ( reduce #11 0 #26 ) ( - #27 e ) ( * #9 #28 ) ( + #2 #29 )

A.6 Unbinding relation vector clustering

We run K-means clustering on both datasets with k=3,4,5,6 clusters and the results are displayed in Figure 4 and Figure 5. As described before, unbinding-vectors for operators or functions with similar semantics tend to be closer to each other. For example, in the MathQA dataset, arithmetic operators such as add, subtract, multiply, divide are clustered together at middle, and operators related to geometry such as square or volume are clustered together at bottom left. In AlgoLisp dataset, basic arithmetic functions are clustered at middle, and string processing functions are clustered at right.

Figure 4: MathQA clustering results
Figure 5: AlgoLisp clustering results