RNNs implicitly implement tensor-product representations

1 INTRODUCTION . Compositional symbolic representations are widely held to be necessary for intelligence ( Newell , 1980 ; Fodor & Pylyshyn , 1988 ) , particularly in the domain of language ( Montague , 1974 ) . However , neural networks have shown great success in natural language processing despite using continuous vector representations rather than explicit symbolic structures . How can these continuous representations yield such success in a domain traditionally believed to require symbol manipulation ? One possible answer is that neural network representations implicitly encode compositional structure . This hypothesis is supported by the spatial relationships between such vector representations , which have been argued to display geometric regularities that parallel plausible symbolic structures of the elements being represented ( Mikolov et al . 2013 ; see Figure 1 ) . Analogical relationships such as those in Figure 1 are special cases of linearity properties shared by several methods developed in the 1990s for designing compositional vector embeddings of symbolic structures . The most general of these is tensor product representations ( TPRs ; Smolensky 1990 ) . Symbolic structures are first decomposed into filler-role bindings ; for example , to represent the sequence [ 5 , 2 , 4 ] , the filler 5 may be bound to the role of first element , the filler 2 may be bound to the role of second element , and so on . Each filler fi and — crucially — each role ri has a vector embedding ; these two vectors are combined using their tensor product fi ⊗ ri , and these tensor products are summed to produce the representation of the sequence : ∑ fi ⊗ ri . This linear combination can predict the linear relations between sequence representations illustrated in Figure 1 . In this article , we test the hypothesis that vector representations of sequences can be approximated as a sum of filler-role bindings , as in TPRs . We introduce the Tensor Product Decomposition Network ( TPDN ) which takes a set of continuous vector representations to be analyzed and learns filler and role embeddings that best predict those vectors , given a particular hypothesis for the relevant set of roles ( e.g. , sequence indexes or structural positions in a parse tree ) . To derive structure-sensitive representations , in Section 2 we look at a task driven by structure , not content : autoencoding of sequences of meaningless symbols , denoted by digits . The focus here is on sequential structure , although we also devise a version of the task that uses tree structure . For the representations learned by these autoencoders , TPDNs find excellent approximations that are TPRs . In Section 3 , we turn to sentence-embedding models from the contemporary literature . It is an open question how structure-sensitive these representations are ; to the degree that they are structuresensitive , our hypothesis is that they can be approximated by TPRs . Here , TPDNs find less accurate approximations , but they also show that a TPR equivalent to a bag-of-words already provides a reasonable approximation ; these results suggest that these sentence representations are not robustly structure-sensitive . We therefore return to synthetic data in Section 4 , exploring which architectures and training tasks are likely to lead RNNs to induce structure-sensitive representations . To summarize the contributions of this work , TPDNs provide a powerful method for interpreting vector representations , shedding light on hard-to-understand neural architectures . We show that standard RNNs can induce compositional representations that are remarkably well approximated by TPRs and that the nature of these representations depends , in intrepretable ways , on the architecture and training task . Combined with our finding that standard sentence encoders do not seem to learn robust representations of structure , these findings suggest that more structured architectures or more structure-dependent training tasks could improve the compositional capabilities of existing models . 1.1 THE TENSOR PRODUCT DECOMPOSITION NETWORK . The Tensor Product Decomposition Network ( TPDN ) , depicted in Figure 2c , learns a TPR that best approximates an existing set of vector encodings . While TPDNs can be applied to any structured space , including embeddings of images or words , this work focuses on applying TPDNs to sequences . The model is given a hypothesized role scheme and the dimensionalities of the filler and role embeddings . The elements of each sequence are assumed to be the fillers in that sequence ’ s representation ; for example , if the hypothesized roles are indexes counting from the end of the sequence , then the hypothesized filler-role pairs for [ 5 , 2 , 4 ] would be ( 4 : last , 2 : second-to-last , 5 : third-to-last ) . The model then learns embeddings for these fillers and roles that minimize the distance between the TPRs generated from these embeddings and the existing encodings of the sequences . Before the comparison is performed , the tensor product ( which is a matrix ) is flattened into a vector , and a linear transformation M is applied ( see Appendix B for an ablation study showing that this transformation , which was not a part of the original TPR proposal , is necessary ) . The overall function computed by the architecture is thus M ( flatten ( ∑ i ri ⊗ fi ) ) . PyTorch code for the TPDN model is available on GitHub,1 along with an interactive demo.2 1https : //github.com/tommccoy1/tpdn 2https : //tommccoy1.github.io/tpdn/tpr_demo.html 2 APPROXIMATING RNN AUTOENCODER REPRESENTATIONS . To establish the effectiveness of the TPDN at uncovering the structural representations used by RNNs , we first apply the TPDN to sequence-to-sequence networks trained on an autoencoding objective : they are expected to encode a sequence of digits and then decode that encoding to reproduce the same sequence ( Figure 2a ) . In addition to testing the TPDN , this experiment also addresses a scientific question : do different architectures ( specifically , unidirectional , bidirectional , and tree-based sequence-to-sequence models ) induce different representations ? 2.1 EXPERIMENTAL SETUP . Digit sequences : The sequences consisted of the digits from 0 to 9 . We randomly generated 50,000 unique sequences with lengths ranging from 1 to 6 inclusive and averaging 5.2 ; these sequences were divided into 40,000 training sequences , 5,000 development sequences , and 5,000 test sequences . Architectures : For all sequence-to-sequence networks , we used gated recurrent units ( GRUs , Cho et al . ( 2014 ) ) as the recurrent units . We considered three encoder-decoder architectures : unidirectional , bidirectional , and tree-based.3 The unidirectional encoders and decoders follow the setup of Sutskever et al . ( 2014 ) : the encoder is fed the input elements one at a time , left to right , updating its hidden state after each element . The decoder then produces the output sequence using the final hidden state of the encoder as its input . The bidirectional encoder combines left-to-right and right-toleft unidirectional encoders ( Schuster & Paliwal , 1997 ) ; for symmetry , we also create a bidirectional decoder , which has both a left-to-right and a right-to-left unidirectional decoder whose hidden states are concatenated to form bidirectional hidden states from which output predictions are made . Our final topology is tree-based RNNs ( Pollack , 1990 ; Socher et al. , 2010 ) , specifically the Tree-GRU encoder of Chen et al . ( 2017 ) and the tree decoder of Chen et al . ( 2018 ) . These architectures require a tree structure as part of their input ; we generated a tree for each sequence using a deterministic algorithm that groups digits based on their values ( see Appendix C ) . To control for initialization effects , we trained five instances of each architecture with different random initializations . Role schemes : We consider 6 possible methods that networks might use to represent the roles of specific digits within a sequence ; see Figure 3a for examples of these role schemes . 1 . Left-to-right : Each digit ’ s role is its index in the sequence , counting from left to right . 2 . Right-to-left : Each digit ’ s role is its index in the sequence , counting from right to left . 3 . Bidirectional : Each digit ’ s role is an ordered pair containing its left-to-right index and its right-to-left index ( compare human representations of spelling , Fischer-Baum et al . 2010 ) . 4 . Wickelroles : Each digit ’ s role is the digit before it and the digit after it ( Wickelgren , 1969 ) . 3For this experiment , the encoder and decoder always matched in type . 5 . Tree positions : Each digit ’ s role is its position in a tree , such as RRL ( left child of right child of right child of root ) . The tree structures are given by the algorithm in Appendix C. 6 . Bag-of-words : All digits have the same role . We call this a bag-of-words because it represents which digits ( “ words ” ) are present and in what quantities , but ignores their positions . Hypothesis : We hypothesize that RNN autoencoders will learn to use role representations that parallel their architectures : left-to-right roles for a unidirectional network , bidirectional roles for a bidirectional network , and tree-position roles for a tree-based network . Evaluation : We evaluate how well a given sequence-to-sequence network can be approximated by a TPR with a particular role scheme as follows . First , we train a TPDN with the role scheme in question ( Section 1.1 ) . Then , we take the original encoder/decoder network and substitute the fitted TPDN for its encoder ( Figure 2d ) . We do not conduct any additional training upon this hybrid network ; the decoder retains exactly the weights it learned in association with the original encoder , while the TPDN retains exactly the weights it learned for approximating the original encoder ( including the weights on the final linear layer ) . We then compute the accuracy of the resulting hybrid network ; we call this metric the substitution accuracy . High substitution accuracy indicates that the TPDN has approximated the encoder well enough for the decoder to handle the resulting vectors . 2.2 RESULTS . Performance of seq2seq networks : The unidirectional and tree-based architectures both performed the training task nearly perfectly , with accuracies of 0.999 and 0.989 ( averaged across five runs ) . Accuracy was lower ( 0.834 ) for the bidirectional architecture ; this might mean that the hidden size of 60 becomes too small when divided into two 30-dimensional halves , one half for each direction . Quality of TPDN approximation : For each of the six role schemes , we fitted a TPDN to the vectors generated by the trained encoder , and evaluated it using substitution accuracy ( Section 2.1 ) . The results , in Figure 3c , show that different architectures do use different representations to solve the task . The tree-based autoencoder can be well-approximated using tree-position roles but not using any of the other role schemes . By contrast , the unidirectional architecture is approximated very closely ( with a substitution accuracy of over 0.99 averaged across five runs ) by bidirectional roles . Left-to-right roles are also fairly successful ( accuracy = 0.87 ) , and right-to-left roles are decidedly unsuccessful ( accuracy = 0.11 ) . This asymmetry suggests that the unidirectional network uses mildly bidirectional roles : while it is best approximated by bidirectional roles , it strongly favors one direction over the other . Though the model uses bidirectional roles , then , roles with the same left-to-right position ( e.g . ( 2,3 ) , ( 2,4 ) , and ( 2,5 ) ) can be collapsed without much loss of accuracy . Finally , the bidirectional architecture is not approximated well by any of the role schemes we investigated . It may be implementing a role scheme we did not consider , or a structure-encoding scheme other than TPR . Alternately , it might simply not have adopted any robust method for representing sequence structure ; this could explain why its accuracy on the training task was relatively low ( 0.83 ) .

Summary: The work proposes Tensor Product Decomposition Networks (TRDN) as a way to uncover the representation learned in recurrent neural networks (RNNs). TRDN trains a Tensor Product Representation, which additively combine tensor products of role (e.g., sequence position) embeddings and filler (e.g., word) embeddings to approximate the encoding produced by RNNs. TRDN as a result shed light into inspecting and interpreting representation learned through RNNs. The authors suggest that the structures captured in RNNs are largely compositional and can be well captured by TPRs without recurrence and nonlinearity.