Title: ENHANCING THE TRANSFORMER WITH EXPLICIT RELATIONAL ENCODING FOR MATH PROBLEM SOLVING

Abstract: We incorporate Tensor-Product Representations within the Transformer in order to better support the explicit representation of relation structure. Our Tensor-Product Transformer (TP-Transformer) sets a new state of the art on the recentlyintroduced Mathematics Dataset containing 56 categories of free-form math wordproblems. The essential component of the model is a novel attention mechanism, called TP-Attention, which explicitly encodes the relations between each Transformer cell and the other cells from which values have been retrieved by attention. TP-Attention goes beyond linear combination of retrieved values, strengthening representation-building and resolving ambiguities introduced by multiple layers of standard attention. The TP-Transformer's attention maps give better insights into how it is capable of solving the Mathematics Dataset's challenging problems. Pretrained models and code will be made available after publication.

1. INTRODUCTION:

In this paper we propose a variation of the Transformer (Vaswani et al., 2017) that is designed to allow it to better incorporate structure into its representations. We test the proposal on a task where structured representations are expected to be particularly helpful: math word-problem solving, where, among other things, correctly parsing expressions and compositionally evaluating them is crucial. Given as input a free-form math question in the form of a character sequence like Let r(g) be the second derivative of 2 * g ** 3/3 -21 * g ** 2/2 + 10 * g. Let z be r(7). Factor -z * s + 6 -9 * s ** 2 + 0 * s + 6 * s ** 2., the model must produce an answer matching the specified target character-sequence -(s + 3) * (3 * s -2) exactly. Our proposed model is trained end-to-end and infers the correct answer for novel examples without any task-specific structural biases.

We begin by viewing the Transformer as a kind of Graph Neural Network (e.g., Gori et al., 2005) . For concreteness, consider the encoder component of a Transformer with H heads. When the h th head of a cell t of layer l issues a query and as a result concentrates its self-attention distribution on another cell t in layer l, we can view these two cells as joined by an edge in an information-flow graph: the information content at t in effect passes via this edge to affect the state of t. The strength of this attention can be viewed as a weight on this edge, and the index h of the head can be viewed as a label. Thus, each layer of the Transformer can be viewed as a complete, directed, weighted, labeled graph. Prior NLP work has interpreted certain edges of these graphs in terms of linguistic relations (Sec. 7), and we wish to enrich the relation structure of these graphs to better support the explicit representation of relations within the Transformer.

Here we propose to replace each of the discrete edge labels 1, . . . , H, with a relation vector: we create a bona fide representational space for the relations being learned by the Transformer. This makes it possible for the hidden representation at each cell to approximate the vector embedding of a symbolic structure built from the relations generated by that cell. This embedding is a Tensor-Product Representation (TPR; Smolensky, 1990) in an end-to-end-differentiable TPR system (Schlag & Schmidhuber, 2018; Schmidhuber, 1992) that learns "internal spotlights of attention" (Schmidhuber, 1993) . TPRs provide a general method for embedding symbol structures in vector spaces. TPRs support compositional processing by directly encoding constituent structure: the representation of a structure is the sum of the representation of its constituents. The representation of each constituent is built compositionally from two vectors: one vector that embeds the content of the constituent, the 'filler' -here, the vector returned by attention -and a second vector that embeds the structural role it fills -here, a relation conceptually labeling an edge of the attention graph. The vector that embeds a filler and the vector that embeds the role it fills are bound together by the tensor product to form the tensor that embeds the constituent that they together define. 1 The relations here, and the structures they define, are learned unsupervised by the Transformer in service of a task; post-hoc analysis is then required to interpret those roles.

In the new model, the TP-Transformer, each head of each cell generates a key-, value-and queryvector, as in the Transformer, but additionally generates a role-vector (which we refer to in some contexts as a 'relation vector'). The query is interpreted as seeking the appropriate filler for that role (or equivalently, the appropriate string-location for fulfilling that relation). Each head binds that filler to its role via the tensor product (or some contraction of it), and these filler/role bindings are summed to form the TPR of a structure with H constituents (details in Sec. 2).

