How LSTM Encodes Syntax: Exploring Context Vectors and Semi-Quantization on Natural Text (2020)

Abstract: Long Short-Term Memory recurrent neural network (LSTM) is widely used and known to capture informative long-term syntactic dependencies. However, how such information are reflected in its internal vectors for natural text has not yet been sufficiently investigated. We analyze them by learning a language model where syntactic structures are implicitly given. We empirically show that the context update vectors, i.e. outputs of internal gates, are approximately quantized to binary or ternary values to help the language model to count the depth of nesting accurately, as Suzgun et al. (2019) recently show for synthetic Dyck languages. For some dimensions in the context vector, we show that their activations are highly correlated with the depth of phrase structures, such as VP and NP. Moreover, with an L1 regularization, we also found that it can accurately predict whether a word is inside a phrase structure or not from a small number of components of the context vector. Even for the case of learning from raw text, context vectors are shown to still correlate well with the phrase structures. Finally, we show that natural clusters of the functional words and the part of speeches that trigger phrases are represented in a small but principal subspace of the context-update vector of LSTM.

## introduction lstm @xcite is one of the most fundamental architectures that support recent developments of natural language processing. it is widely used for building accurate language models by controlling the flow of gradients and tracking informative long-distance dependencies in various tasks such as machine translation, summarization and text generation @xcite @xcite . while attention-based models such as transformer @xcite and bert @xcite and their extensions are known to encode syntactic information @xcite , some studies show that lstms are still theoretically superior in terms of ability to capture syntactic dependency @xcite . @xcite and @xcite also empirically demonstrate that transformers do not outperform lstm with respect to tasks to capture syntactic information. recent empirical studies attempt to explain deep neural network models and to answer the questions such as how rnns capture the long-distance dependencies, and how abstract or syntactic information is embedded inside deep neural network models @xcite @xcite . they mainly discuss the extent to which the rnn acquires syntax by comparing experimental accuracy on some syntactic structures, such as number agreements (see section 7 for details). some studies also investigate in which vector spaces and layers a specific syntactic information is captured @xcite . lately, @xcite trained lstm on dyck-{1,2} formal languages, and showed that it can emulate counter machines. however, no studies have shed light on the inherent mechanisms of lstm and their relevance to its internal representation in actual text. @xcite theoretically showed that under a realistic condition, the computational power of rnns are much more limited than previously envisaged, despite of the fact that rnns are turing complete @xcite . on the other hand, they also showed that lstm is stronger than the simple rnn (srnn) and gru owing to the counting mechanism lstm is argued to possess. following these results, @xcite introduces an inverse temperature θ into the sigmoid and tanh functions and taking limits as θ → ∞, and thus assumes that all gates of lstm are asymptotically quantized: e.g. lim θ→∞ σ(θx) ∈ {0, 1} and lim θ→∞ σ(θx) tanh(θy) ∈ {-1, 0, 1}. under the above assumption, it shows lstms work like counter machines, or more precisely, the expressiveness of lstms is asymptotically equivalent to that of some subclass of counter machines. while those results are significant and giving us theoretical clues to understand how lstms acquire syntactic representations as their hidden vectors, it is not yet known whether or not similar phenomena occur in models learned from real-world data. regarding this point, we show that those quantization actually often happens in real situations and bridge a gap between theories and practical models through statistical analysis of internal vectors of lstm that are trained from both raw texts and texts augmented by implicit syntactical symbols. we first explore the behaviors of lstm language models (lstm-lms) and the representation of the syntactic structures by giving linearized syntax trees implicitly. then, we show that lstm also acquires a representation of syntactic information in their internal vectors even from a raw text, by statistically analyzing the internal vectors corresponding to syntactic functions. we empirically show that the representations of parts of speech such as np and vp and syntactic functions that specific words have, both of which often act as syntactic triggers, are acquired in the space of context-update vectors, as well as syntactic dependencies are accumulated in the space of context vectors. ## hypotheses and outline of analyses to understand the behavior of lstm further, we try to answer two kinds of questions: (a) what information is relevant with the syntax, and (b) how this information is correlated with the syntactic behavior. in particular, we will examine: (1) which of the internal vectors (i.e. h, c, and u) of lstm highly correlates with the prediction of the phrase structure and its nesting (sections 5.1 and 5.2), and (2) how well these internal vectors or some subsets of their dimensions can predict the syntactic structures (section 5.3). since recognition of syntax inevitably requires recognition of the part-of-speech for each word, we also investigate: (3) how the contextual part-of-speech is represented in the internal vectors of the lstm, and how the differences between them can be captured using pca (section 6). ## representation of syntactic structures after these investigations on lstm, next we will examine how each tag of the phrase structure and the depth of the nesting are embedded in its internal vectors. ## internal representation of syntactic functions finally, we investigate how syntactic functions, such as part-of-speech (pos) and functional words, are represented in internal vectors when lstm is trained for raw text. we also show that their syntactic functions are naturally represented in the context-update vector u, rather than c. ## related work as research on how lstm tracks long-term dependence, behaviors of lstm with several dimensions have been studied using artificial languages @xcite @xcite . with recent applications of lstm to various tasks, studies are being conducted on how lstm recognizes syntax and long-term dependencies @xcite . for instance, @xcite uses number agreement to determine whether a language model using lstm truly captures it. @xcite evaluates how the distance between words affects the prediction in lstm-lm. @xcite utilize the learned lstm to construct deterministic automata. furthermore, @xcite control the complexity of long-range dependency using sp-k languages, and verify if lstm can track them. several studies have attempted to theoretically understand the learning ability of language models using rnns, including lstm and gru @xcite @xcite . ## conclusion in this paper, we empirically investigated various behaviors of lstm on natural text by looking into its hidden state vectors. contrary to previous work that deal with only artificial data, we clarified that updates u of the context vectors c are approximately discretized and accumulated in a low-dimensional subspace, leading to an approximate counter machines discussed in section 4 and a clear representation of syntactic functions as shown in section 5, in spite of the high dimensionality of state vectors explored in this study. especially, we show that the representations of pos are acquired in the space of u rather than c and h in an unsupervised manner. the fact that the first principal component of pca-uq for u encodes the difference between np and vp is not only significant for understanding how lstm-lm acquires ayntax, but also seen as a result of extracting the most important syntactic factor using lstm with respect to the target language.