An interpretation of an actual learned relation illustrates this (see Fig. 4 in Sec. 5.2). One head of our trained model can be interpreted as partially encoding the relation second-argument-of. The toplayer cell dominating an input digit seeks the operator of which the digit is in the second-argument role. That cell generates a vector r t signifying this relation, and retrieves a value vector v t describing the operator from position t that stands in this relation. The result of this head's attention is then the binding of filler v t to role r t ; this binding is added to the bindings resulting from the cell's other attention heads.

On the Mathematics Dataset (Sec. 3), the new model sets a new state of the art for the overall accuracy (Sec. 4), and for all the individual-problem-type module accuracies (Fig. 2 ). Initial results of interpreting the learned roles for the arithmetic-problem module show that they include a good approximation to the second-argument role of the division operator and that they distinguish between numbers in the numerator and denominator roles (Sec. 5).

More generally, it is shown that Multi-Head Attention layers not only capture a subspace of the attended cell but capture nearly the full information content (Sec. 6.1). An argument is provided that multiple layers of standard attention suffer from the binding problem, and it is shown theoretically how the proposed TP-Attention avoids such ambiguity (Sec. 6.2). The paper closes with a discussion of related work (Sec. 7) and a conclusion (Sec. 8).

2. THE TP-TRANSFORMER:

The TP-Transformer's encoder network, like the Transformer's encoder (Vaswani et al., 2017) , can be described as a 2-dimensional lattice of cells (t, l) where t = 1, ..., T are the sequence elements of the input and l = 1, ..., L are the layer indices with l = 0 as the embedding layer. All cells share the same topology and the cells of the same layer share the same weights. More specifically, each cell consists of an initial layer normalization (LN) followed by a TP-Multi-Head Attention (TPMHA) sub-layer followed by a fully-connected feed-forward (FF) sub-layer. Each sub-layer is followed by layer normalization (LN) and by a residual connection (as in the original Transformer; Eq. 1). Our cell structure follows directly from the official TensorFlow source code by Vaswani et al. (2017) but with regular Multi-Head Attention replaced by our TPMHA layer.

The input into cell t,l is the output of cell t,l-1 and doesn't depend on the state of any other cells of the same layer, which allows a layer's outputs to be computed in parallel. h t,l = z t,l + TPMHA(LN(z t,l ), LN(z 1:T,l )) z t,l+1 = LN(h t,l + FF(LN(h t,l )))

(1)

We represent the symbols of the input string as one-hot vectors x 1 , ..., x T ∈ R dv where d v is the size of the vocabulary and the respective columns of the matrix E ∈ R dz×dv are the embedding vectors of those symbols. We also include a positional representation p t using the same sinusoidal encoding schema introduced by Vaswani et al. (2017) . The input of the first-layer cell t,1 is z t,0 :

e t = Ex t d z + p t r t = W (p) e t + b (p) z t,0 = e t r t (2)

where W (p) ∈ R dz×dz , b (p) ∈ R dz , r t is a position-and symbol-dependent role representation, and is elementwise multiplication (a contraction of the tensor product: see Sec. 2.1).

2.1. TP-MULTI-HEAD ATTENTION:

The TPMHA layer of the encoder consists of H heads that can be applied in parallel. Every head 

h, 1 ≤ h ≤ H applies separate affine transformations W h,(k) l , W h,(v) l , W h,(q) l , W h,(r) l ∈ R d k ×dz , b h,(k) l , b h,(v) l , b h,(q) l , b h,(r) l ∈ R d k to

EQUATION

The filler of the attention head t, l, h is

EQUATION

i.e., a weighted sum of all T values of the same layer and attention head (see Fig. 1 ). Here α h,i t,l ∈ (0, 1) is a continuous degree of match given by the softmax of the dot product between the query vector at position t and the key vector at position i:

EQUATION

The scale factor 1 √ d k can be motivated as a variance-reducing factor under the assumption that the elements of q h t,l and k h t,l are uncorrelated variables with mean 0 and variance 1, in order to initially keep the values of the softmax in a region with better gradients.

Finally, we bind the filler vh t,l with our relation vector r h t,l , followed by an affine transformation

W (o) h,l ∈ R dz×d k , b (o)

h,l ∈ R dz before it is summed up with the other heads' bindings to form the TPR of a structure with H constituents: this is the output of the TPMHA layer.

EQUATION

Note that, in this binding, to control dimensionality, we use a contraction of the tensor product, pointwise multiplication : this is the diagonal of the tensor product. For discussion, see the Appendix.

It is worth noting that the l th TPMHA layer returns a vector that is quadratic in the inputs z t,l to the layer: the vectors v h i,l that are linearly combined to form vh t,l (Eq. 4), and r h t,l , are both linear in the z i,l (Eq. 3), and they are multiplied together to form the output of TPMHA (Eq. 6). This means that, unlike regular attention, TPMHA can increase, over successive layers, the polynomial degree of its representations as a function of the original input to the Transformer. Although it is true that the feed-forward layer following attention (Sec. 2.2) introduces its own non-linearity even in the standard Transformer, in the TP-Transformer the attention mechanism itself goes beyond mere linear re-combination of vectors from the previous layer. This provides further potential for the construction of increasingly abstract representations in higher layers.

Figure 1 : A simplified illustration of our TP-Attention mechanism for one head at position t in layer l. The main difference from standard Attention is the additional role representation that is element-wise multiplied with the filler/value representation.

2.2. FEED-FORWARD LAYER:

The feed-forward layer of a cell consists of an affine transformation followed by a ReLU activation and a second affine transformation:

FF(x) = W (g) l ReLU(W (f ) l x + b (f ) l ) + b (g) l (7) Here, W (f ) l ∈ R d f ×dz , b (f ) l ∈ R d f , W (g) l ∈ R dz×d f , b (g) l ∈ R dz and x is the function's argument.

As in previous work, we set d f = 4d z .

2.3. THE DECODER NETWORK:

The decoder network is a separate network with a similar structure to the encoder that takes the hidden states of the encoder and auto-regressively generates the output sequence. In contrast to the encoder network, the cells of the decoder contain two TPMHA layers and one feed-forward layer. We designed our decoder network analogously to Vaswani et al. (2017) where the first attention layer attends over the masked decoder states while the second attention layer attends over the final encoder states. During training, the decoder network receives the shifted targets (teacher-forcing) while during inference we use the previous symbol with highest probability (greedy-decoding). The final symbol probability distribution is given by

EQUATION

where ẑt ,L is the hidden state of the last layer of the decoder at decoding step t of the output sequence and E is the shared symbol embedding of the encoder and decoder.

3. THE MATHEMATICS DATASET:

The Mathematics Dataset (Saxton et al., 2019) The dataset is structured into 56 modules which cover a broad spectrum of mathematics up to university level. It is procedurally generated and comes with 2 million pre-generated training samples per module. The authors provide an interpolation dataset for every module, as well as a few extrapolation datasets as an additional measure of algebraic generalization.

We merge the different training splits train-easy, train-medium, and train-hard from all modules into one big training dataset of 120 million unique samples. From this dataset we extract a character-level vocabulary of 72 symbols, including start-of-sentence, end-of-sentence, and padding symbols2 .

4. EXPERIMENTAL RESULTS:

We evaluate our trained model on the concatenated interpolation and extrapolation datasets of the pre-generated files, achieving a new state of the art: see Table 1 . For a more detailed comparison, Fig. 2 shows the interpolation and extrapolation performance of every module separately.

The TP-Transformer matches or out-performs the Transformer in every module but one (probability swr p sequence). Our model never quite converged, and was stopped prematurely after 1.7 million steps. We trained our model on one server with 4 V100 Nvidia GPUs for 25 days. We initialize the symbol embedding matrix E from N (0, 1), W (p) from N (1, 1), and all other matrices W (•) using the Xavier uniform initialization as introduced by Glorot & Bengio (2010) . The model parameters are set to d z = 512, d f = 2048, d v = 72, H = 8, L = 6. We were not able to train the TP-Transformer, nor the regular Transformer, using the learning rate and gradient clipping scheme described by Saxton et al. (2019) . Instead we proceed as follows: The gradients are computed using PyTorch's Autograd engine and their gradient norm is clipped at 0.1. The optimizer we use is also Adam, but with a smaller learning rate = 1 × 10 -4 , beta1 = 0.9, beta2 = 0.995. We train with a batch size of 1024 up to 1.7 million steps.

5. INTERPRETING THE LEARNED STRUCTURE:

We report initial results of analyzing the learned structure of the encoder network's last layer from our 700k-step TP-Transformer.

5.1. INTERPRETING THE LEARNED ROLES:

To this end, we sample 128 problems from the interpolation dataset of the arithmetic mixed module and collect the role vectors from a randomly chosen head. We use k-means with k = 20 to cluster the role vectors from different samples and different time steps of the final layer of the encoder. Interestingly, we find separate clusters for digits in the numerator and denominator of fractions.

When there is a fraction of fractions we can observe that these assignments are placed such that the second fraction reverses, arguably simplifying the division of fractions into a multiplication of fractions (see Fig. 3 ).  and 4 , where a number in the denominator of a denominator is treated as if in a numerator. Role-cluster 9 corresponds to the role ones-digit-of-anumerator-factor, and 6 to ones-digit-of-a-denominator-factor; other such roles are also evident.

Figure 4 : TP-Transformer attention maps for three examples as described in section 5.2.

5.2. INTERPRETING THE ATTENTION MAPS:

In Fig. 4 we display three separate attention weight vectors of one head of the last TP-Transformer layer of the encoder. Gold boxes are overlaid to highlight most-relevant portions. The row above the attention mask indicates the symbols that take information to the symbol in the bottom row. In each case, they take from '/'. Seen most simply in the first example, this attention can be interpreted as encoding a relation second-argument-to holding between the querying digits and the '/' operator.

The second and third examples show that several numerals in the denominator can participate in this relation. The third display shows how a numerator-numeral (-297) intervening between two denominator-numerals is skipped for this relation.

6. INSIGHTS AND DEFICITS OF MULTIPLE MULTI-HEAD ATTENTION LAYERS:



6.1. MULTI-HEAD ATTENTION SUBSPACES CAPTURE VIRTUALLY ALL INFORMATION:

It was claimed by Vaswani et al. (2017) that Multi-head attention allows the model to jointly attend to information from different representation subspaces at different positions. In this section, we show that in our trained models, an individual attention head does not access merely a subset of the information in the attended cell but instead captures nearly the full information content.

Let us consider a toy example where the attention layer of cell t,l only attends to cell t ,l . In this setting, the post-attention representation simplifies and becomes

EQUATION

where o and v are the respective affine maps (see Sec. 2.1). Note that even though W (v) l is a projection into an 8 times smaller vector space, it remains to be seen whether the hidden state loses information about z t ,l . We empirically test to what extent the trained Transformer and TP-Transformer lose information. To this end, we randomly select n = 100 samples and extract the hidden state of the last layer of the encoder z t,6 , as well as the value representation v h (z t,6 ) for every head. We then train an affine model to reconstruct z t,6 from v h (z t,6 ), the value vector of the single head h:

ẑt,6 = W h v h (z t,6 ) + b h e = 1 n ( ẑt,6 -z t,6 ) 2 (10)

For both trained models, the TP-Transformer and the regular Transformer, the mean squared error e averaged across all heads is only ~0.017 and ~0.009 respectively. This indicates that the attention mechanism incorporates not just a subspace of the states it attends to, but affine transformations of those states that preserve nearly the full information content.

6.2. THE BINDING PROBLEM OF STACKED ATTENTION LAYERS:

The binding problem refers to the problem of binding features together into objects while keeping them separated from other objects. It has been studied in the context of theoretical neuroscience (von der Malsburg, 1981; 1994) but also with regards to connectionist machine learning models (Hinton et al., 1984) . The purpose of a binding mechanism is to enable the fully distributed representation of symbolic structure (like a hierarchy of features) which has recently resurfaced as an important direction for neural network research (Lake & Baroni, 2017; Bahdanau et al., 2018; van Steenkiste et al., 2019; Palangi et al., 2017; Tang et al., 2018) .

In this section, we describe how the standard attention mechanism is ill suited to capture complex nested representations, and we provide an intuitive understanding of the benefit of our TP-Attention. We understand the attention layer of a cell as the means by which the subject (the cell state) queries all other cells for an object. We then show how a hierarchical representation of multiple queries becomes ambiguous in multiple standard attention layers.

Consider the string (a/b)/(c/d). A good neural representation captures the hierarchical structure of the string such that it will not be confused with the similar-looking but structurally different string (a/d)/(c/b). Our TP-Attention makes use of a binding mechanism in order to explicitly support complex structural relations by binding together the object representations receiving high attention with a subject-specific role representation. Let us continue with a more technical example. Consider a simplified Transformer network where every cell consists only of a single-head attention layer with a residual connection: no feed-forward layer or layer normalization, and let us assume no bias terms in the maps o l and v l introduced in the previous section (Eq. 9). In this setting, assume that cell a,l only attends to cell b,l , and cell c,l only attends to cell d,l where a, b, c, d are distinct positions of the input sequence. In this case

EQUATION

Suppose now that, for hierarchical grouping, the next layer cell e,l+1 attends to both cell a,l+1 and cell c,l+1 (equally, each with attention weight 1 2 ). This results in the representation

EQUATION

Note that the final representation is ambiguous in the sense that it is unclear by looking only at Eq. 12 whether cell a,l has picked cell b,l or cell d,l . Either scenario would have led to the same outcome, which means that the network would not be able to distinguish between these two different structures (as in confusing (a/b)/(c/d) with (a/d)/(c/b)). In order to resolve this ambiguity, the standard Transformer must recruit other attention heads or find suitable non-linear maps in between attention layers, but it remains uncertain how the network might achieve a clean separation.

Our TP-Attention mechanism, on the other hand, specifically removes this ambiguity. Now Eqs. 11 and 12 become:

EQUATION

Note that the final representation is not ambiguous anymore. Binding the filler symbols v l (z) (our objects) with a subject-specific role representation r as described in Eq. 6 breaks the structural symmetry we had with regular attention. It is now simple for the network to specifically distinguish the two different structures.

7. RELATED WORK:

Several recent studies have shown that the Transformer-based language model BERT (Devlin et al., 2018) captures linguistic relations such as those expressed in dependency-parse trees. This was shown for BERT's hidden activation states (Hewitt & Manning, 2019; Tenney et al., 2019) and, most directly related to the present work, for the graph implicit in BERT's attention weights (Coenen et al., 2019; Lin et al., 2019) . Future work applying the TP-Transformer to language tasks (like those on which BERT is trained) will enable us to study the connection between the explicit relations {r h t,l } the TP-Transformer learns and the implicit relations that have been extracted from BERT.

8. CONCLUSION:

We have introduced the TP-Transformer, which enables the powerful Transformer architecture to learn to explicitly encode structural relations using Tensor-Product Representations. On the novel and challenging Mathematics Dataset, TP-Transformer beats the previously published state of the art by 8.24%. Our initial analysis of this model's final layer suggests that the TP-Transformer naturally learns to cluster symbol representations based on their structural position and relation to other symbols.

A APPENDIX: RELATIONS BETWEEN HADAMARD-AND TENSOR-PRODUCT-BINDING:

A.1 GENERAL CONSIDERATIONS In the version of the TP-Transformer studied in this paper, binding of relations r to their values v is not done by the tensor product, v ⊗ r, as in full TPRs. Rather, a contraction of the full TPR is used: the diagonal, which is the elementwise or Hadamard product v r. 3 To what extent does Hadamard-product binding share relevant properties with tensor-product binding?

A crucial property of the tensor product for its use in vector representations of structure is that a structure like a/b is not confusable with b/a, unlike the frequently-used bag-of-words encoding: in the BOW encoding of a/b, the pair of arguments to the operator are encoded simply as a + b, where a and b are respectively the vector encodings of a and b. Obviously, this cannot be distinguished from the BOW encoding of the argument pair in b/a, b + a. (Hence the name, symbol "bag", as opposed to symbol "structure".)

In a tensor-product representation of the argument pair in a/b, we have a r n +b r d , where r n and r d are respectively distinct vector embeddings of the numerator (or first-argument) and denominator (or second-argument) roles, and is the tensor product. This is distinct from a r d + b r n , the embedding of the argument-pair in b/a. (In Sec. 6.2 of the paper, an aspect of this general property, in the context of attention models, is discussed. In Sec. 5, visualization of the roles and the perrole-attention show that this particular distinction, between the numerator and denominator roles, is learned and used by the trained TP-Transformer model.)

This crucial property of the tensor product, that a r n + b r d = a r d + b r n , is shared by the Hadamard product: if we now take to represent the Hadamard product, the inequality remains true. To achieve this important property, the full tensor product is not required: the Hadamard product is the diagonal of the tensor product, which retains much of the product structure of the tensor product. In any application, it is an empirical question how much of the full tensor product is required to successfully encode distinctions between bindings of symbols to roles; in the TP-Transformer, it turns out that the diagonal of the tensor product is sufficient to get improvement in performance over having no symbol-role-product structure at all. Unfortunately, the compute requirements of training on the Mathematics Dataset currently makes using the full tensor product infeasible, unless the vector representations of symbols and roles are reduced to dimensions that proved to be too small for the task. When future compute makes it possible, we expect that expanding from the diagonal to the full tensor product will provide further improvement in performance and interpretability.

We next move beyond these general considerations and consider a setting in which Hadamardproduct attention can yield an optimal approximation to tensor-product attention.

A.2 HADAMARD-PRODUCT ATTENTION AS AN OPTIMAL APPROXIMATION TO TENSOR-PRODUCT ATTENTION:

In Eq. 6 for TPMHA, we have a sum over all H heads of an affine-transformed product of a value vector v h and a role vector r h . (Throughout this discussion, we leave the subscripts t, l implicit, as well as the over-bar on v h in Eq. 6.) In a hypothetical, full-TPR formulation, this product would be the tensor product v h ⊗ r h , although in our actual proposed TP-Transformer, the Hadamard (elementwise) product v h r h (the diagonal of v h ⊗ r h ) is used. The appropriateness of the compression from tensor product to Hadamard product can be seen as follows.

In the hypothetical full-TPR version of TPMHA, attention would return the sum of H tensor products. This tensor A would have rank at most H, potentially enabling a substantial degree of compression across all tensors the model will compute over the data of interest. Given the translationinvariance built into the Transformer via position-invariant parameters, the same compression must be applied in all positions within a given layer l, although the compression may vary across heads. For the compression of A we will need more than H components, as this decomposition needs to be optimal over all all tensors in that layer for all data points.

In detail, for each head h, the compression of the tensor A h = v h ⊗ r h (or matrix A h = v h r h ) is to dimension d k , which will ultimately be mapped to dimension d z (to enable addition with z via the residual connection of Eq. 1) by the affine transformation of Eq. 6 . The optimal d k -dimensional compression for head h at layer l would preserve the d k dominant dimensions of variance of the attention-generated states for that head and layer, across all positions and inputs: a kind of singularvalue decomposition retaining those dimensions with the principal singular values. Denote these principal directions by {m 

Ãh = M h Âh N h ≈ M h A h N h = M h v h r h N h = (M h v h )(N h r h ) ãh c = Ãh cc ≈ [M h v h ] c [N h r h ] c = [ṽ h rh ] c

where ṽh = M h v h , rh = N h r h . Now from Eq. 3, v h = W h,(v) z + b h, (v) , so ṽh = M h (W h,(v) z + b h,(v) ). Thus by changing the parameters W h,(v) , b h,(v) to W h,(v) = M h W h,(v) , bh,(v) = M h b h, (v) , and analogously for the role parameters W h,(r) , b h,(r) , we convert our original hypothetical TPR attention tensor A h to its optimal d k -dimensional approximation, in which the tensor product of the original vectors v h , r h is replaced by the Hadamard product of the linearly-transformed vectors ṽh , rh . Therefore, in the proposed model, which deploys the Hadamard product, learning simply needs to converge to the parameters W h,(v) , bh,(v) rather than the parameters W h,(v) , b h, (v) .

A.3 NEURAL MACHINE TRANSLATION:

To demonstrate the generalizability of our contribution, we run a preliminary neural machine translation experiment. We follow the experimental setup of the fairseq toolkit (Ott et al., 2019) . The dataset was modeled as in previous work (Vaswani et al., 2017) . The dataset consists of the WMT'14 English to German data but adds additional news-commentary-v12 data from WMT'17. We use byte-pair encoding and employed label-smoothing with a value of 0.1. We train the regular transformer and our TP-Transformer on 4 P100 GPUs for 500,000 steps using the hyperparameters of the regular transformer. Throughout training, we observe that our TP-Transformer achieves a lower negative log-likelihood than the regular transformer.

Table 2 : The results of our neural machine translation experiment. The loss is the smoothed negative log-likelihood of the word-pieces (lower is better). The TP-Transformer achieves a lower loss throughout training and a comparable final BLEU score (higher is better). 

:

The tensor product operation (when the role-embedding vectors are linearly independent) enables the sum of constituents representing the structure as a whole to be uniquely decomposable back into individual pairs of roles and their fillers, if necessary.

Note thatSaxton et al. (2019) report a vocabulary size of 95, but this figure encompasses characters that never appear in the pre-generated training and test data.

This is a vector, and should not be confused with the inner product v • r which is a scalar: the inner product is the sum of all the elements of the Hadamard product.

Figures and Tables:

Figure 2: The accuracies of our implementation of the Transformer (700k steps) and the TP-Transformer (700k and 1.7M steps) for every module of the Mathematics Dataset.

Figure 3: Samples of correctly processed problems from the arithmetic mixed module. '#' and '%' are the start-and end-of-sentence symbols. The colored squares indicate the k-means cluster of the role-vector assigned by one head in the final layer in that position. Blue and gold rectangles respectively highlight numerator and denominator roles. They were discovered manually. Note how their placement is correctly swapped in rows 2, 3,and 4, where a number in the denominator of a denominator is treated as if in a numerator. Role-cluster 9 corresponds to the role ones-digit-of-anumerator-factor, and 6 to ones-digit-of-a-denominator-factor; other such roles are also evident.

h c ⊗ n h c |c = 1, . . . , d k }, and let M h and N h respectively be the d k × d k matrices with the orthonormal vectors {m h c } and {n h c } as columns. (Note that orthonormality implies that M h M h = I and N h N h = I, with I the d k × d k identity matrix.)The compression of A h , Âh , will lie within the space spanned by these d k tensor products m h c ⊗ n h c , i.e., Âh =d k c=1 ãh c m c ⊗ n c ; in matrix form, Âh = M h Ãh N h ,where Ãh is the d k × d k diagonal matrix with elements ãh c . Thus the d k dimensions {ã h c } of the compressed matrix Âh that approximates A h are given by:

Figure 5: The best-so-far smoothed negative log-likelihood of word-pieces on held-out data throughout training.

produce key, value, query, and relation vectors from the hidden state z t,l , where d k = d z /H:

Table content: <table/>

Model accuracy averaged over all modules. A sample is correct if all characters of the target sequence have been predicted correctly. The column ">95%" counts how many of the 56 modules achieve over 95% accuracy. Boldface marks the best-performing model up to 700k steps.

Table content: <table><tr><td/><td colspan="2">weights steps</td><td>train</td><td colspan="2">interpolation</td><td colspan="2">extrapolation</td></tr><tr><td/><td/><td/><td/><td>acc</td><td>&gt;95%</td><td>acc</td><td>&gt;95%</td></tr><tr><td>Simple LSTM</td><td>18M</td><td>500k</td><td>-</td><td>57.00%</td><td>6</td><td>41.00%</td><td>1</td></tr><tr><td>Transformer (Saxton et al.)</td><td>30M</td><td>500k</td><td>-</td><td>76.00%</td><td>13</td><td>50.00%</td><td>1</td></tr><tr><td>Transformer (ours)</td><td>44.2M</td><td>500k 700k</td><td>83.06% 85.01%</td><td>75.33% 77.42%</td><td>12 14</td><td>52.42% 52.00%</td><td>1 2</td></tr><tr><td/><td/><td>500k</td><td>85.41%</td><td>78.30%</td><td>16</td><td>52.22%</td><td>2</td></tr><tr><td>TP-Transformer (ours)</td><td>49.2M</td><td>700k</td><td>87.25%</td><td>80.67%</td><td>18</td><td>52.48%</td><td>3</td></tr><tr><td/><td/><td>1.7M</td><td>91.04%</td><td>84.24%</td><td>25</td><td>55.40%</td><td>3</td></tr><tr><td colspan="2">4.1 IMPLEMENTATION DETAILS</td><td/><td/><td/><td/><td/><td/></tr></table>

Peer review (iclr2020):
Motivated by the fact that the attention mechanism in transformers is symmetric which might not be able to disambiguate different orders, this work proposes to use a subject vector (in addition to query, key states) for each attention head, and multiply it elementwise with the context vector for each head before merging the heads. Experiments on a mathematics dataset shows superior performance compared to the normal transformer. Qualitatively, the proposed model exhibits attentions that are more interpretable, and clustering by the subject vector gives some insights into how the model solved this problem. Pros: 1. This work shows better performance than baseline transformer. 2. The clustering of the subject vectors gives some insights into model*s behavior . Cons: 1. In terms of experiments, the proposed approach adds a few million parameters to normal transformer (table 1), but in terms of interpolation it only improves 3% (extrapolation improves 0.5%) at 700k steps. The comparison would be fairer if the normal transformer can be given more parameters. 2. In terms of experiments, this approach is only evaluated on the mathematics dataset, but the argument for relational encoding is pretty general. It would be nice if experiments on other tasks are shown in addition to the math dataset. 3. In terms of motivation, the claim that there*re ambiguities introduced by multiple layers of regular attention needs to be supported by evidence. I think (which authors also pointed out) the feedforward network and non-linearties can disambiguate as well. 4. In terms of interpretablity, there*s claim that the learned attention maps more interpretable than transformer. Can there be more quantitative measures? It appears to me that both are hard to interpret. While this work shows superior performance on the mathematics dataset, I have a few concerns about the generalizability of this proposed architectural change to other problems, as well as the fairness of comparison to baseline. Therefore, I am inclined to reject this paper. ----updates after reading rebuttal---- Thanks for adding the new NMT experiment in Appendix A3. My concern is that the proposed TP-Transformer is not very effective on NMT. Therefore, I*m keeping my score.